Worker.UpdateBroadcast

The free CAN Software API (Application Programming Interface) for Windows®
Post Reply
hedgehog in a fog
Posts: 1
Joined: Fri 17. Nov 2023, 07:03

Worker.UpdateBroadcast

Post by hedgehog in a fog » Fri 17. Nov 2023, 07:31

Hello, everyone! Please help me with this question. I send and receive CAN FD messages with a period of 10 ms with the Worker. I used Worker.AddBroadcast and Worker.Start() to send the messages. Before each message sending I update the data in the message. Since it is difficult to know at what point in time to do Worker.UpdateBroadcast, I do it in a separate thread in an infinite delayed loop. In this variant I get the following picture: if Worker.UpdateBroadcast happens at the moment of sending a message, then in fact I have a message with all zeros instead of data on the CAN bus. Even if before Worker.UpdateBroadcast insert Worker.PauseBroadcast and after it insert Worker.ResumeBroadcast in the CAN bus I still get a message with all zeros instead of data. Could you please tell me if there is any way to synchronize Worker.UpdateBroadcast and the moment when the message is sent so that these zeros do not appear, besides doing it by timer without Broadcast?

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

Re: Worker.UpdateBroadcast

Post by K.Wagner » Fri 17. Nov 2023, 09:12

[Topic moved to Development Packages/PCAN-Basic]

Hello,

First of all, please let us know wich version are you using. NOte that the latest version is 4.8.0 (see history of change). If you have an older version, please update and try again. Note tha you have to update both, the native dll (using PEAK-Drivers Setup), and also the PCAN-Basic.NET NuGet package.

If using the last version or you see the same behavior after updating, then:
hedgehog in a fog wrote:
Fri 17. Nov 2023, 07:31
if Worker.UpdateBroadcast happens at the moment of sending a message, then in fact I have a message with all zeros instead of data on the CAN bus.
Could you provide us wiht a minimalistic version of your project, so that we can reproduce the issue here?
The library itself is thread safe, but if this behavior you describe is true, then maybe this could be a thread snychronization problen within the .NET assembly.
hedgehog in a fog wrote:
Fri 17. Nov 2023, 07:31
Could you please tell me if there is any way to synchronize Worker.UpdateBroadcast and the moment when the message is sent so that these zeros do not appear, besides doing it by timer without Broadcast?
The way how broadcast works is actually easy. You get a reference to the Broadcast object when you create one, then, using that object, any change you do will be directly applied. For isntance:

Code: Select all

Worker myWorker = new Worker();
PcanMessage message = new PcanMessage(0x100, MessageType.Standard, 3, new byte[] { 1, 2, 3 }, false);
Broadcast broadcast = new Broadcast(message, 10);
myWorker.AddBroadcast(ref broadcast);
myWorker.Start();

// Change the data, for instance, the next time the broadcast is triggered, the new data is sent
broadcast.Message.Data[2] = 7; // at this point the broadcast starts sending the "7" in byte[2] instead of "3"

Best regards,
Keneth

Post Reply