How to read data from CAN device using Codesys?

rariusz
2021-02-25
2021-02-26
  • rariusz

    rariusz - 2021-02-25

    Hello All,

    I have a device that cyclically sends CAN frames to the network. I want to receive this data using Codesys and a PLC controller and at this point there is a problem. As I do not have physical access (yet) to the device, I send data in the CAN network using the USB-CAN adapter. This is example frame 0x01,0x04, 0x01,0x02,0x03,0x04 (CAN ID, length of data and data). I want to read this data in Codesys. I currently have the following error: CANOPEN_WRONG_PARAMETER. In the case of the Beckhoff controller, things were simple because the CANopen Master module read the data itself. How read CAN frame that I generate using USB-CAN adapter in Codesys?

     

    Last edit: rariusz 2021-02-25
  • sgronchi

    sgronchi - 2021-02-26

    Your code tries to SDO read an object from the local node (DEVICE = 0), but you have not created a CANopen local device.

    In any case, you seem not to have clear the distinction between CAN (the bus) and CANopen (one of the various application protocol built on top of CAN).

    In particular, your message is illegal to use in a CANopen network: the only message that can have ID 1 is the Global Failsafe Command (GFC) that has DLC 0 (thus no payload), that has a very special meaning. It is however totally fine to use that message in a CAN network without CANopen nodes.

    If you want to interface with CAN at low level, check the related library: https://help.codesys.com/webapp/hGcF55fadXXw7LxTlfIUoErJcVQ%2Ffld-CAN-Low-Level;product=CAA_CanL2_Extern;version=3.5.16.0

    If you want to set up a CANopen network, try to understand CANopen foundations and its allocation of CAN addresses, and only then try to simulate a device.

     

Log in to post a comment.