needed wait time for Status return ?

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
elpimous12
Posts: 59
Joined: Tue 3. Aug 2021, 23:34

needed wait time for Status return ?

Post by elpimous12 » Wed 8. May 2024, 15:27

hello, in my function :

Code: Select all

do {
            Status = CAN_WriteFD(port, &moteus_tx_msg);
        }
    while (Status != PCAN_ERROR_OK);
    return true;
do I need a usleep(???) like this :

Code: Select all

do {
            Status = CAN_WriteFD(port, &moteus_tx_msg);
            usleep(50);
        }
    while (Status != PCAN_ERROR_OK);
    return true;
Thanks the team.

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

Re: needed wait time for Status return ?

Post by M.Heidemann » Wed 8. May 2024, 16:52

Hello,

Using a sleep will free up some compute for the rest of the system, yes.

But we would like to know:

What do you want to do? We can only guess as to what the context of your code here is...

Depending on the intended purpose there could be better solutions.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

elpimous12
Posts: 59
Joined: Tue 3. Aug 2021, 23:34

Re: needed wait time for Status return ?

Post by elpimous12 » Wed 8. May 2024, 20:34

Hello Marvin,

I need to call 12 ids, 3 per PEAK M2 port, on a 48 bytes frame, as fast as possible.

on my ubuntu 20.04 RT, i send 12 frames (48 bytes), then read 12 others .

I'd like to reach anything like 500hz

My computer is up xtreme i7.

I'd like to use a pause, but 10us could be enouth to receive/send from/to Peak ?

Not sure infos would be enouth.
Thanks for your time, Marvin.

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

Re: needed wait time for Status return ?

Post by M.Heidemann » Fri 10. May 2024, 12:40

Hello,

i assume communication would rely on request-response?

If that is the case i don't see the need to use a pause necessarily.

Your scope io messages is limited to those 12 frames of 48byte,
push your requests and wait for the response.

I'd only advise against doing that in a while-loop checking against
NOT PCAN_ERROR_OK. Here's why: This will push messages to the queue
as fast as possible, even if they are not going out (bus-errors), this will
easily result in the queue being overrun if there is an issue. You would have to
use a check against TPCANStatus "PCAN_ERROR_QXMTFULL" and wait for the frames
to be pushed to bus and out of the queue. Also, in a while loop this will happen as fast
as your cpu is able to push it, this will most likely complete lock up your system if
there are issues on your bus.

I'd argue this a pretty brute implementation.

My suggestion:
I'd iterate through each ID and check against "PCAN_ERROR_OK", the proceed
to the next ID if i get that response and repeat sending the current ID if not.
This is a bit more predictable and maybe easier to debug if there is something going wrong.
Also, this will not completely suck all ressources of your system if you do run into an error state.

Also your configuration leaves some questions:

A) Is this CAN-FD or J1939? 48 byte isn't a regular CAN 2.0 frame, so please elaborate.

B) 500hz isn't really a good unit to measure this, can you elaborate how you came to that
requirement? Do you mean 500 msgs per second? Is this one bus or are these seperate buses?
Which bitrate are you using currently?

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

Post Reply