FP_READ_FROM_SLAVE

Read data from slave

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.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_READ_FROM_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.

Parameters

Input

Port (WORD, INT, UINT)

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

StationNumber (WORD, INT, UINT)

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

SlaveAddress (WORD, INT, UINT)

Source address on the slave from which the data is requested.

Output

Destination (ANY)

Word area or register on the master unit to which the requested data is written.

Result (ANY)
  • For FP7 only:
    • 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

  • For other PLCs: set to 0

Time chart

  1.  (1) Master communication clear-to-send flag,e.g. sys_bIsEthernetUserConnection1MasterCommunication
  2.  (2) Check that the master communication clear-to-send flag is TRUE and check that the master communication sending flag is FALSE
  3.  (3) Master communication sending flag, e.g. sys_bIsEthernetUserConnection1MasterCommunicationActive

    While sending: Master communication sending flag is TRUE

    Sending done: Master communication sending flag is FALSE

  4.  (4) Execute this instruction
  5.  (5) Master communication sending done flag, e.g. sys_bIsEthernetUserConnection1CommunicationError

    Normal completion: FALSE

    Abnormal completion: TRUE

  6.  (6) Send data
  7.  (7) Response reception processing

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • If slave or master data exceed the available address range.

  • 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.

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • If slave or master data exceed the available address range.

  • 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.

Example

Global variables

In the global variable list you define variables that can be accessed by all POUs in the project.

POU header

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_EXTERNAL
		g_Peripherie_SlaveResult_Address: ARRAY[0..9] OF REAL:=[10(0)];
	END_VAR
	VAR
		bReadResult: BOOL:=FALSE;
		wReadFromSlaveResult: WORD:=0;
			(*result of write to slave instruction*)
		iSlaveStationNumber: INT:=0;
			(*slave station number*)
		arrResults: ARRAY [0..9] OF REAL:=[10(0.0)];
			(*Array of results to be read from slave station*)
		iSlaveMemoryArea: INT:=5;
			(*memory Area in slave station*)
		iSlaveMemoryOffset: INT:=100;
		iSlaveMemorySize: INT:=1;
	END_VAR

LD body

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_VARIN,,SYS_COM1_PORT,19,2,21,4,);
B(B_VARIN,,iSlaveStationNumber,19,3,21,5,);
B(B_CONTACT,,bReadResult,8,1,10,3,);
B(B_VAROUT,,wReadFromSlaveResult,38,3,40,5,);
B(B_VAROUT,,arrResults,38,2,40,4,);
B(B_F,FP_READ_FROM_SLAVE!,,21,0,33,6,,?DEN?DnPort?DStationNumber?DSlaveAddress?AENO?CDestination?CResult);
B(B_VARIN,,g_Peripherie_SlaveResult_Address,19,4,21,6,);
L(1,2,8,2);
L(10,2,21,2);
L(33,3,38,3);
L(33,4,38,4);
L(1,0,1,8);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

if (bReadResult) then
    FP_READ_FROM_SLAVE(Port := SYS_COM1_PORT, StationNumber := iSlaveStationNumber,
                       SlaveAddress := g_Peripherie_SlaveResult_Address, Destination => arrResults[0], 
                       Result => wReadFromSlaveResult);
end_if;

Modified on: 2022-03-02Feedback on this pagePanasonic hotline