Intermittent sending of CAN frames

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
NinaAlexandra
Posts: 3
Joined: Mon 4. May 2020, 11:34

Intermittent sending of CAN frames

Post by NinaAlexandra » Mon 11. May 2020, 14:14

Hi, I'm trying to write a software that sends periodic CAN messages in C++.

I've opened the CAN-Socket in this way:

Code: Select all

if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
            perror("CanSend: Error while opening socket");
            exit(-1);
        }

        strcpy(ifr.ifr_name, ifname.c_str());
        ioctl(s, SIOCGIFINDEX, &ifr);

        addr.can_family = AF_CAN;
        addr.can_ifindex = ifr.ifr_ifindex;

        if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
            perror("CanSend: Error in socket bind");
            exit(-2);
        }
's

Writing in a separate thread getting the packages from a shared queue:

Code: Select all

bytes_written = write(t->s, frame.get(), sizeof(struct can_frame));
The weird part is, the software works, sending out CAN-Frames, and then the write function blocks, after a while it stops blocking, the backlog in the queue is sent quite quickly, and after a while the write function blocks again.
The first time that block occurs it's usually about 30s, and after a while its a 2-3s block, every 15-20s.

I'm using the PCAN-FD USB interface.
I'm running this on a CentOS (Kernel 4.18.0-147.8.1.el8_1.x86_64) with gcc v8.3.1

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: Intermittent sending of CAN frames

Post by M.Heidemann » Mon 11. May 2020, 14:38

Hello,

Thank you for your request.

Are you using the Mainline driver inlcuded in the kernel or are you using the PCAN-Linux driver from the driver package?

Can you check, if "cangen" from the can-utils package does act the same way?

I would also recommend to take a look at the source code for cangen (can be found online) for reference.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

NinaAlexandra
Posts: 3
Joined: Mon 4. May 2020, 11:34

Re: Intermittent sending of CAN frames

Post by NinaAlexandra » Wed 13. May 2020, 16:26

I'm using the mainline driver.
Both with cangen and my program, the led blinks red. According to the manual this tells me there is some kind of error.
Any hints of how debug this, and find out what kind of error I'm dealing with?

M.Maidhof
Support
Support
Posts: 1753
Joined: Wed 22. Sep 2010, 14:00

Re: Intermittent sending of CAN frames

Post by M.Maidhof » Wed 13. May 2020, 17:29

Hi,

sure you have another active CAN node with the same baudrate and a terminated CAN cable connected to the PCAN-USB FD?

regards

Michael

NinaAlexandra
Posts: 3
Joined: Mon 4. May 2020, 11:34

Re: Intermittent sending of CAN frames

Post by NinaAlexandra » Thu 14. May 2020, 10:26

Yes, I soldered the terminator adapter (short cable with a 120Ω resistor between the data lines) myself, and tried it with and without.
The baudrate (500k) seems good, since I can dump the traffic on the bus once it is active (blinking green in that case).
No, the CAN node on the other end is not fully active, because that's just what I'm trying to do, activate the device on the other end so it boots up, sending the correct signals telling it that all is well and the key has been turned so it's time to wake up and start working.

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: Intermittent sending of CAN frames

Post by M.Heidemann » Thu 14. May 2020, 11:00

Hello,

What does "not fully active" mean in this context?

Will the CAN-node on the other end still be able to acknowledge incoming frames from other nodes in that state?

You could test the following:

Does the same issue arise, if the Node on the other end has been woken up already and is fully active at the time of frame transmission from your application/cangen?

Furthermore we do recommend to have termination (120Ohms) at both ends of your bus, even though using just one resistor might work in the current setup it could introduce issues later on in case your network is expanded or changed.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

Post Reply