Page 1 of 1

Intermittent sending of CAN frames

Posted: Mon 11. May 2020, 14:14
by NinaAlexandra
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

Re: Intermittent sending of CAN frames

Posted: Mon 11. May 2020, 14:38
by M.Heidemann
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

Re: Intermittent sending of CAN frames

Posted: Wed 13. May 2020, 16:26
by NinaAlexandra
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?

Re: Intermittent sending of CAN frames

Posted: Wed 13. May 2020, 17:29
by M.Maidhof
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

Re: Intermittent sending of CAN frames

Posted: Thu 14. May 2020, 10:26
by NinaAlexandra
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.

Re: Intermittent sending of CAN frames

Posted: Thu 14. May 2020, 11:00
by M.Heidemann
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