Author Topic: Problems with CAN 2.0 comunication on Wago PLC (Codesys 3.5)  (Read 3005 times)

0 Members and 1 Guest are viewing this topic.

Offline FlyingDutchTopic starter

  • Regular Contributor
  • *
  • Posts: 147
  • Country: pl
Problems with CAN 2.0 comunication on Wago PLC (Codesys 3.5)
« on: August 02, 2024, 09:44:15 am »
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
Code: [Select]
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:
Code: [Select]
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

Best regards



 

Offline Zucca

  • Supporter
  • ****
  • Posts: 4603
  • Country: it
  • EE meid in Itali
Re: Problems with CAN 2.0 comunication on Wago PLC (Codesys 3.5)
« Reply #1 on: August 17, 2024, 02:59:24 am »
Probably you need to talk with WAGO support for this one.
Are the CANbus termination resistance connected?
Can't know what you don't love. St. Augustine
Can't love what you don't know. Zucca
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf