Python Function to Continuously Transmit

The free CAN Software API (Application Programming Interface) for Windows®
Post Reply
blipton
Posts: 17
Joined: Sat 11. Jul 2020, 02:22

Python Function to Continuously Transmit

Post by blipton » Thu 8. Sep 2022, 04:04

I'm able to transmit on-demand, using a 20ms timer, but it's a lot overhead... I'm looking for the driver function that would allow the message to be transmitted automatically at this rate.

The cpu overhead would be minimal.. just updating the message data as needed.

K.Wagner
Software Development
Software Development
Posts: 1082
Joined: Wed 22. Sep 2010, 13:36

Re: Python Function to Continuously Transmit

Post by K.Wagner » Thu 8. Sep 2022, 07:58

Hello,

unfortunately, broadcast (automatic transmission) is supported neither by the device driver nor by the API itself. Using a timer or a thread is the normal way for doing this, so your approach is perfectly OK.

We will support this in a near future, but only for .NET applications.
Best regards,
Keneth

blipton
Posts: 17
Joined: Sat 11. Jul 2020, 02:22

Re: Python Function to Continuously Transmit

Post by blipton » Fri 9. Sep 2022, 04:01

I've never tried running .net on linux.. but hoping I can just get my existing Python app to be a bit more responsive.

Is there a way to setup the driver/API to issue an interrupt when the message has been successfully transmitted?

I'm thinking of using a thread to automatically transmit what's in a queue, whenever the previous message has been ACK'd. I think this should improve performance considerably.

K.Wagner
Software Development
Software Development
Posts: 1082
Joined: Wed 22. Sep 2010, 13:36

Re: Python Function to Continuously Transmit

Post by K.Wagner » Fri 9. Sep 2022, 07:57

Hello,
blipton wrote:
Fri 9. Sep 2022, 04:01
Is there a way to setup the driver/API to issue an interrupt when the message has been successfully transmitted?
yes, kind of. You can activate the parameter PCAN_ALLOW_ECHO_FRAMES. This causes your applicaiton to get an echo of any sent frame, this is, when you get an echo means the message was physically sent. The echo is placed in the receive queue of your application and is read like any other message, over the CAN_Read/CAN_ReadFD function.
blipton wrote:
Fri 9. Sep 2022, 04:01
I'm thinking of using a thread to automatically transmit what's in a queue, whenever the previous message has been ACK'd. I think this should improve performance considerably.
Yes, you can use the echo frames as triggger to send the next message in your queue. Note that the API has only one queue per channel, so if you are already reading and processing messages somewhere in your code, you will need to synchronize that part with the new thread in charge of sending mesages,
Best regards,
Keneth

blipton
Posts: 17
Joined: Sat 11. Jul 2020, 02:22

Re: Python Function to Continuously Transmit

Post by blipton » Sun 25. Sep 2022, 21:49

I've updated the driver (9/1/2022) and downloaded the latest pcan-basic zip (7/6/2022), and I it seems to mostly work.. i think the only issue I'm seeing has to do with filters.

Is it possible to filter out all messages on the bus, EXCEPT for my ECHO'd message that was ACK'd by the receiver?

I'm using the following to generate the 11-bit accept-code and accept-msg masks
https://gist.github.com/Lauszus/bd322b17b77c96f240fc

to filters out all node-ids and messages , but I'm seeing INCONSISTENT results in receiving MY message. If I open to receive all nodes/msgs then I always get my message.

Is there any special consideration for the accept filters when using the echo?

K.Wagner
Software Development
Software Development
Posts: 1082
Joined: Wed 22. Sep 2010, 13:36

Re: Python Function to Continuously Transmit

Post by K.Wagner » Mon 26. Sep 2022, 11:03

Hello,
blipton wrote:
Sun 25. Sep 2022, 21:49
Is it possible to filter out all messages on the bus, EXCEPT for my ECHO'd message that was ACK'd by the receiver?
this is only possible to a limited extent. For this, you need to configure the filter to only allow the IDs used for outgoing messages. Note that if you are receiving messages with the same IDs from another node, those messages are also received, so you still have to check the type of the received messages. The problem is, that echo messages are phisical received messages, this is, they are processed by the driver in the same manner as other recieved messages and passed throw the same filter as well.
blipton wrote:
Sun 25. Sep 2022, 21:49
to filters out all node-ids and messages , but I'm seeing INCONSISTENT results in receiving MY message. If I open to receive all nodes/msgs then I always get my message.

Is there any special consideration for the accept filters when using the echo?
As explained above, check that your filter is not discarding any of the IDs used for sending.
Best regards,
Keneth

Post Reply