/*@!Encoding:1252*/ variables { // A normal Modbus Application Header. Every Modbus Packet begins with these 7 (+FuncCode) Bytes _align(1) struct ModbusApHeader { word TxID; word Protocol; word Length; byte UnitID; byte FuncCode; }; // 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 { struct ModbusApHeader Header; word Address; word Count; }; // Write a single value to a bit/register _align(1) struct ModbusReqWriteSingle { struct ModbusApHeader Header; word Address; word Value; }; // Write several values to a bit/register starting with Address _align(1) struct ModbusReqWriteBits { struct ModbusApHeader Header; word Address; word Count; byte ByteCount; byte Data[246]; // Max length: 1968 bits }; // Write several values to bits starting with Address _align(1) struct ModbusReqWriteRegisters { struct ModbusApHeader Header; word Address; word Count; byte ByteCount; word Data[123]; // Max length: 123 registers }; // Write AND and OR masks to a holding register _align(1) struct ModbusReqWriteMasks { struct ModbusApHeader Header; word Address; word And; word Or; }; // Read and write multiple registers _align(1) struct ModbusReqReadWriteRegisters { struct ModbusApHeader Header; word ReadAddress; word ReadCount; word WriteAddress; word WriteCount; byte ByteCount; word Data[121]; // Max length: 123-2 registers }; // Receive several bit values _align(1) struct ModbusResReceiveBits { struct ModbusApHeader Header; byte ByteCount; byte Data[250]; // Max length: 2000 bits }; // Receive several register values _align(1) struct ModbusResReceiveRegisters { struct ModbusApHeader Header; byte ByteCount; word Data[125]; // Max length: 125 registers }; // Confirm the write of a single bit/register _align(1) struct ModbusResConfirmSingle { struct ModbusApHeader Header; word Address; int Value; }; // Confirm the write of several bits/registers _align(1) struct ModbusResConfirmMultiple { struct ModbusApHeader Header; word Address; word Count; }; // Confirm the write of AND and OR mask _align(1) struct ModbusResConfirmMasks { struct ModbusApHeader Header; word Address; word And; word Or; }; enum ModbusRequestError { Exception, Timeout }; enum ModbusException { None = 0x00, IllegalFuncCode = 0x01, IllegalDataAddress = 0x02, IllegalDataValue = 0x03, ServerFailure = 0x04, Acknowledge = 0x05, ServerBusy = 0x06, GatewayPathsNA = 0x0A, TargetOffline = 0x0B }; }