FP_READ_FROM_SLAVE_AREA_OFFS

Read data from slave with 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. Make sure the same protocol is set for master and slave. Master and slave must have matching memory areas.

For data transmissions using the Modbus protocol, the compiler generates Modbus commands based on the Modbus reference numbers.

Parameters

Input

Port (INT)

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–247)

Set to 1, if a SYS_ETHERNET_USER_CONNECTION_xx is applied to input Port

SlaveMemoryArea (WORD, INT, UINT)

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

Flag memory areas

SYS_MEMORY_AREA_R

SYS_MEMORY_AREA_L

SYS_MEMORY_AREA_X

SYS_MEMORY_AREA_Y

Flags

SYS_MEMORY_AREA_WR

Set value timer/counter

SYS_MEMORY_AREA_SV

Elapsed value timer/counter

SYS_MEMORY_AREA_EV

Data registers

SYS_MEMORY_AREA_DT

Link flags

SYS_MEMORY_AREA_WL

Link registers

SYS_MEMORY_AREA_LD

File registers

SYS_MEMORY_AREA_FL

Input registers

SYS_MEMORY_AREA_WX

Output registers

SYS_MEMORY_AREA_WY

SlaveMemoryOffset (WORD, INT, UINT)

Offset of the starting address on the slave from which the data is requested.

Words_Bits (WORD, INT, UINT)

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

Destination(ANY)

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

Result(ANY)

For FP7 only: For a description of all error codes, please refer to the table of Modbus/MEWTOCOL communication error codes.

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) Processing of the received response

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

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
		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*)
		iSlaveMemoryOffset: INT:=200;
		iSlaveMemorySize: INT:=1;
	END_VAR
	VAR CONSTANT 
		iSlaveMemoryArea: INT:=5;
			(*memory Area in slave station*)
	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,15,2,17,4,);
B(B_VARIN,,iSlaveStationNumber,15,3,17,5,);
B(B_CONTACT,,bReadResult,4,1,6,3,);
B(B_VAROUT,,wReadFromSlaveResult,34,3,36,5,);
B(B_VAROUT,,arrResults,34,2,36,4,);
B(B_VARIN,,SYS_MEMORY_AREA_DT,15,4,17,6,);
B(B_VARIN,,iSlaveMemoryOffset,15,5,17,7,);
B(B_VARIN,,iSlaveMemorySize,15,6,17,8,);
B(B_F,FP_READ_FROM_SLAVE_AREA_OFFS!,,17,0,34,8,,?DEN?DnPort?DStationNumber?HSlaveMemoryArea?DSlaveMemoryOffset?DWords_Bits?AENO?CDestination?CResult);
L(1,2,4,2);
L(6,2,17,2);
L(1,0,1,8);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

if (bReadResult) then
    FP_READ_FROM_SLAVE_AREA_OFFS(Port := SYS_COM1_PORT, 
                                 StationNumber := iSlaveStationNumber, 
                                 SlaveMemoryArea := SYS_MEMORY_AREA_DT, 
                                 SlaveMemoryOffset := iSlaveMemoryOffset, 
                                 Words_Bits := iSlaveMemorySize, 
                                 Destination => arrResults[0], 
                                 Result => wReadFromSlaveResult);
end_if;

Modified on: 2024-10-16Feedback on this pagePanasonic hotline