Bachelorthesis/Modbus-CAPL/include/CAPL/include/ModbusStructs.cin
2014-06-20 10:45:41 +00:00

153 lines
3.5 KiB
Plaintext

/*@!Encoding:1252*/
variables
{
// according to Modbus Specification v1.1
const word gMaxBitsPerRead = 2000;
const word gMaxRegsPerRead = 125;
const word gMaxBitsPerWrite = 1968; // Multiple of 8!
const word gMaxRegsPerWrite = 123;
// 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[gMaxBitsPerWrite/8]; // 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[gMaxRegsPerWrite]; // 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[gMaxRegsPerWrite-2]; // Max length: 123-2 registers
};
// Receive several bit values
_align(1) struct ModbusResReceiveBits
{
struct ModbusApHeader Header;
byte ByteCount;
byte Data[gMaxBitsPerRead/8]; // Max length: 2000 bits
};
// Receive several register values
_align(1) struct ModbusResReceiveRegisters
{
struct ModbusApHeader Header;
byte ByteCount;
word Data[gMaxRegsPerRead]; // 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;
};
const word gModbusMaxTelegramSize = __size_of(struct ModbusResReceiveRegisters);
enum ModbusRequestError
{
Exception,
Timeout,
FinalTimeout
};
enum ModbusException
{
None = 0x00,
IllegalFuncCode = 0x01,
IllegalDataAddress = 0x02,
IllegalDataValue = 0x03,
ServerFailure = 0x04,
Acknowledge = 0x05,
ServerBusy = 0x06,
GatewayPathsNA = 0x0A,
TargetOffline = 0x0B
};
enum ModbusFuncCode
{
ReadBits1 = 0x01,
ReadBits2 = 0x02,
ReadRegisters1 = 0x03,
ReadRegisters2 = 0x04,
WriteBit = 0x05,
WriteRegister = 0x06,
WriteBits = 0x0F,
WriteRegisters = 0x10,
MaskRegister = 0x16,
ReadWriteRegisters = 0x17
};
enum FatalErrors
{
ParsingBuffer = 0x00,
ModbusPackageWasSplit = 0x01,
DeviceCodeUnknown = 0x02,
VendorIdUnknown = 0x03,
ConnectionError = 0x04
};
}