rllib  1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
rlmodbus.h
Go to the documentation of this file.
1 /***************************************************************************
2  rlmodbus.h - description
3  -------------------
4  begin : Tue Mar 13 2003
5  copyright : (C) 2003 by R. Lehrig
6  email : lehrig@t-online.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This library is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as *
13  * published by the Free Software Foundation *
14  * *
15  ***************************************************************************/
16 #ifndef _RL_MODBUS_H_
17 #define _RL_MODBUS_H_
18 
19 #include "rldefine.h"
20 #include "rlsocket.h"
21 #include "rlserial.h"
22 
148 class rlModbus
149 {
150  public:
151  enum Modbus
152  {
158  };
159 
161  {
179  };
180 
181  rlModbus(long max_telegram_length = 1024, int mode = MODBUS_RTU, char end_delimitor = 0x0a);
182  virtual ~rlModbus();
183  int write (int slave, int function, const unsigned char *data, int len, int *transactionID = NULL);
184  int request (int slave, int function, int start_adr, int num_register);
185  int response(int *slave, int *function, unsigned char *data, int timeout=1000);
186  int readRequest(int *slave, int *function, unsigned char *data, int timeout=1000, int *transactionID = NULL);
187  void registerSocket(rlSocket *socket);
188  void registerSerial(rlSerial *serial);
189  int data2int(const unsigned char *data);
190  int int2data(int val, unsigned char *data);
191  int intsize();
193  int readCoilStatus (int slave, int start_adr, int number_of_coils, unsigned char *status, int timeout=1000);
194  int readInputStatus (int slave, int start_adr, int number_of_inputs, unsigned char *status, int timeout=1000);
195  int readHoldingRegisters (int slave, int start_adr, int number_of_registers, int *registers, int timeout=1000);
196  int readInputRegisters (int slave, int start_adr, int number_of_registers, int *registers, int timeout=1000);
197  int forceSingleCoil (int slave, int coil_adr, int value, int timeout=1000);
198  int presetSingleRegister (int slave, int register_adr, int value, int timeout=1000);
199  int forceMultipleCoils (int slave, int coil_adr, int number_of_coils, unsigned char *coils, int timeout=1000);
200  int presetMultipleRegisters (int slave, int start_adr, int number_of_registers, int *registers, int timeout=1000);
201 
202  private:
203  int buf2int_rtu(unsigned char *buf);
204  void int2buf_rtu(int i, unsigned char *buf);
205  int buf2int_ascii(unsigned char *buf);
206  void int2buf_ascii(int i, unsigned char *buf);
207  void insertLRC(int len);
208  void insertCRC(int len);
209  int LRCerror(int len);
210  int CRCerror(int len);
213  unsigned char *tel;
214  long maxtel;
215  int mode;
216  char delimitor;
217 };
218 
219 #endif
220