FB_WriteReadVar: Write and Read Function Block
The function block FB_WriteReadVar can be used to:
owrite consecutive internal registers and read back their values in the same execution cycle of the function block (single transaction),
owrite consecutive internal registers and read different registers.
The following graphic shows the pin diagram of the function block FB_WriteReadVar:
The function block FB_WriteReadVar reads and writes internal registers (MW type only) to an external device in the Modbus protocol. The read and write operations are contained in a single transaction. Note that the write operation is performed first.
The table describes the input variables of the function block in the TwidoEmulationSupport library:
Input |
Data type |
Description |
---|---|---|
i_xExecute |
BOOL |
The function is executed on the rising edge of this input. NOTE: When i_xExecute is set to TRUE at the first task cycle in RUNNING after a cold or warm reset, the rising edge is not detected. |
i_xAbort |
BOOL |
Stops the ongoing operation at the rising edge. |
i_iLink |
INT |
Indicates the port used to communicate. o1 = Serial port 1 o2 = Serial port 2 o3 = Ethernet / Modbus TCP |
i_iId |
INT |
Device identifier of targeted external device: oSerial line slave address: 1...247 or oEthernet index: 1...16 (Depends on the link configuration). |
i_iTimeout |
INT |
Set the maximum time to wait to receive a response from the modem. Specified in ms. A value of 0 means no timeout is enforced. |
i_diFirstReadObj |
DINT |
Address of the first object from which values are read. |
i_iReadQuantity |
INT |
Number of objects to read. |
i_pbyReadBuffer |
POINTER TO BYTE |
Address of the buffer in which read object values are stored. |
i_diFirstWriteObj |
DINT |
Address of the first object from which values are written. |
i_iWriteQuantity |
INT |
Number of objects to write. |
i_pbyWriteBuffer |
POINTER TO BYTE |
Address of the buffer in which object values to write are stored. |
i_astRemoteDevices |
ARRAY [1..Gc_uiRemoteAddressTableLen] OF ST_RemoteDevice |
Contains the list of remote device addresses for Modbus TCP communication. |
The table describes the output variables of the function block in the TwidoEmulationSupport library:
Output |
Data type |
Description |
---|---|---|
q_xDone |
BOOL |
q_xDone is set to TRUE when the function is completed successfully. |
q_xBusy |
BOOL |
q_xBusy is set to TRUE while the function is ongoing. |
q_xAborted |
BOOL |
q_xAborted is set to TRUE when the function is stopped with the i_xAbort input. |
q_xError |
BOOL |
q_xError is set to TRUE when the function stops because of a detected error. |
q_etCommError |
SEN.CommunicationErrorCodes |
q_etCommError contains the value of communication error codes SEN.CommunicationErrorCodes. |
q_etOperError |
SEN.OperationErrorCodes |
q_etOperError contains the value of operation error codes SEN.OperationErrorCodes. |