12-28-2021 08:09 AM
Hi guys, I am reading these two sensors from an integrated cable with its own communication protocol. I am using a stream_send option where i simply give just once at the beginning the initial command to the cable, 0x01 0x1E 0x00 0x45. The sensors start giving me their data through a constant stream of 8 bytes, without me having to make the request each time i want a data. The last two bytes of these 8 bytes are always the same and are a sort of tail. Since i don't know the specific frequency of this stream of data, and i would like to sample my data every 5 ms (200 Hz) and i cannot control the stream frequency, i thought that i could receive the data through this stream, but enable the saving just every 5 ms. For some reason my labview does not work. If i save everything that i get from the serial communication it works, if i try to count and save every 5 ms it doesn't work. Can someone help me understand what i am doing wrong? Thank you every one
12-28-2021 09:11 AM
There's quite a few things wrong with your code, mostly style issues. Wire bends, right to left wiring, etc.
But the simples part might be what's causing you trouble:
Are you sure that times is called every ms? If it returns 6, 11, 14, 18, etc, the output might never become 0. You need to keep the previous save time, and compare the current time with the last time + interval time.
Are you sure that output ever gets 0? The integer is converted to a double, and that causes rounding. The output might be 0.00000000001. That 5 needs to be an integer. You probably be OK in this case, but you're walking on thin ice. And without good reason.
12-28-2021 10:13 AM
@dave97 wrote:
The last two bytes of these 8 bytes are always the same and are a sort of tail.
If the last two bytes are always the same then wouldn't it be simpler to just save when you receive those bytes?
12-28-2021 11:07 AM
wiebe@CARYA wrote:
There's quite a few things wrong with your code, mostly style issues. Wire bends, right to left wiring, etc..
I could not agree more!
12-28-2021 03:06 PM
Thank you for your reply. I see your point, it could be, i thought that tick counter returned the ms value of the timer. How can I store the old value of my timer until the new value is 5 ms higher than the old value? I can't figure out a method.
12-28-2021 03:12 PM
Hi Dave,
@dave97 wrote:
How can I store the old value of my timer until the new value is 5 ms higher than the old value? I can't figure out a method.
You should carefully read message#2 again and look at the images in that message!
Ever heard of shift registers?
12-29-2021 03:36 AM - edited 12-29-2021 03:48 AM
@GerdW wrote:
Hi Dave,
@dave97 wrote:
How can I store the old value of my timer until the new value is 5 ms higher than the old value? I can't figure out a method.You should carefully read message#2 again and look at the images in that message!
Ever heard of shift registers?
In retrospect, that code wouldn't work.
The ms count is a U32 so 0 + 5 could take a long time to get the first trigger. The compare won't work well... Once the count wraps to 0, it will again take a long time before prev + 5 > current...
But the shift register is the key.
Something like this:
The subtract results in a valid dT, despite (or because) both values are unsigned.
If the U32 wrapped, you'd get e.g. 5 - (max U32-5) = 10
Of course you can save the U32 drama and use Get Data/Time In Seconds or High Resolution Relative Seconds.vi
12-29-2021 05:58 AM
I tried the same configuration, but I think it is possible that the difference never get exactly equal to 5 as you said in your first answer. When i tried what you showed me my file ends up to be empty. So after the difference I had to put a greater compared with 5. Now the file doesn't end up empty, but the frequency is not 200 Hz, it is like 10 Hz. In 10 seconds i get 100 samples. I don't get what is wrong..
12-29-2021
08:44 AM
- last edited on
05-14-2025
04:09 PM
by
Content Cleaner
As far as speeding up your code, there are a few things to look at.
1. Your data processing is horribly inefficient. There is no reason at all to convert into a Boolean Array, combine, and convert back to numbers. Just use Unflatten From String on your original string data and you can go straight to your integer values before doing the math on those values.
2. You may need to go with a Producer/Consumer setup in order to separate the acquisition, processing, and logging into 2 loops. File IO tends to be slow, so this might be a way to gain up the processing rate.
12-29-2021 11:37 AM
Thank you for your suggestions, i changed the convertion into Boolean Array with your method that for sure is more efficient. I am looking at the producer/consumer setup now.
However my problem remains the same, i don't understand how to save my data every 5 ms. I am sure that it is not a problem of speeding up my code, because i succeeded in saving my stream of data with the original frequency that is much higher than 200 Hz.