FC_ComIecWrite - General Information

Overview

Type:

Function

Available as of:

SystemInterface_1.32.6.0

Versions:

Current version

Task

Write character to the logical device.

Description

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.

NOTE: Note for "RS 485 2-wire" that the hardware has to switch (TriState) between transmitting and receiving. Therefore, a waiting period of at least 5 ms is necessary between sending ( FC_ComIecWrite()) and receiving ( FC_ComIecRead()).

Interface

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

Return Value

Data type

Description

DINT

0...: Number of bytes written

-1: i_stComIecId invalid

-2: other error detected. Contact your Schneider Electric representative.

Examples

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