Can I use virtual can (vcan) in CoDeSys?

alt
2019-03-12
2023-06-01
  • alt - 2019-03-12

    Hello!
    There are no problems with the physical interface can0, everything works.
    We want to use the virtual can (vcan) interface in the Beaglebone Black controller from the CoDeSys environment, but it does not work.

    I activate the virtual can in the controller with the following commands:
     $ modprobe vcan
     $ sudo ip link add dev can2 type vcan
     $ sudo ip link set up can2

    Through ifconfig I see that this interface appeared in the system.
    Utilities can-utils work with it without any problems.

    BUT, if you add this interface number (2) to the can bus in the CoDeSys project, then after loading the project into the controller, an error appears in the log that the device could not be configured.

    What could be the reason?

    I tried to remove the bitrate setting from the file rts_set_baud.sh because vcan does not support this setting, but it did not help.

     
  • alt - 2019-03-16

    No one can help? I also wrote help on the store, also silence. Maybe the manufacturer is not interested in selling?

     
  • eschwellinger

    eschwellinger - 2019-03-16

    not sure if vcan is supported by CODESYS.. don't think so.
    Let me check.
    BR
    Edwin

     
  • eschwellinger

    eschwellinger - 2019-03-20

    Hi,
    what do you want to archive with this virtual CAN / vcan?
    Maybe you need to explain a little more in detail.

    BR
    Edwin

     
  • eschwellinger

    eschwellinger - 2019-03-20

    Hi,
    you could give the following solution a try (wihout guarantee that this will work)

    [CmpSocketCanDrv]
    ScriptPath=/opt/codesys/scripts/
    ScriptName=rts_set_baud.sh
    InterfaceName=vcan

    not sure, if it will work (did not try) but sure is either vcan will work or the real interface not both at the same time
    I guess.

    BR
    Edwin

     
  • alt - 2019-03-21

    Thanks, Edwin!
    Let's try today or tomorrow.
    The reason for using vcan is an implementation of automatic switching between two physical can interfaces, unfortunately the driver built into CoDeSys cannot do this. Correct if I'm wrong.

     
  • alt - 2019-03-22

    Hi,
    Using the "InterfaceName = vcan" parameter does not help,
    but this setting is somehow applied runtime because after that the physical can interface also stops working.

    Record in CoDeSys log and the output of the command "ifconfig vcan2".

    Using the InterfaceName = vcan parameter does not help, but this setting is somehow applied runtime because after that the physical can interface also stops working. An entry in the CoDeSys log.
    The output of the command "ifconfig vcan2" in the attachment.

    I noticed that even in normal mode, the setting "Baudrate = Use current setting" does not work (and when setting a specific speed it works)

    IMG: 66.jpg

    IMG: 44.jpg

    IMG: 55.jpg

    IMG: 88.jpg

    IMG: 77

    IMG: 77

     
  • alt - 2019-03-28

    Hello!
    Until now, there is no solution.
    And the ticket on store.codesys.com is closed with redirection to this thread in the forum: (

    Are there any other ideas that you can try other than "InterfaceName = vcan"?
    The test bench is on and available at any time.

    IMG: ticket_close.jpg

     
  • eschwellinger

    eschwellinger - 2019-03-29

    come on,
    this is not good stile to post here screenshots from store requests!
    Need some time....
    BR
    Edwin

     
  • eschwellinger

    eschwellinger - 2019-03-29

    Hi,
    at the moment it is not possible to mix it up and use vcan and real can at the same time in CODESYS.
    If you need this this need to be done by a improvement tracking entry ….!

    BR
    Edwin

     
  • alt - 2019-04-04

    Hi!
    NOT! I don't need to use real and virtual can at the SAME TIME! I need ONLY a virtual can! And the string "InterfaceName = vcan" does not work! Help me please! Already so much time there is no solution

     
  • eschwellinger

    eschwellinger - 2019-04-04

    I see no workaround...
    it is possible to use CAN ( as interface name) but it stops after 2 interfaces... (hard coded)
    BR
    Edwin

     
  • alt - 2019-04-11

    Hello, Edwin!

    Excuse me, really, the "InterfaceName = vcan" setting works!
    The problem was that the number of CAN interfaces used by CoDeSys should be no more than 2.
    Now there is another problem, how to use the vcan interface?
    The Candump utility program does not see the packets that the CoDeSys sends to the CAN bus via the vcan interface.

    For the physical CAN interface, this is not a problem. You can view the packets on the bus using another device, and for virtual CAN I did not find a suitable solution.

    Forwarding packets with socat or cangw utility programs
    work ONLY to receive packets in the direction of CoDeSys

    socat INTERFACE: can0, pf = 29, type = 3, prototype = 1 INTERFACE: vcan0, pf = 29, type = 3, prototype = 1

    or via cangw

    cangw -A -s can0 -d vcan0
    cangw -A -s vcan0 -d can0

    Thus, packet transmission in the direction "CoDeSys -> vcan0-> can0-> physical CAN device" does not work
    But it works in the opposite direction.

    How to solve this problem?

    Most likely the reason is that when you open a socket in the Canopen CoDeSys driver, loopback mode is disabled:

    int loopback = 0;
           if (setsockopt (s_fd_write [byNet], SOL_CAN_RAW, CAN_RAW_LOOPBACK, & loopback, sizeof (loopback))) {
                   DEBUGP ("setsockopt (CAN_RAW_LOOPBACK):% s", strerror (errno));
           }

    If this is true, then how was the virtual can interface supposed to be used? After all, virtual can works only through loopback (correct, if I'm wrong).

     
  • alt - 2019-04-23

    It took almost 2 weeks, but no answer!
    At the same time, the ticket on store.codesys.com is closed!
    Help me please!!!

     
  • eschwellinger

    eschwellinger - 2019-04-23

    Hi,
    give this a try:

    [CmpSocketCanDrv]
    Loopback=1

    BR
    Edwin

     
  • alt - 2019-04-29

    Thank you very much, Edwin!
    Works great!

    (advice for the future: try to spend more time documenting your capabilities)

     
  • damenx - 2023-06-01

    I know this is old but I cant find other references of vcan implementation.
    I followed this thread and I can see in candump that Codesys is transmitting to the virtual bus, But it does not recive any on the messages on the bus. I can see messages from my other device in candump but codesys cannot see them. Any advice would be appreciated.

     

Log in to post a comment.