This function writes characters to the logical device i_stComIecId. It writes i_diSize characters. When calling, transfer the address of a variable to i_diBuffer. The characters to be written are taken from this variable. The function transfers the data to the serial driver and returns. The driver performs the write operation autonomously.
Input |
Data type |
Description |
---|---|---|
i_stComIecId |
ST_LogicalAddress |
Device selection |
i_diBuffer |
DINT |
Buffer address |
i_diSize |
DINT |
Number of characters that have to be written |
Data type |
Description |
---|---|
DINT |
0...: Number of bytes written -1: i_stComIecId invalid -2: other error detected. Contact your Schneider Electric representative. |
Task
Write a program for testing the COM2 serial interface. Characters are sent via the serial interface COM2. The transmission and reception lines (pin 2 -> 5 pin 3 -> 4) are interconnected in a COM4 plug. The sent characters are received again by the COM2.
Declaration
PROGRAM ComIecLoopBackDemo
VAR
lState: DINT := 1;
bStart: BOOL := FALSE;
lResultOpen: DINT;
lResultWrite: DINT;
lResultReadCount: DINT;
lResultRead: DINT;
lReadCount: DINT := 0;
pszRBuffer: STRING := 'PacDriveM';
pszWBuffer: STRING := 'ELAU the Future of Packaging';
lWSize: DINT := 28;
END_VAR
Program
CASE lState OF
1:
IF bStart THEN
lResultOpen := FC_ComIecOpen(_ComIec); lState := 2; END_IF
2:
lResultWrite := FC_ComIecWrite(_ComIec, ADR(pszWBuf fer), lWSize);
pszRBuffer := 'PacDriveM';
lState:= 3;
3:
lResultReadCount := FC_ComIecGetReadCount(_ComIec);
IF lResultReadCount = lWSize THEN
lResultRead := FC_ComIecRead(_ComIec, ADR(pszRBuffer), lWSize);
lReadCount := lReadCount + lResultReadCount;
IF bStart THEN
lState := 2;
ELSE
FC_ComIecClose(_ComIec);
lState := 1;
END_IF
END_IF
END_CASE