mgabryel - 2024-08-02

Hello,
I am trying to program CAN Bus comunication on WAGO PLC (more precisely on WAGO Touch Monitor model TP600).
I am using for this purpose library "WagoAppCanLayer2" from Wago company. My IDE for programming this device is CODESYS V3.5 SP19 Patch 2 + (64-bit). My program is written in Structured text using function blocks from previously mentioned library. Here is code of this program:
1) Variables declarations:

PROGRAM PLC_PRG
VAR
    oOpenInterface      : WagoAppCanLayer2.FbCanL2Open :=(
        udiBaudrate     := 125000 );
    xInterfaceIsOpen    : BOOL;
    sInterfaceInfo      : STRING;
    oReceive            : WagoAppCanLayer2.FbCanRx29BitFrame :=(
        xBufferMode     := FALSE, 
        wCanId          := 16#181 );
    xRecv               : BOOL;
    sReceiveInfo        : STRING;
    oSend               : WagoAppCanLayer2.FbCanTx29BitFrame :=(
        dwCanId         := 16#100, //was 16#201
        xRtrFrame       := FALSE );
    xSend               : BOOL;
    sSendInfo           : STRING;
    oCanDiag            : WagoAppCanLayer2.FbCanErrorInfo;
    xRst                : BOOL;
    aSendData           : ARRAY [1..8] OF BYTE;
    bSendLen            : BYTE;
    TON_0               : TON;
    TON_1               : TON;
END_VAR

2) Program body:

oOpenInterface(
    xEnable         := NOT xInterfaceIsOpen,
    I_Port          := IoConfig_Globals.WAGO_CAN_LAYER2_DEVICE );
sInterfaceInfo := oOpenInterface.oStatus.GetDescription();
xInterfaceIsOpen    S= oOpenInterface.xValid AND NOT oOpenInterface.xError;

oReceive(
    xEnable     := xInterfaceIsOpen, 
    I_Port      := IoConfig_Globals.WAGO_CAN_LAYER2_DEVICE, 
    xRxTrigger  := xRecv );
sReceiveInfo := oReceive.oStatus.GetDescription();

IF NOT xRecv THEN
    IF oReceive.bRxNBytes > 0 THEN
        oReceive.aRxBuffer[1];
        oReceive.aRxBuffer[2];
        oReceive.aRxBuffer[3];
        oReceive.aRxBuffer[4];
        oReceive.aRxBuffer[5];
        oReceive.aRxBuffer[6];
        oReceive.aRxBuffer[7];
        oReceive.aRxBuffer[8];
    END_IF
    xRecv := TRUE;
END_IF

aSendData[1] := 224;
aSendData[2] := 13;
aSendData[3] := 14;
aSendData[4] := 15;
aSendData[5] := 222;
aSendData[6] := 13;
aSendData[7] := 14;
aSendData[8] := 15;

bSendLen := 8;

TON_0(IN:= NOT TON_1.Q, PT:= T#2S , Q=>xSend, ET=> );
TON_1(IN:= TON_0.Q, PT:= T#2S , Q=>, ET=> );

oSend(
    xEnable     := xInterfaceIsOpen, 
    I_Port      := IoConfig_Globals.WAGO_CAN_LAYER2_DEVICE, 
    aTxBuffer   := aSendData, 
    bTxNBytes   := bSendLen, 
    xTxTrigger  := xSend );
sSendInfo := oSend.oStatus.GetDescription();

oCanDiag(
    xEnable                 := TRUE, 
    I_Port                  := IoConfig_Globals.WAGO_CAN_LAYER2_DEVICE, 
    xTriggerResetCounter    := xRst, 
    xValid=> , 
    xError=> , 
    oStatus=> , 
    wBusState=> , 
    wBusDiag=> , 
    uiRxOverflowsL2=> , 
    uiTxOverflowsL2=> , 
    uiRxOverflows=> , 
    uiMsgTimeouts=> , 
    uiBusOffs=> , 
    uiBusWarnings=> );

Program first opens comunication on CAN 2 device and then periodically try send one CAN data frame. After starting program CAN 2 interface is properly open. The xSend variable is toggling with period 2s. When program sends data an "Tx overflow" error appears. When I am watching CAN_H line on DSub 9 socket i am not able to see proper CAN frames - see screenshot attached to this message.
Could somebody help me determine what is wrong with this program.

Best regards

 

Related

Talk.ru: 1
Talk.ru: 2
Talk.ru: 3
Talk.ru: 5
Talk.ru: 7
Talk.ru: 8