Send data via CPU or MCU port
This instructions sends data using a send buffer to external devices (computer, measuring instrument, bar code reader, etc.) connected to the specified communication port. 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.
Input
Send buffer
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 between "Program controlled" and MEWTOCOL master/slave.
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
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.
F159_MTRN is encapsulated in the following instructions:
SendCharacters
SendCharactersAndClearString
ClearReceiveBuffer
SetCommunicationMode
if the area specified using the index modifier exceeds the limit.
if the number of bytes to be sent specified by n_Number 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
if the area specified using the index modifier exceeds the limit.
if the number of bytes to be sent specified by n_Number 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
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.
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
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.
F159_MTRN sends the data from the first element of the send buffer (awSendBuffer[0]) as specified by s_Start. The length of the string to be sent (8 bytes) is set at n_Number. Use the function LEN to calculate the number of bytes. The data is output from COM port 1 as specified by d_Port.
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_F,F159_MTRN!,,17,1,25,7,,?DEN?Ds_Start?Dn_Number?Dd_Port?AENO);
B(B_VARIN,,awSendBuffer[0],15,3,17,5,);
B(B_VARIN,,1,15,5,17,7,);
B(B_F,LEN!,,9,3,14,6,,?DIN?C);
B(B_VARIN,,sSendData,7,4,9,6,);
L(5,3,17,3);
L(1,3,3,3);
L(14,5,17,5);
L(1,0,1,7);
END_NETWORK_BODY
END_NET_WORK
END_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 *)
F159_MTRN(s_Start := SendBuffer[0], n_Number := LEN(sSendData), d_Port :=16#0302);
end_if;