Multiple Workers
Multiple Workers
One worker at a time works properly, but I plan to launch another one with the same interface. On the worker Start method, I tried to set "ignoreBitrateCheck" to TRUE, but I still get the error:
Peak.Can.Basic.PcanBasicException: 'Api.SetValue(BitrateAdapting)' is failed with following error: action can not be taken in the current configuration.
Is it at all possible to launch multiple Workers?
Peak.Can.Basic.PcanBasicException: 'Api.SetValue(BitrateAdapting)' is failed with following error: action can not be taken in the current configuration.
Is it at all possible to launch multiple Workers?
-
- Support
- Posts: 14
- Joined: Tue 31. Aug 2010, 12:42
Re: Multiple Workers
Hello,
yes, you can use multiple workers.
However, you could use the 'ParameterValue' class instead of using API.SetParameter.
Also, BitrateAdapting can only be set on unitialized channels.
BR
Marvin
yes, you can use multiple workers.
However, you could use the 'ParameterValue' class instead of using API.SetParameter.
Also, BitrateAdapting can only be set on unitialized channels.
BR
Marvin
Re: Multiple Workers
Hi,
I don't even use API.SetParameter, only the .net method Peak.Can.Basic.Worker.Start(), which calls (I guess) internally the API.SetParameter method.
My goal is basically to get 2 read queues; one with 1 specific message ID, and another one with all messages with any ID. This I tried with one worker configuring 2 filters, where:
- Worker.AddFilter(0, filter) --> queueIndex is 0
- Worker.AddFilter(1, filter) --> queueIndex is 1
In the MessageAvailable callback, I read both queues 0 and 1 using the Worker.Dequeue(), but both return exactly the same messages, as the filter for queueIndes=1 would have no effect.
The FilterCriterion for QueueIndex=1 is constructed as FilteringCriterion(0xFF, FilterBehavior.Include), intending to include all messages, inclusive error frames.
Whether I do it with the same worker with 2 read queues, or with 2 Workers, it doesn't matter. But one should work
I don't even use API.SetParameter, only the .net method Peak.Can.Basic.Worker.Start(), which calls (I guess) internally the API.SetParameter method.
My goal is basically to get 2 read queues; one with 1 specific message ID, and another one with all messages with any ID. This I tried with one worker configuring 2 filters, where:
- Worker.AddFilter(0, filter) --> queueIndex is 0
- Worker.AddFilter(1, filter) --> queueIndex is 1
In the MessageAvailable callback, I read both queues 0 and 1 using the Worker.Dequeue(), but both return exactly the same messages, as the filter for queueIndes=1 would have no effect.
The FilterCriterion for QueueIndex=1 is constructed as FilteringCriterion(0xFF, FilterBehavior.Include), intending to include all messages, inclusive error frames.
Whether I do it with the same worker with 2 read queues, or with 2 Workers, it doesn't matter. But one should work

-
- Sales & Support
- Posts: 1083
- Joined: Fri 20. Sep 2019, 13:31
Re: Multiple Workers
Hello,
Once the channel is initialized you won't be able to hook another worker to it,
i think you would have more success handling the fiiltering yourself, maybe generate
a list of messages with your filtering applied.
What you are trying to do is not possible, as those filters work on a hardware level
and once set will be globally active.
BR
Marvin
Once the channel is initialized you won't be able to hook another worker to it,
i think you would have more success handling the fiiltering yourself, maybe generate
a list of messages with your filtering applied.
What you are trying to do is not possible, as those filters work on a hardware level
and once set will be globally active.
BR
Marvin
---
Marvin Heidemann
PEAK-Support Team
Marvin Heidemann
PEAK-Support Team
Re: Multiple Workers
Hi,
then I don't understand the functionality of QueueIndex.
At adding a filter, I can define the queue, and at Dequeue() I can do it too. So, what is the intended usage of QueueIndex?
then I don't understand the functionality of QueueIndex.
At adding a filter, I can define the queue, and at Dequeue() I can do it too. So, what is the intended usage of QueueIndex?
-
- Sales & Support
- Posts: 1083
- Joined: Fri 20. Sep 2019, 13:31
Re: Multiple Workers
Pardon me, slight mix up on my part...
You can handle multiple receive queues within one worker,
the queueindex is used to differentiate between those queues.
Also, the filters are per queue, i have to negate my previous statement (filters used to work different in the PCANBasic context, my mistake sorry)
Quoting the docs:
https://docs.peak-system.com/API/PCAN-B ... 23aa51.htm
Then you can use your filtering options on the subsequent queues:
https://docs.peak-system.com/API/PCAN-B ... 1c7e97.htm
QueueIndex is used as the receive event will fire for all queues, so this allows you to
differentiate which queue did receive the message.
So, i was partially right, you can't use mutliple works on the same channel, you can however have multiple queues with differing filters (That's where i was wrong)
Does that clear up things for you?
Please let me know.
BR
Marvin
You can handle multiple receive queues within one worker,
the queueindex is used to differentiate between those queues.
Also, the filters are per queue, i have to negate my previous statement (filters used to work different in the PCANBasic context, my mistake sorry)
Quoting the docs:
So, you configure your worker to have at least two queues using Worker.ReceiveQueuesCount:The Worker object does have multiple receive queues. Only one of those receive queues is active by default when the object is created, and its filter is configured to receive any message. The remaining receive queues keep their filters closed.
The reading process is executed in an additional thread, making use of the event notification mechanism to fetch CAN messages. Fetched messages can be dequeued for their further processing using the Dequeue method. If needed, messages stored in one or all receive queues may be discarded using the methods ClearReceiveQueue and ClearAllReceiveQueues respectively.
Each receive queue has its own message filter. This message filter can be configured using several filtering criteria, in form of FilteringCriterion data, by using the AddFilter method. The message filtering in a receive queue can also be temporarily disabled/enabled at any time by using the SetFilteringState method. A specific filtering criterion, or all of them, can be removed using the methods RemoveFilter and ClearFilters respectively.
https://docs.peak-system.com/API/PCAN-B ... 23aa51.htm
Then you can use your filtering options on the subsequent queues:
https://docs.peak-system.com/API/PCAN-B ... 1c7e97.htm
QueueIndex is used as the receive event will fire for all queues, so this allows you to
differentiate which queue did receive the message.
So, i was partially right, you can't use mutliple works on the same channel, you can however have multiple queues with differing filters (That's where i was wrong)
Does that clear up things for you?
Please let me know.
BR
Marvin
---
Marvin Heidemann
PEAK-Support Team
Marvin Heidemann
PEAK-Support Team
Re: Multiple Workers
Hi Marvin,
yes, it works great. Thank you!
Gyula
yes, it works great. Thank you!
Gyula
Re: Multiple Workers
Hi,
I still have the question, how it is possible to start 2 Workers parallel. Does your answer mean, that I can start only one Worker at a time, but for a second one I can't use the Worker class?
I still have the question, how it is possible to start 2 Workers parallel. Does your answer mean, that I can start only one Worker at a time, but for a second one I can't use the Worker class?
-
- Sales & Support
- Posts: 1083
- Joined: Fri 20. Sep 2019, 13:31
Re: Multiple Workers
Hello,
There are these constructors for a worker object :
Worker() Initializes a PCAN-Basic Worker object with its default values.
Worker(PcanChannel, Bitrate, Boolean) Initializes a PCAN-Basic Worker object.
Worker(PcanChannel, BitrateFD, Boolean) Initializes a PCAN-Basic Worker object.
All of them will initialize a channel, which is not possible with an already initialized channel.
You can have one worker per channel, no problem but what purpose would multiple workers on one channel serve?
can you explain? Maybe it is something we need to consider.
BR
Marvin
There are these constructors for a worker object :
Worker() Initializes a PCAN-Basic Worker object with its default values.
Worker(PcanChannel, Bitrate, Boolean) Initializes a PCAN-Basic Worker object.
Worker(PcanChannel, BitrateFD, Boolean) Initializes a PCAN-Basic Worker object.
All of them will initialize a channel, which is not possible with an already initialized channel.
You can have one worker per channel, no problem but what purpose would multiple workers on one channel serve?
can you explain? Maybe it is something we need to consider.
BR
Marvin
---
Marvin Heidemann
PEAK-Support Team
Marvin Heidemann
PEAK-Support Team
Re: Multiple Workers
Hi,
I have an existing LabVIEW project, which communicates with different ECUs over UDS, originally using only NI-XNET.
Our idea was to keep this project, but extend it with other CAN/LIN hardware. One of these hardware type is Peak, in order to be independent of NI.
As the project already exists, I just created a new class "CAN_Peak", which is a child class of the Diagnostics\CAN class. This is the class hierarchy:
Diagnostics (main class)
--> CAN (Child class of Diagnostics)
--> CAN_NI-XNET (Child class of CAN)
--> CAN_Peak (Child class of CAN)
--> LIN
--> LIN_NI-XNET (Child class of LIN)
--> LIN_Peak (Child class of LIN) -- not yet implemented
The project has a trace function, which should work even when the interface is not initialized at all. This works as long as we use NI-XNET, where you can create multiple sessions. So if I start trace, the tracing part of the software listens to the CAN/LIN interface, even if it is not initialized or started yet. This functionality I would keep, and I ty to implement the same with Peak. That is the backround why I wanted to have multiple Workers.
The diagnostics part works with Peak hardware in the meanwhile without issues. The only issue left is the tracing function.
I could initialize the interface by creating only one Worker object, register "MessageAvailable" callback, and fill a queue there. This is actually what I am doing. But in this case I have to pass the queue reference to the tracing engine. I want to trace messages even if I don't start my software, but also when I send messages in the PCAN-View.
Is that possible somehow using the Pcan .NET assembly?
I have an existing LabVIEW project, which communicates with different ECUs over UDS, originally using only NI-XNET.
Our idea was to keep this project, but extend it with other CAN/LIN hardware. One of these hardware type is Peak, in order to be independent of NI.
As the project already exists, I just created a new class "CAN_Peak", which is a child class of the Diagnostics\CAN class. This is the class hierarchy:
Diagnostics (main class)
--> CAN (Child class of Diagnostics)
--> CAN_NI-XNET (Child class of CAN)
--> CAN_Peak (Child class of CAN)
--> LIN
--> LIN_NI-XNET (Child class of LIN)
--> LIN_Peak (Child class of LIN) -- not yet implemented
The project has a trace function, which should work even when the interface is not initialized at all. This works as long as we use NI-XNET, where you can create multiple sessions. So if I start trace, the tracing part of the software listens to the CAN/LIN interface, even if it is not initialized or started yet. This functionality I would keep, and I ty to implement the same with Peak. That is the backround why I wanted to have multiple Workers.
The diagnostics part works with Peak hardware in the meanwhile without issues. The only issue left is the tracing function.
I could initialize the interface by creating only one Worker object, register "MessageAvailable" callback, and fill a queue there. This is actually what I am doing. But in this case I have to pass the queue reference to the tracing engine. I want to trace messages even if I don't start my software, but also when I send messages in the PCAN-View.
Is that possible somehow using the Pcan .NET assembly?