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
xEnableBOOLFALSE
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).
fcsSupportedConstants.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.
tInactivityInfoTimeUDINT0
“inactivity info time” (in milliseconds). If no valid requests are received in this time xInactive is signaling inactivity - default = 0 -> no “inactivity info”.
Output
xRunningBOOLServer is up and running, waiting for requests.
xErrorBOOLError
eErrorIDError status
xInactiveBOOLNo valid requests received for tInactivityTimeOut.
udiNumMsgRecvUDINTNumber of request messages received since enabling the Server.
udiNumMsgReplyUDINTNumber of reply messages send since enabling the Server.
udiNumMsgExcReplyUDINTNumber of exception reply messages send since enabling the Server.
udiNumMsgExcReplyIllFctUDINTNumber of exception reply messages send since enabling the Server, signaling illegal function.
udiNumMsgExcReplyIllDataAdrUDINTNumber of exception reply messages send since enabling the Server, signaling illegal data address.
udiNumMsgExcReplyIllDataValueUDINTNumber of exception reply messages send since enabling the Server, signaling illegal data value.
xReadRequestBOOLRead request(s) happened since last call, rejected requests included.
udiNumReadRequestsUDINTRead request counter, rejected requests included.
xWriteRequestBOOLWrite request(s) happened since last call, rejected requests included.
udiNumWriteRequestsUDINTWrite request counter, rejected requests included.
DataModelImplServer.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)
LogServer.SupportFc(METH)Server.SupportsFc(METH)