Functions of the block COM_SET_PROT

The block COM_SET_PROT can be used for different functions:

  • Switching between two different protocols, for example ASCII / Modbus
  • Switching the interface parameters of a protocol, for example changing the baudrate
  • Re-initialization of an interface protocol (for example, if an interface “hangs up”)
  • Switching between “Online access” and ASCII/Modbus/SysLibCom depending on the current PLC mode, for example STOP=Online access, RUN=Modbus (or ASCII, SysLibCom). In this case, the parameter “Enable login” does not have to be activated and the interface can use other interface parameters than required for “Online access” (see the following program example).

Example for switching COM2 between “Online access” and Modbus (master)

1. Setting in the PLC configuration:

-> Protocol with index 0: Online access

../_images/4a95836fe38c62cd0a33139000eba54e

-> Protocol with index 1: Modbus (master)

../_images/388e5389e38c631b0a33139000eba54e1

2. Setting the system events START and STOP in the task configuration:

../_images/3a4c016ae38c63790a33139000eba54e1

3. Call of block COM_SET_PROT in system events

FUNCTION callback_Start: DWORD

VAR_INPUT

dwEvent : DINT;

dwFilter: DINT;

dwOwner : DINT;

END_VAR

COM_SET_PROT(EN := FALSE); (* for edge creation *)

COM_SET_PROT(EN := TRUE, COM := 2, IDX := 1); (* switch to Modbus *)

FUNCTION callback_Stop : BOOL

VAR_INPUT

dwEvent : DINT;

dwFilter: DINT;

dwOwner : DINT;

END_VAR

COM_SET_PROT(EN := FALSE); (* for edge creation *)

COM_SET_PROT(EN := TRUE, COM := 2, IDX := 0); (* switch to Online access *)