ServerSerial
(FB)
FUNCTION_BLOCK ServerSerial EXTENDS Server IMPLEMENTS ISysComUser
MODBUS serial server (slave).
For details about supported function codes and “data model” see Server.
Please note: some input variables related to connection configuration are read when rising edge on xEnable occurs. To change connection configuration the application needs to - disconnect (xEnable := FALSE and execute the FB) - modify the related input variables - connect (xEnable := TRUE and execute the FB)
The Server provides some statistics of received valid requests messages and sent reply messages. Invalid messages are dropped at the communication level, so doesnt appear in the statistics. To analyse situations where invalid reply messages might occur, you can use udiLogOptions with LoggingOptions.WarnOnReceivedInvalidFrames.
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).
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.
Input
uiUnitId
UINT
1
Unit-Id / Slave address. Only read when rising edge on xEnable occurs. Slave address has to be in range 1 .. 247 according to MODBUS standard.
iPort
SysCom.SYS_COM_PORTS
SysCom.SYS_COM_PORTS.SYS_COMPORT_NONE
Serial port. Only read when rising edge on xEnable occurs.
dwBaudrate
SysCom.SYS_COM_BAUDRATE
SysCom.SYS_COM_BAUDRATE.SYS_BR_115200
Baud rate. Only read when rising edge on xEnable occurs.
byDataBits
BYTE
8
Number of data bits/BYTE, 4-8. Only read when rising edge on xEnable occurs.
eParity
SysCom.SYS_COM_PARITY
SysCom.SYS_COM_PARITY.SYS_NOPARITY
Parity. Only read when rising edge on xEnable occurs.
eStopBits
SysCom.SYS_COM_STOPBITS
SysCom.SYS_COM_STOPBITS.SYS_ONESTOPBIT
Stop bits. Only read when rising edge on xEnable occurs.
eDTRcontrol
SysCom.SYS_COM_DTR_CONTROL
SysCom.SYS_COM_DTR_CONTROL.SYS_DTR_CONTROL_DISABLE
DTR control. Only read when rising edge on xEnable occurs.
eRTScontrol
SysCom.SYS_COM_RTS_CONTROL
SysCom.SYS_COM_RTS_CONTROL.SYS_RTS_CONTROL_DISABLE
RTS control. Only read when rising edge on xEnable occurs.
eRtuAscii
RtuAscii.RTU
RTU / ASCII. Only read when rising edge on xEnable occurs.
udiLogOptions
UDINT
LoggingOptions.ServerStartStop
Logging options.