Function Block COM_SET_PROT

Function Block COM_SET_PROT: COM_SET_PROTMODBUS (master):

  1. In the device tree, append the COM2 - Multi protocol to the COM2 node (Add object).

  2. Append the COM2 - Online Access protocol to the COM2 - Multi node (Protocol with index 0).

  3. Append the COM2 - Modbus protocol to the COM2 - Multi node (Protocol with index 1).

    ../_images/388e5389e38c631b0a33139000eba54e
  4. Set the system events START and STOP in the task configuration:

    ../_images/3a4c016ae38c63790a33139000eba54e
  5. 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 *)