ModbusStructs.cin
Improved comments
This commit is contained in:
parent
eb6d28c71b
commit
f97e0c7481
1 changed files with 28 additions and 16 deletions
|
@ -1,27 +1,29 @@
|
||||||
/*@!Encoding:1252*/
|
/*@!Encoding:1252*/
|
||||||
variables
|
variables
|
||||||
{
|
{
|
||||||
// according to Modbus Specification v1.1
|
// Constant maximum values according to Modbus Specification v1.1
|
||||||
const word gMaxBitsPerRead = 2000;
|
const word gMaxBitsPerRead = 2000;
|
||||||
const word gMaxRegsPerRead = 125;
|
const word gMaxRegsPerRead = 125;
|
||||||
const word gMaxBitsPerWrite = 1968; // Multiple of 8!
|
const word gMaxBitsPerWrite = 1968; // Multiple of 8!
|
||||||
const word gMaxRegsPerWrite = 123;
|
const word gMaxRegsPerWrite = 123;
|
||||||
|
|
||||||
|
// Function Codes according to Modbus Specification v1.1
|
||||||
enum ModbusFuncCode
|
enum ModbusFuncCode
|
||||||
{
|
{
|
||||||
ReadBitsOut = 0x01,
|
ReadBitsOut = 0x01, // Read Coils
|
||||||
ReadBitsIn = 0x02,
|
ReadBitsIn = 0x02, // Read Discrete Inputs
|
||||||
ReadRegistersOut = 0x03,
|
ReadRegistersOut = 0x03, // Read Holding Registers
|
||||||
ReadRegistersIn = 0x04,
|
ReadRegistersIn = 0x04, // Read Input Registers
|
||||||
WriteBit = 0x05,
|
WriteBit = 0x05, // Write Single Coil
|
||||||
WriteRegister = 0x06,
|
WriteRegister = 0x06, // Write Single Holding Register
|
||||||
WriteBits = 0x0F,
|
WriteBits = 0x0F, // Write Multiple Coils
|
||||||
WriteRegisters = 0x10,
|
WriteRegisters = 0x10, // Write Multiple Holding Registers
|
||||||
MaskRegister = 0x16,
|
MaskRegister = 0x16, // Mask Write Holding Register
|
||||||
ReadWriteRegisters = 0x17
|
ReadWriteRegisters = 0x17 // Read/Write Multiple Registers
|
||||||
};
|
};
|
||||||
|
|
||||||
// A normal Modbus Application Header. Every Modbus Packet begins with these 7 (+FuncCode) Bytes
|
// Modbus Application Header
|
||||||
|
// Every Modbus Packet begins with these 7 (+FuncCode) Bytes
|
||||||
_align(1) struct ModbusApHeader
|
_align(1) struct ModbusApHeader
|
||||||
{
|
{
|
||||||
word TxID;
|
word TxID;
|
||||||
|
@ -30,6 +32,8 @@ variables
|
||||||
byte UnitID;
|
byte UnitID;
|
||||||
byte FuncCode;
|
byte FuncCode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Request structures following
|
||||||
// Read Data from the host. We only need the start address and the number of bits/registers we want to read
|
// Read Data from the host. We only need the start address and the number of bits/registers we want to read
|
||||||
_align(1) struct ModbusReqRead
|
_align(1) struct ModbusReqRead
|
||||||
{
|
{
|
||||||
|
@ -83,6 +87,7 @@ variables
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// Response structures following
|
||||||
// Receive several bit values
|
// Receive several bit values
|
||||||
_align(1) struct ModbusResReceiveBits
|
_align(1) struct ModbusResReceiveBits
|
||||||
{
|
{
|
||||||
|
@ -120,16 +125,21 @@ variables
|
||||||
word Or;
|
word Or;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// The maximum modbus telegram size.
|
||||||
|
// Several telegrams use this many bytes, but CAPL does not support a constant max function to let it calculate it. So we use ModbusResReceiveRegisters
|
||||||
const word gModbusMaxTelegramSize = __size_of(struct ModbusResReceiveRegisters);
|
const word gModbusMaxTelegramSize = __size_of(struct ModbusResReceiveRegisters);
|
||||||
|
|
||||||
|
|
||||||
|
// Some errors that may occur when sending a request
|
||||||
enum ModbusRequestError
|
enum ModbusRequestError
|
||||||
{
|
{
|
||||||
Exception,
|
Exception, // Modbus exception was returned
|
||||||
Timeout,
|
Timeout, // Timeout occured, resending the packet
|
||||||
FinalTimeout,
|
FinalTimeout, // Timeout occured, not resending the packet
|
||||||
NotSent
|
NotSent // Sending the packet was impossible
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Modbus exception codes according to Modbus Specification v1.1
|
||||||
enum ModbusException
|
enum ModbusException
|
||||||
{
|
{
|
||||||
None = 0x00,
|
None = 0x00,
|
||||||
|
@ -142,6 +152,8 @@ variables
|
||||||
GatewayPathsNA = 0x0A,
|
GatewayPathsNA = 0x0A,
|
||||||
TargetOffline = 0x0B
|
TargetOffline = 0x0B
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Fatal errors that may stop the code execution
|
||||||
enum FatalErrors
|
enum FatalErrors
|
||||||
{
|
{
|
||||||
ParsingBuffer,
|
ParsingBuffer,
|
||||||
|
|
Loading…
Reference in a new issue