05-06-2017 04:58 AM
Microcontroller is interfaced to LabVIEW using UART. When I am trying to read data into LabVIEW i am not getting no. of bytes in multiple of 4. For my application 1 sample has 4 characters e.g 258,
As shown in figure sample is separated by ,. Also as shown in figure. first sample don't have 4 characters rest of all samples have 4 characters and hence during plotting my first sample values is different than other all samples . How can I read data so always I get each sample correctly. Please see attached image marked with red color highlight
05-06-2017 06:46 AM
There are a few ways to handle this. Your big issue is that it sounds like you are using the Bytes At Port. Don't!!! Instead, we need to come up with a scheme so that we get full messages.
Since you are streaming data, I recommend having a command that your LabVIEW code can send to the microcontroller to start sending data. This will fix that first sample being cut off.
As to the best route for the rest of the issues, a little more information is needed. What is the sample rate of the data (how often is data sent)? Are there multiple channels?
05-06-2017 06:56 AM
Yes I am using bytes at port.
Microcontroller start to acquire data and sends serial port when I am sending command from LabVIEW called AnalogIn.
What you are looking in previously attached image is not first sample. I am able to read first sample properly but when 2nd time I am reading bytes at port at that time sampling is cut off. Eg.
1. first time reading bytes at port last sample is ,2
2. Second time reading bytes at port first sample is 38,
Means in first reading last sample is cut off and in next all readings first and last sample have chances to cut off. This is single channel issue.
Right now I am deleting first and last sample every time when I read bytes at port
05-06-2017 08:41 AM
You didn't answer my question about the sample rate (ie how fast the data is being sent).
If the rate is fairly slow (a few ms per sample), you could just set the comma as the termination character and just tell the VISA Read to read 10 bytes. What this will do is have the VISA Read return a single sample each time it reads (it will stop reading when the termination character is read).
If a faster rate, then I would just tell the VISA Read to read 40 bytes. That will give you 10 samples per read. This will work as long as each reading is exactly 4 bytes.
05-06-2017 08:48 AM
My rate is faster. Setting loop rate 1 second in LabVIEW. I am able to get 2300 samples (10 bit). I mean i am reading 9300 bytes approx. in 1second.
In this case if I set no. of bytes to 40 it will overflow and my system becomes hang.Gives error character you are trying is overwritten like that.
05-06-2017
09:05 AM
- last edited on
08-14-2024
04:47 PM
by
Content Cleaner
@piZviZ wrote:
My rate is faster. Setting loop rate 1 second in LabVIEW. I am able to get 2300 samples (10 bit). I mean i am reading 9300 bytes approx. in 1second.
In this case if I set no. of bytes to 40 it will overflow and my system becomes hang.Gives error character you are trying is overwritten like that.
Need to see code to know what else is happening in your loop. But if you get a overflow, read more and/or use parallel loops to do all of the processing (Producer/Consumer). The 40 was just an example (should be ~4ms of data). You could try 100 (25 samples per read, ~11ms of data).
Also make sure you do not have a Wait in the loop. The VISA Read will limit the loop rate.
05-15-2017 07:12 AM
I am using producer consumer loop and reading all available bytes at port. Now its working