Write data to slave
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.Make sure the same protocol is set for master and slave.Master and slave must have matching memory areas. If the slave data is not available in the user area of the master, use FP_WRITE_TO_SLAVE_AREA_OFFS or FP_MODBUS_MASTER.
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)
Set to 1, if a SYS_ETHERNET_USER_CONNECTION_xx is applied to input Port
Word area or register on the master unit for the data to be written to the slave.
Output
Destination address on the slave to which the requested data is written.
0: Normal completion
1: Communication port is used for master communication
2: Communication port is used for slave communication
3: No. of master communication instructions that can be used at the same time is exceeded
4: Sending timeout
5: Response reception timeout
6: Received data error
While sending: Master communication sending flag is TRUE
Sending done: Master communication sending flag is FALSE
Normal completion: FALSE
Abnormal completion: TRUE
If the COM port selected requires a communication cassette that has not been installed.
In the global variable list you define variables that can be accessed by all POUs in the project.
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
VAR
wWriteToSlaveResult: WORD:=0;
(*result of write to slave instruction*)
iSlaveStationNumber: INT:=0;
(*slave station number*)
arrParameters: ARRAY [0..15] OF DINT;
(*Array of parameters to be send to slave station*)
bSetParameters: BOOL:=FALSE;
END_VAR
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_F,FP_WRITE_TO_SLAVE!,,19,0,30,6,,?DEN?DnPort?DStationNumber?DSource?AENO?CSlaveAddress?CResult);
B(B_VARIN,,SYS_COM2_PORT,17,2,19,4,);
B(B_VARIN,,iSlaveStationNumber,17,3,19,5,);
B(B_VARIN,,arrParameters,17,4,19,6,);
B(B_VAROUT,,g_Peripherie_SlaveParameter_Address,30,2,32,4,);
B(B_VAROUT,,wWriteToSlaveResult,30,3,32,5,);
B(B_CONTACT,,bSetParameters,4,1,6,3,);
L(1,2,4,2);
L(6,2,19,2);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY
if bSetParameters then
FP_WRITE_TO_SLAVE(Port := SYS_COM2_PORT,
StationNumber := iSlaveStationNumber,
Source := arrParameters,
SlaveAddress => g_Peripherie_SlaveParameter_Address,
Result => wWriteToSlaveResult);
end_if;