Read data from slave with type and offset
Use this instruction to request data from 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
Destination address type in the slave. Specify an offset of zero, e.g. DT0 or WL0.
Offset of the starting address on the slave from which the data is read. 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).
Output
Word area or register on the master unit to which the requested data is written.
Instead of using this F instruction, we recommend using the corresponding FP7 instruction: FP_READ_FROM_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.
Evaluate the "F145/F146 error" flag to check whether transmission has completed normally or with an error.
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 SlaveWordAddressType: Offset ¹ 0
If SlaveWordAddressType: Offset ¹ 0
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
bBool2: BOOL:=FALSE;
bRead1: BOOL:=FALSE;
bWrite2: BOOL:=FALSE;
Bool16_OverlappingDut_1: BOOL16_OVERLAPPING_DUT;
END_VAR
If bRead1 and sys_bIsComPort1F145F146NotActive are set to TRUE, the output Y38 of slave 2 is read and written to bit 1 of Bool16_OverlappingDut_1.w0. This bit can be accessed by Bool16_OverlappingDut_1.b1 and is copied to bBool2.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 8 ;
NETWORK_BODY
B(B_CONTACT,,bRead1,3,1,5,3,);
B(B_CONTACT,,sys_bIsComPort1F145F146NotActive,12,1,14,3,);
B(B_COIL,,bWrite2,45,1,47,3,S);
B(B_VARIN,,2,22,3,24,5,);
B(B_VARIN,,WY0,22,4,24,6,);
B(B_VARIN,,3,22,5,24,7,);
B(B_VARIN,,SYS_COM1_PORT,22,2,24,4,);
B(B_COIL,,bRead1,41,1,43,3,E);
B(B_F,F146_READ_DATA_TYPE_OFFS!,Instance,24,0,39,8,,?DEN?DPort?DSlaveAddress?DSlaveWordAddressType?DSlaveWordAddressOffs?DNumberOfWords_BitsInWords?AENO?CMasterWordData);
B(B_VARIN,,16#8108,22,6,24,8,);
B(B_VAROUT,,Bool16_OverlappingDut_1.w0,39,2,41,4,);
L(1,2,3,2);
L(5,2,12,2);
L(43,2,45,2);
L(14,2,24,2);
L(39,2,41,2);
L(1,0,1,8);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 3 ;
NETWORK_BODY
B(B_CONTACT,,Bool16_OverlappingDut_1.b1,8,1,10,3,);
B(B_COIL,,bBool2,20,1,22,3,);
L(10,2,20,2);
L(1,2,8,2);
L(1,0,1,3);
END_NETWORK_BODY
END_NET_WORK
END_BODY
if (bRead1 and sys_bIsComPort1F145F146NotActive) then
F146_READ_DATA_TYPE_OFFS(Port := SYS_COM1_PORT,
SlaveAddress := 2,
SlaveWordAddressType := WY0,
SlaveWordAddressOffs := 3,
NumberOfWords_BitsInWords := 16#8108,
MasterWordData => Bool16_OverlappingDut_1.w0);
end_if;
bBool2 := Bool16_OverlappingDut_1.b1;