Adjust tracing sampling frequency

The free CAN Software API (Application Programming Interface) for Windows®
Post Reply
braden
Posts: 4
Joined: Wed 15. Jul 2020, 16:35

Adjust tracing sampling frequency

Post by braden » Tue 4. Aug 2020, 16:55

I'm using PCAN-Basic to build a custom application to interact with my hardware, and I've been successful in writing data to a .trc trace file. I'm getting a new data point about once every 0.1 ms. I want to slow this down (once per second, once per minute) to allow for longer tests. Is there a parameter I can use to change the sampling rate that produces the trace file? I checked the PCAN-Parameter documentation and didn't see anything.

Thanks

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

Re: Adjust tracing sampling frequency

Post by K.Wagner » Tue 4. Aug 2020, 17:40

Hello,

this is no possible. Writing in the trace file occurs only when a message is read. Since PCAN-Basic doesn't read messages actively, but only when you call the function CAN_Read, or CAN_ReadFD (according to your configuration), you cannot adjust a time for flushing data. The only thing you could is to read slower, but I think this could be more a backdraw than a progress.
Best regards,
Keneth

braden
Posts: 4
Joined: Wed 15. Jul 2020, 16:35

Re: Adjust tracing sampling frequency

Post by braden » Tue 4. Aug 2020, 17:58

Yes, that's what I want. I want to read data slower (less frequently) to collect data over a longer period of time. How would I go about doing this with PCAN-Basic?

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

Re: Adjust tracing sampling frequency

Post by K.Wagner » Wed 5. Aug 2020, 08:34

Hello,

then you just need to call CAN_Read less frequently. Each call to the CAN_Read function will return just one message, so you can use a timer, set its interval to the frequency you want to read and call the CAN_Read function each time the time elapses. But keep in mind that doing so could lead to queue overruns errors, if the queue gets full because it is being read to slow. Note that the reception queue can contain up to 32767, and there is no parameter in PCAN-Basic to ask the current message count of it. You may want to set a filter, if you are expecting just a set of IDs.
Best regards,
Keneth

braden
Posts: 4
Joined: Wed 15. Jul 2020, 16:35

Re: Adjust tracing sampling frequency

Post by braden » Wed 5. Aug 2020, 18:05

Thanks, I'm trying this but still having issues. It seems like the frequency of the time stamps in the trace file in the same no matter how often I call CAN_Read(). To be clear, what I really want is less frequent data in the resulting trace file for analysis purposes.

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

Re: Adjust tracing sampling frequency

Post by K.Wagner » Thu 6. Aug 2020, 09:11

Hello,
braden wrote:
Wed 5. Aug 2020, 18:05
It seems like the frequency of the time stamps in the trace file in the same no matter how often I call CAN_Read()
Just to read a message "later" doesn't mean that they will change their timestamps. You need to understand more how CAN works.
braden wrote:
Wed 5. Aug 2020, 18:05
To be clear, what I really want is less frequent data in the resulting trace file for analysis purposes.
If you just want to take a "snapshot" of the data at certain point and to have this in a trace file, then you will need to do more steps. Note that a trace file is actually thought to get "all" data you are transmitting. I see folowing ways to go:
  1. As I said before, setting of some filters to just get interesting messages for you. In this way, not all data received but the data important for you is placed in the trace file.
  2. You could start and stop tracing each time you need to get data. The problem here is that you will have several trace files (one for every trace trigger you do).
  3. You can use the parameter PCAN_RECEIVE_STATUS (see PCAN-Parameter_Documentation.pdf). Configuring this to off tells the API to discard messages coming from the device. Configuring this to on again, restores the reception of messages. You could use a timer to enable this each X amount of time, wait the time you want to trace messages, and disabling it again.
I think the last is the best approach for you, if I understood well what you want to do. You would have only one trace file with "fresh" data passing to the moments when you activate the PCAN_RECEIVE_STATUS parameter.
Best regards,
Keneth

Post Reply