Server
(FB)
FUNCTION_BLOCK ABSTRACT Server
MODBUS server (slave) base class.
Supported function codes
Supported function codes can be configured, see fcsSupported.
By default the MODBUS server supports:
ReadCoils
ReadDiscreteInputs
ReadHoldingRegisters
ReadInputRegisters
WriteSingleCoil
WriteSingleRegister
WriteMultipleRegisters
ReadWriteMultipleRegisters
Optionally it supports also:
MaskWriteRegister
“data model”
The “data model” allows:
non-consecutive index for the “data items” (for example: index 0..9, 20..29)
multiple (non-consecutive) memory blocks for “data items” in one “data block” (for example: index 0..9 => memory block 1, index 20..29 => memory block 2)
not-memory-mapped “data items” (user code needs to be written to handle reads/writes for those “data items”)
“discrete inputs” / “coils” : data item size 1 bit or 8 bit (basically: ARRAY [0..numBits/8] OF BYTE vs. ARRAY [0..numBits-1] OF BOOL)
“input registers” / “holding registers” : data item size of 16 bit (basically: ARRAY [0..numRegisters-1] OF UDINT)
overlapping memory blocks, could overlap “registers” with “registers” as well as “registers” with “discrete inputs” / “coils” (caution - hard to use feature)
To support all this the “data model” (TableDefinitions) defines zero or more TableSection for each of the MODBUS “primary tables” (TableDefinition).
Some more or less obvious limitations:
all “data items” in one section need to have the same TableSection.uiDataItemSize
all “data item” index in one “primary table” have to be unique, so no section index overlap is allowed of course
read/write requests must not span more than one section
“data item” offset / “data item” numbers
Please note: unlike standard MODBUS, in CODESYS MODBUS the “data item” numbers are equal to the “data addresses”. The MODBUS standard states: “In the MODBUS data Model each element within a data block is numbered from 1 to n.” In CODESYS MODBUS the “data items” are numbered from 0 to n-1.
- InOut:
Scope
Name
Type
Initial
Comment
Input
xEnable
BOOL
FALSE
Enables the server, take over the configuration information fcsSupported and dataModel. If the “data model” (tableDefinitions) contains configuration errors, the Server will not got busy (xBusy = FALSE).
fcsSupported
Constants.SUPPORTED_FCS_SIMPLE_SERVER
Supported “function codes”, accepted at xEnable FALSE => TRUE. In case fcsSupported is not assigned by the application it defaults to Constants.SUPPORTED_FCS_SIMPLE_SERVER.
dataModel
“data model”, accepted at xEnable FALSE => TRUE.
tInactivityInfoTime
UDINT
0
“inactivity info time” (in milliseconds). If no valid requests are received in this time xInactive is signaling inactivity - default = 0 -> no “inactivity info”.
Output
xRunning
BOOL
Server is up and running, waiting for requests.
xError
BOOL
Error
eErrorID
Error status
xInactive
BOOL
No valid requests received for tInactivityTimeOut.
udiNumMsgRecv
UDINT
Number of request messages received since enabling the Server.
udiNumMsgReply
UDINT
Number of reply messages send since enabling the Server.
udiNumMsgExcReply
UDINT
Number of exception reply messages send since enabling the Server.
udiNumMsgExcReplyIllFct
UDINT
Number of exception reply messages send since enabling the Server, signaling illegal function.
udiNumMsgExcReplyIllDataAdr
UDINT
Number of exception reply messages send since enabling the Server, signaling illegal data address.
udiNumMsgExcReplyIllDataValue
UDINT
Number of exception reply messages send since enabling the Server, signaling illegal data value.
xReadRequest
BOOL
Read request(s) happened since last call, rejected requests included.
udiNumReadRequests
UDINT
Read request counter, rejected requests included.
xWriteRequest
BOOL
Write request(s) happened since last call, rejected requests included.
udiNumWriteRequests
UDINT
Write request counter, rejected requests included.
DataModel
Impl
Server.ProcessMaskWriteRegister
(METH)Server.ProcessReadCoils
(METH)Server.ProcessReadDiscreteInputs
(METH)Server.ProcessReadHoldingRegisters
(METH)Server.ProcessReadInputRegisters
(METH)Server.ProcessReadWriteMultipleRegisters
(METH)Server.ProcessRequestFallback
(METH)Server.ProcessWriteMultipleCoils
(METH)Server.ProcessWriteMultipleRegisters
(METH)Server.ProcessWriteSingleCoil
(METH)Server.ProcessWriteSingleRegister
(METH)
Log
Server.SupportFc
(METH)Server.SupportsFc
(METH)