The fast PLC task
Here you can unpack the complete PLC sources: TutorialSample.zip
Add the following PLC code to the declaration part of P_SerialComm_HighSpeed:
PROGRAM P_SerialComm_HighSpeed
VAR
fbSerialLineCtrl : FB_IEC870_SerialLineCtrl := (
Mode := SERIALLINEMODE_PC_COM_PORT, (*SERIALLINEMODE_KL6_5B_STANDARD *)
Baudrate := 19200,
NoDatabits := 8,
Parity := PARITY_EVEN,
Stopbits := 1,
Handshake := HANDSHAKE_NONE,
ContinousMode := FALSE );
serial_in AT%IB4000 : PcComInData;
serial_out AT%QB4000 : PcComOutData;
KL6_in AT%IB4100 : KL6inData5B;
KL6_out AT%QB4100 : KL6outData5B;
hSerial : T_HSERIALCTRL;
END_VAR
and the instance is called in the program part:
fbSerialLineCtrl( pComIn := SEL( fbSerialLineCtrl.Mode = SERIALLINEMODE_KL6_5B_STANDARD, ADR( serial_in ), ADR( KL6_in ) ),
pComOut := SEL( fbSerialLineCtrl.Mode = SERIALLINEMODE_KL6_5B_STANDARD, ADR( serial_out ), ADR( KL6_out ) ),
SizeComIn := SEL( fbSerialLineCtrl.Mode = SERIALLINEMODE_KL6_5B_STANDARD, SIZEOF( serial_in ), SIZEOF( KL6_in ) ),
hSerial := hSerial );
You can find a Twincat System Manager configuration fitting to the PLC on the example overview page.
Communication via standard PC COMx interface
- In this case the mode parameter is set to the value: SERIALLINEMODE_PC_COM_PORT.
- At the TwinCAT System Manager the serial_in and serial_out variables are bound to the corresponding IO variables of the serial interface.
- The interface will and has to be configured within the TwinCAT System Manager (Baudrate, Parity etc.). Other communication parameters at the FB_IEC870_SerialLineCtrl function block are not relevant at this mode.
Communication via serial Beckhoff Bus Terminals KL6xxx
- In this case the mode parameter is set to the value: SERIALLINEMODE_KL6_5B_STANDARD.
- At the TwinCAT System Manager the KL6_in and KL6_out variables are bound to the corresponding IO variables of the serial terminal KL6xxx.
- The interface is configured within the TwinCAT PLC by the instance of the FB_IEC870_SerialLineCtrlfunction block. Communication parameters like baud rate, parity etc. must be set via this function block.
Communication via serial Beckhoff Bus Terminals EL6xxx
PROGRAM P_SerialComm_HighSpeed
VAR
fbSerialLineCtrl : FB_IEC870_SerialLineCtrl := ( Mode := SERIALLINEMODE_EL6_22B );
EL6_in AT%IB4100 : EL6inData22B;
EL6_out AT%QB4100 : EL6outData22B;
hSerial : T_HSERIALCTRL;
END_VAR
fbSerialLineCtrl( pComIn := ADR( EL6_in ),
pComOut := ADR( EL6_out ),
SizeComIn := SIZEOF( EL6_in ),
hSerial := hSerial );
- In this case the mode parameter is set to the value: SERIALLINEMODE_EL6_22B.
- At the TwinCAT System Manager the EL6_in and EL6_out variables are bound to the corresponding IO variables of the serial terminal EL6xxx.
- The interface will and has to be configured within the TwinCAT System Manager (Baudrate, Parity etc.). Other communication parameters at the FB_IEC870_SerialLineCtrl function block are not relevant at this mode.