SendData

Send data via communication port or Ethernet user connection

This instruction sends data using a send buffer to external devices (computer, measuring instrument, bar code reader, etc.) connected to the specified communication port or via Ethernet user connection. If applied to the CPU's COM port, it also clears the receive buffer, resets the "reception done" flag and allows further reception of data.

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

Start (WORD, INT, UINT)

Send buffer

NumberOfBytes (WORD, INT, UINT)

Number of bytes to send:

  • Negative value: The end code selected in the system registers is not appended to the send string.

  • 0 (zero bytes): Prepare system to receive further data

  • 16#8000: Toggle communication mode

Remarks

  • When the specified number of bytes has been sent, the "transmission done" flag turns to TRUE. New data may be sent or received. Any send instruction turns the "transmission done" flag to FALSE and no data can be received. Evaluation of the "transmission done" flag may be useful in cases where no response can be expected, e.g. with broadcast messages.

  • SendData is encapsulated in the following instructions:

    • SendCharacters

    • SendCharactersAndClearString

    • ClearReceiveBuffer

    • SetCommunicationMode

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if the area specified using the index modifier exceeds the limit.

  • if the number of bytes to be sent specified by NumberOfBytes is outside of the specified area.

  • Flags only for the MCU:

    • if the MCU unit does not exist in the specified slot or zero bytes should be sent.

    • if 16#8000 is specified in MEWTOCOL-COM Master/Slave mode

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if the area specified using the index modifier exceeds the limit.

  • if the number of bytes to be sent specified by NumberOfBytes is outside of the specified area.

  • Flags only for the MCU:

    • if the MCU unit does not exist in the specified slot or zero bytes should be sent.

    • if 16#8000 is specified in MEWTOCOL-COM Master/Slave mode

Example

In this example the characters of the string sSendData are transmitted. Define a send buffer for 30 bytes (ARRAY [0...15] OF WORD) and copy 8 characters of a string ("ABCDEFGH") into the buffer.

Send buffer layout:

The first word of the send buffer (offset 0) is reserved for the number of bytes to be sent. Therefore, copy the data into offset 1 (SendBuffer[1]).

When sending begins (the execution condition of the send instruction turns to TRUE), the value in offset 0 is set to 8. At the end of transmission, the value in offset 0 is automatically reset to 0. The data in offset 1 to offset 4 is sent in order from the lower byte.

Transmit the characters "ABCDEFGH" to an external device connected to COM port 1. For start code and end code the default settings "No-STX" and "CR" are selected.

  1.  (1)  "Transmission done" flag
  2.  (2) Execution condition
  3.  (3) Execution of send instruction
  4.  (4) Transmission

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
		bSend: BOOL:=FALSE;
			(*activates function*)
		sSendData: STRING[30]:='ABCDEFGH';
			(*up to 30 chars*)
		awSendBuffer: ARRAY [0..15] OF WORD:=[16(0)];
			(*for 30 chars + 1 word*)
	END_VAR

POU body

When bSend is TRUE, F10_BKMV copies the characters of the string at sSendData to the buffer awSendBuffer beginning at awSendBuffer[1]. The first two words of a string contain the string header information (maximum number of characters and current number of characters). The string header must not be copied into the buffer. Therefore, enter an offset of 2 to the starting address of the string before copying the data. Make sure the size of the send buffer is sufficient for all the data to be sent. Each element of the array at SendBuffer can contain two characters of the string at SendString. SendBuffer[0] is reserved for the total number of bytes to be sent.

SendData sends the data from the first element of the send buffer (awSendBuffer[0]) as specified by Start. The length of the string to be sent (8 bytes) is set at NumberOfBytes. Use the function LEN to calculate the number of bytes. The data is output from COM port 1 as specified by Port.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 10 ;
        NETWORK_BODY
B(B_COMMENT,,Creating the send buffer,1,0,14,1,);
B(B_CONTACT,,bSend,3,2,5,4,R);
B(B_VAROUT,,awSendBuffer[1],26,4,28,6,);
B(B_F,F10_BKMV,,18,2,26,7,,?DEN?D@'s1'?Ds2?AENO?Cd);
B(B_F,Adr_Of_VarOffs_I!,,9,3,18,7,,?D@'Var'?DOffs?CAdr);
B(B_VARIN,,sSendData,7,4,9,6,);
B(B_F,AdrLast_Of_Var_I!,,9,7,18,9,,?D?C);
B(B_VARIN,,sSendData,7,7,9,9,);
B(B_VARIN,,2,7,5,9,7,);
L(5,3,18,3);
L(1,3,3,3);
L(18,3,18,4);
L(1,0,1,10);
L(18,6,18,8);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 7 ;
        NETWORK_BODY
B(B_COMMENT,,bSend sign of the bSend buffer via the serial interface,1,0,25,1,);
B(B_CONTACT,,bSend,3,2,5,4,R);
B(B_VARIN,,awSendBuffer[0],14,4,16,6,);
B(B_F,LEN!,,9,4,14,7,,?DIN?C);
B(B_VARIN,,sSendData,7,5,9,7,);
B(B_F,E_SendData!,,16,1,26,7,,?DEN?DPort?DStart?DNumberOfBytes?AENO);
B(B_VARIN,,1,14,3,16,5,);
L(1,3,3,3);
L(5,3,16,3);
L(14,6,16,6);
L(1,0,1,7);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

if (DF(bSend)) then
    (* Copy all characters of the SendString to the SendBuffer from position 1 *)
    F10_BKMV(s1_Start := Adr_Of_VarOffs(Var := sSendData, Offs :=2), 
         s2_End := AdrLast_Of_Var(sSendData), 
         d_Start => awSendBuffer[1]);
    (* Send the data of the SendBuffer via the COM Port 2 of the MCU unit in slot 3 *)
    (* In SendBuffer[0] the number of bytes not yet transmitted is stored *)         
    SendData(Port :=1, start := awSendBuffer[0], NumberOfBytes := LEN(sSendData));
end_if;

IsTransmissionDone

Modified on: 2022-01-14Feedback on this pagePanasonic hotline