Write data to slave with type and offset
Use this instruction to write data from a master to a slave via the communication port using the MEWTOCOL-COM or Modbus RTU protocol, as defined in the system registers of the port used. For data transmissions using the Modbus protocol, the compiler generates Modbus commands based on the Modbus reference numbers.
Input
Specifies the communication ports depending on the PLC type:
COM port e.g. SYS_COM0_PORT
Ethernet port e.g. SYS_ETHERNET_USER_CONNECTION_1
MCU/SCU e.g. 16#xx01 (xx = slot number) in COM01
Station number of the slave (MEWTOCOL: 1–99, MODBUS: 1–255, Broadcasting: 0)
Set to 1, if a SYS_ETHERNET_USER_CONNECTION_xx is applied to input Port
Source address on the master for the data to be written to the slave.
Destination address type in the slave. Specify an offset of zero, e.g. DT0 or WL0.
Offset of the starting address on the slave to which the data is written. The address type is defined by SlaveWordAddressType.
Number of words (bits) to be transmitted.
Either:
Number of words
for Modbus RTU: 16#001–16#07F
for MEWTOCOL-COM: 16#001–16#1FD or 16#001–16#1B (FP0, FP-e)
Or:
Control word for bit transfer: 16#8T0F with T as "to bit" in the master and F as "from bit" in the slave (does not apply to FP7).
Instead of using this F instruction, we recommend using the corresponding FP7 instruction: FP_WRITE_TO_SLAVE_AREA_OFFS.
The F145 or F146 instructions can only be executed if neither instruction is active. Evaluate the "F145/F146 not active" flag in your program to check the state of the instructions.
The F145 instruction only requests that data be sent to the slave. The actual processing takes place at the end of the scan.
Evaluate the "F145/F146 error" flag to check whether transmission has completed normally or with an error.
When broadcasting (SlaveAddress set to 0), make sure transmission is executed only after the maximum scan time has elapsed.
The F145 or F146 instructions cannot be executed if the destination address is a special internal flag (from R9000), a special data register (from DT9000/DT90000), or a file register FL.
If slave or master data exceed the available address range.
If SlaveWordAddressType: Offset ¹ 0
If the communication mode is not set to MEWTOCOL-COM Master/Slave or Modbus RTU Master/Slave.
If the COM port selected requires a communication cassette that has not been installed.
If slave or master data exceed the available address range.
If SlaveWordAddressType: Offset ¹ 0
If the communication mode is not set to MEWTOCOL-COM Master/Slave or Modbus RTU Master/Slave.
If the COM port selected requires a communication cassette that has not been installed.
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
bBool1: BOOL:=FALSE;
bRead1: BOOL:=FALSE;
bWrite1: BOOL:=FALSE;
Bool16_OverlappingDut_1: BOOL16_OVERLAPPING_DUT;
END_VAR
VAR_EXTERNAL
Printer: WORD:=0;
END_VAR
VAR
END_VAR
The system variable sys_bPulse1s is copied to bBool1 and Bool16_OverlappingDut_1.b0. If bWrite1 and sys_bIsComPort1F145F146NotActive are set to TRUE, bBool1 is written to the output Y38 of slave 2 via Bool16_OverlappingDut_1.b0.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 3 ;
NETWORK_BODY
B(B_CONTACT,,sys_bPulse1s,3,1,5,3,);
B(B_COIL,,bBool1,15,1,17,3,);
L(5,2,15,2);
L(1,2,3,2);
L(1,0,1,3);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 3 ;
NETWORK_BODY
B(B_CONTACT,,bBool1,3,1,5,3,);
B(B_COIL,,Bool16_OverlappingDut_1.b0,15,1,17,3,);
L(5,2,15,2);
L(1,2,3,2);
L(1,0,1,3);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 13 ;
NETWORK_BODY
B(B_CONTACT,,sys_bIsComPort1F145F146NotActive,8,1,10,3,);
B(B_CONTACT,,bWrite1,18,1,20,3,);
B(B_COIL,,bRead1,46,1,48,3,S);
B(B_VARIN,,2,23,3,25,5,);
B(B_VARIN,,Bool16_OverlappingDut_1.w0,23,4,25,6,);
B(B_VARIN,,WY0,23,5,25,7,);
B(B_VARIN,,3,23,6,25,8,);
B(B_VARIN,,16#8800,23,7,25,9,);
B(B_F,F145_WRITE_DATA_TYPE_OFFS!,Instance,25,0,40,9,,?DEN?DPort?DSlaveAddress?DMasterWordData?DSlaveWordAddressType?DSlaveWordAddressOffs?DNumberOfWords_BitsInWords?AENO);
B(B_VARIN,,SYS_COM1_PORT,23,2,25,4,);
B(B_COIL,,bWrite1,42,1,44,3,E);
L(1,2,8,2);
L(10,2,18,2);
L(20,2,25,2);
L(44,2,46,2);
L(40,2,42,2);
L(1,0,1,13);
END_NETWORK_BODY
END_NET_WORK
END_BODY
bBool1 := sys_bPulse1s;
Bool16_OverlappingDut_1.b0 := bBool1;
if (bWrite1 and sys_bIsComPort1F145F146NotActive) then
F145_WRITE_DATA_TYPE_OFFS(Port := SYS_COM1_PORT,
SlaveAddress := 2,
MasterWordData := Bool16_OverlappingDut_1.w0,
SlaveWordAddressType := WY0,
SlaveWordAddressOffs := 3,
NumberOfWords_BitsInWords := 16#8800);
bRead1 := true;
bWrite1 := false;
end_if;