ServerTCP_extended (FB)

FUNCTION_BLOCK ServerTCP_extended EXTENDS ModbusFB.ServerTCP

MODBUS TCP server (slave) with non-standard extensions.

ServerTCP_extended actually supports beyond the ServerTCP features: - “wide register” (registers > 16bit) Other non-standard extensions might be added here, but not on ServerTCP.

“wide registers” and endianess

The MODBUS standard defines the length of input / holding registers to read/write with 16-bit - no way out of this. The message definitions in the MODBUS standard come with some room for non-standard interpretation. FC03 Read Holding Registers should be used as an example here:

Request: Quantity of Registers Response: Byte count

So a non-standard MODBUS server can inform a client in the response indirectly about the register width (Response:Byte count = Request:Quantity of Registers * register width in Bytes). This fact leaded some vendors to implement MODBUS devices with registers > 16bit. Because the CODESYS ModbusFB lib should be usable with such non-standard devices (clients as well as servers) there is a Server*_extended and some related ClientRequest*RegistersWide in this library. Following client requests can be used with “wide registers”: - Read Holding Registers - Read Input Registers - Write Multiple registers - Read/Write Multiple registers

Following client requests can not be used with “wide registers” because of their MODBUS protocol data unit (PDU) definition: - Write Single Register - Mask Write Register because the “data item” width is explicitly defined to be 16bit.

A standard MODBUS client requesting register data from such a non-standard MODBUS server, unfortunately requesting register data from a register > 16bit gets confronted with an invalid Response: Byte count <> Quantity of Registers * 2, and will most likely drop such a response as invalid or less likely put out error/warning/information on this fact.

The MODBUS standard defines byte ordering in MODBUS messages to read/write 16-bit registers. The MODBUS standard doesnt define anything beyond this - so there is no rule for byte ordering in “wide registers”. This ServerTCP_extended is using the same byte ordering for register data > 16bit as defined in the MODBUS standard (“big-Endian” representation). So for example register size 32bit value 0x12345678 - the first byte sent is 0x12 then 0x34, 0x56, 0x78.

Please visit https://forge.codesys.com/prj/codesys-example/modbus/home to find examples.

InOut:

Scope

Name

Type

Initial

Comment

Inherited from

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).

Server

fcsSupported

SupportedFcs

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|.

Server

dataModel

TableDefinitions

“data model”, accepted at xEnable FALSE => TRUE.

Server

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”.

Server

Output

xRunning

BOOL

Server is up and running, waiting for requests.

Server

xError

BOOL

Error

Server

eErrorID

Error

Error status

Server

xInactive

BOOL

No valid requests received for tInactivityTimeOut.

Server

udiNumMsgRecv

UDINT

Number of request messages received since enabling the Server.

Server

udiNumMsgReply

UDINT

Number of reply messages send since enabling the Server.

Server

udiNumMsgExcReply

UDINT

Number of exception reply messages send since enabling the Server.

Server

udiNumMsgExcReplyIllFct

UDINT

Number of exception reply messages send since enabling the Server, signaling illegal function.

Server

udiNumMsgExcReplyIllDataAdr

UDINT

Number of exception reply messages send since enabling the Server, signaling illegal data address.

Server

udiNumMsgExcReplyIllDataValue

UDINT

Number of exception reply messages send since enabling the Server, signaling illegal data value.

Server

xReadRequest

BOOL

Read request(s) happened since last call, rejected requests included.

Server

udiNumReadRequests

UDINT

Read request counter, rejected requests included.

Server

xWriteRequest

BOOL

Write request(s) happened since last call, rejected requests included.

Server

udiNumWriteRequests

UDINT

Write request counter, rejected requests included.

Server

Input

wsInterfaceName

WSTRING(255)

ETH interface name to bind to, “” to bind to any ETH interface. Only read when rising edge on xEnable occurs.

ServerTCP

uiPort

UINT

502

ETH port to use. Only read when rising edge on xEnable occurs.

ServerTCP

xReset

BOOL

FALSE

Reset the server.

ServerTCP

udiLogOptions

UDINT

LoggingOptions.ServerStartStop

Logging options.

ServerTCP

Output

uiConnectedClients

UINT

Number of actually connected clients.

ServerTCP