caprez95 - 2024-06-04

Hello everyone.

I've been struggling with the problem for a long time that I can't reset (restart) a trend (visual element).
With the example I have now managed to control the trace recording via the CmpTraceMgr library.
But how do I get this trace recording into a visual element?

The code looks like this:

// Configure trace
IF xInit THEN
    // Create a trace packet
    PacketConfig.pszName := ADR('IECTraceConfiguration.Trace1'); // Name of trace
    PacketConfig.pszApplicationName := ADR('IECTraceConfiguration'); // Name of the application
    PacketConfig.pszIecTaskName := ADR('Task'); // Name of the task
    PacketConfig.pszComment := ADR('Demo packet');
    PacketConfig.ulEveryNCycles := 1;
    PacketConfig.ulBufferEntries := 1000;
    PacketConfig.ulFlags := TRACE_PACKET_FLAGS.TRACE_PACKET_FLAGS_TIMESTAMP_MS AND TRACE_PACKET_FLAGS.TRACE_PACKET_FLAGS_AUTOSTART;

    IF (NOT fbTraceManager.CreatePacket(PacketConfig := PacketConfig, hPacket=>hPacket1)) THEN
        xError := TRUE;
    END_IF

    // Create a trace record
    RecordConfig.pszVariable := ADR('iSignal'); // This is the name of variable to record
    RecordConfig.tcClass := INT_TO_UDINT(TypeClass.TYPE_INT); // Type of the recording variable
    RecordConfig.ulSize := SIZEOF(iSignal); // Size of the recording variable
    pApp := AppFindApplicationByName('IECTraceConfiguration', 0); 
    AppGetAreaOffsetByAddress(pApp, ADR(iSignal), ADR(RecordConfig.tvaAddress.taAddress.Area.usArea), ADR(RecordConfig.tvaAddress.taAddress.Area.ulOffset)); // Get and set area offsets 
    RecordConfig.tvaAddress.ulAddressFlags := TRACE_VAR_ADDRESS_FLAGS_IEC OR TRACE_VAR_ADDRESS_FLAGS_AREA_OFFSET;
    RecordConfig.ulGraphColor := 16#FF00FF00; // green
    RecordConfig.ulGraphType := 1; // Line with points

    IF (NOT fbTraceManager.AddRecord(RecordConfig := RecordConfig, hPacket := hPacket1, hRecord => hRecord1)) THEN
        xError := TRUE;
    END_IF

    xInit := FALSE;

END_IF

// Starts the recording
IF xStart THEN
    IF (NOT fbTraceManager.StartPacket(hPacket := hPacket1)) THEN
        xError := TRUE;
    END_IF
    xStart := FALSE;
END_IF

// Stop the recording
IF xStop THEN
    IF (NOT fbTraceManager.StopPacket(hPacket := hPacket1)) THEN
        xError := TRUE;
    END_IF
    xStop := FALSE;
END_IF

// Reset the recording
IF xReset THEN
    IF (NOT fbTraceManager.ResetPacket(hPacket := hPacket1)) THEN
        xError := TRUE;
    END_IF
    xReset := FALSE;
END_IF