FB_AdsLogStringMessageFifoQueue Function Block

This function block is responsible for making sure that the ADSLOGSTR-messages to the ADS-router are transmitted cyclically and not in a burst. The reason this is necessary is because that if too many messages are sent at the same time some get lost and are never printed to the error list output


Variables

NameTypeDefaultDescription
ArrayBufferARRAY[0..((GVL_Param_TcUnit.AdsLogMessageFifoRingBufferSize * (SIZEOF(ST_ADSLogStringMessage) + MEM_RING_BUFFER_INTERNAL_USE_PER_DATA_RECORD)) - 1)] OF BYTE
MemRingBufferFB_MemRingBuffer
TimerBetweenMessagesTON(IN := TRUE, PT := TIME_BETWEEN_MESSAGES)
MEM_RING_BUFFER_INTERNAL_USE_PER_DATA_RECORDUSINT4
TIME_BETWEEN_MESSAGESTIMET#10MS
MessageToBeSentST_AdsLogStringMessage
ErrorGetBOOL
ReturnValueDINT

Methods

GetAndRemoveLogFromQueue PRIVATE

Reads and removes the oldest message

Outputs

NameTypeDescription
AdsLogStringMessageST_ADSLogStringMessage
ErrorBOOLBuffer empty
Implementation
MemRingBuffer.A_RemoveHead(pRead := ADR(AdsLogStringMessage),
                           cbRead := SIZEOF(ST_ADSLogStringMessage),
                           pBuffer := ADR(ArrayBuffer),
                           cbBuffer := SIZEOF(ArrayBuffer));
Error := NOT MemRingBuffer.bOk;
GetLogCount PRIVATE
Implementation
GetLogCount := MemRingBuffer.nCount;
WriteLog INTERNAL

Writes a new data set into the ring buffer

Parameters

NameTypeDescription
MsgCtrlMaskDWORD
MsgFmtStrT_MaxString
StrArgT_MaxString

Outputs

NameTypeDescription
ErrorBOOLBuffer overflow
Implementation
// Only log message types of ERROR if log extended results is not enabled
IF MsgCtrlMask = ADSLOG_MSGTYPE_ERROR OR GVL_Param_TcUnit.LogExtendedResults THEN
    AdsLogStringMessage.MsgCtrlMask := MsgCtrlMask;
    AdsLogStringMessage.MsgFmtStr := MsgFmtStr;
    AdsLogStringMessage.StrArg := StrArg;

    MemRingBuffer.A_AddTail(pWrite := ADR(AdsLogStringMessage),
                            cbWrite := SIZEOF(ST_AdsLogStringMessage),
                            pBuffer := ADR(ArrayBuffer),
                            cbBuffer := SIZEOF(ArrayBuffer));

    Error := NOT MemRingBuffer.bOk;
END_IF

Used by

Declaration source
(* This function block is responsible for making sure that the ADSLOGSTR-messages to the ADS-router are transmitted
   cyclically and not in a burst. The reason this is necessary is because that if too many messages are sent at the
   same time some get lost and are never printed to the error list output
*)
FUNCTION_BLOCK FB_AdsLogStringMessageFifoQueue
VAR
    ArrayBuffer : ARRAY[0..((GVL_Param_TcUnit.AdsLogMessageFifoRingBufferSize * (SIZEOF(ST_ADSLogStringMessage) + MEM_RING_BUFFER_INTERNAL_USE_PER_DATA_RECORD)) - 1)] OF BYTE;
    MemRingBuffer : FB_MemRingBuffer;
    TimerBetweenMessages : TON := (IN := TRUE, PT := TIME_BETWEEN_MESSAGES);
END_VAR
VAR CONSTANT
    MEM_RING_BUFFER_INTERNAL_USE_PER_DATA_RECORD : USINT := 4;
    TIME_BETWEEN_MESSAGES : TIME := T#10MS;
END_VAR
VAR_TEMP
    MessageToBeSent : ST_AdsLogStringMessage;
    ErrorGet : BOOL;
    ReturnValue : DINT;
END_VAR