rllib
1
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
lib
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
{
153
MODBUS_CHECKSUM_ERROR
= -2,
154
MODBUS_ERROR
= -1,
155
MODBUS_SUCCESS
= 0,
156
MODBUS_RTU
= 1,
157
MODBUS_ASCII
= 2
158
};
159
160
enum
ModbusFunctionCodes
161
{
162
ReadCoilStatus
= 1,
163
ReadInputStatus
= 2,
164
ReadHoldingRegisters
= 3,
165
ReadInputRegisters
= 4,
166
ForceSingleCoil
= 5,
167
PresetSingleRegister
= 6,
168
ReadExceptionStatus
= 7,
169
FetchCommEventCtr
= 11,
170
FetchCommEventLog
= 12,
171
ForceMultipleCoils
= 15,
172
PresetMultipleRegs
= 16,
173
ReportSlaveID
= 17,
174
ReadGeneralReference
= 20,
175
WriteGeneralReference
= 21,
176
MaskWrite4XRegisters
= 22,
177
ReadWrite4XRegisters
= 23,
178
ReadFifoQueue
= 24
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
();
192
int
autoreconnectSocket
;
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);
211
rlSocket
*
s
;
212
rlSerial
*
tty
;
213
unsigned
char
*
tel
;
214
long
maxtel
;
215
int
mode
;
216
char
delimitor
;
217
};
218
219
#endif
220
Generated by
1.8.2