Issue a message with format parameters

Its possible to transfer one or more variables with a message. This example shows how to do it.

 

  1. Create a PLC Project like in the previous Sample
  2. Add following variables to the variable configuration:
  3. The value 'value' will be transferred; The string 'format' describes the data format.
  4. value     : DWORD    := 0;
    format    : STRING   := '%d';
  5. Now Change the configuration for the Event:
  6. (* Event 2 *)
    CfgEvent2.Prio := 0;
    CfgEvent2.bQuitRequired := TRUE;
    CfgEvent2.Flags := TCEVENTFLAG_LOG OR TCEVENTFLAG_SRCID;
    CfgEvent2.StreamType := TCEVENTSTREAM_SIMPLE;
    CfgEvent2.ProgId := 'TcEventFormatter.TcXmlFormatter';
    CfgEvent2.Id := 2; (* Meldung 2*)
    CfgEvent2.SourceId := 17001; (* 17001: Achsregelung *)
    CfgEvent2.DataFormatStrAddress := ADR(format);
    CfgEvent2.Class := TCEVENTCLASS_ALARM;

    event2(
    NETID:= '',
    PORT:= 110,
    Event:= bSetEvent2,
    EventQuit:= bQuitEvent2,
    EventConfigData:= CfgEvent2,
    EventDataAddress := ADR(value),
    EventDataLength := SIZEOF(value),
    TMOUT:= t#10s);
  7. Trigger the event

You can transfer multiple variables by wrapping them inside a structure. Then the format string must define the order of the variables inside the struct.

When a string is transferred with the eventdata, this string must be the last element in the structure. Only one string at a time may be transferred.

(*data types*)
TYPE ST_EventData1 :
STRUCT
    axis   : UDINT;
    pos    : LREAL;
    text   : STRING;
END_STRUCT
END_TYPE

 

(*variable-declaration*)
...
format     : STRING := '%d%f%s'
Eventdata1 : ST_EventData1;
... 
(*PLC ode*)
...
EventDataAddress    := ADR(Eventdata1),
EventDataLength     :=SIZEOF(Eventdata1),
...

 

Requirements

Language / IDE

Source code

TwinCAT PLC (Structured Text)

Sample03.zip