From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Microcontroller based data acqsuition system

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

0 Kudos
Message 1 of 7
(3,129 Views)

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?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 7
(3,099 Views)

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

0 Kudos
Message 3 of 7
(3,097 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 7
(3,084 Views)

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.

0 Kudos
Message 5 of 7
(3,081 Views)

@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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 7
(3,078 Views)

I am using producer consumer loop and reading all available bytes at port.  Now its working

0 Kudos
Message 7 of 7
(2,982 Views)