LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial data (real time plot)

Im having some problems with the VI I made to read data of a 3 axis accelerometer. The VI is working but after some time it shows an error (it says that the string is not in the correct format, but when I monitor the serial port with the program ''tera term'' I can see that the data is shown properly). I don´t know whats hapenning. Can somebody help me? The VI is attached. Thanks

0 Kudos
Message 1 of 8
(2,886 Views)

Somebody?

0 Kudos
Message 2 of 8
(2,863 Views)

What is the exact error code?  Which VI or function generates the error?

 

What is the exact string which was received when the error occurs?  Is it possible for the termaination character to appear as a data byte?

 

What value do you use for Bytes to Read?

 

You loop almost certainly does not run as fast as you apparently intend.  I do not have the Power Spcetrum VI you are using so I substituted the standard on from the Signal Processing palette.  I replaced the VISA Read with a random number function. When I run the loop for about 10000 iterations the mean time per iteration is 1.5 ms and the maximum is 25 ms.  If it runs longer, the times will get worse because of the memory reallocations required by Build Array. Maximum is 253 ms and the mean is up to almost 4 ms after 40000 iterations.

 

Lynn

0 Kudos
Message 3 of 8
(2,850 Views)

Johnsold,

 

Thank you for your  answer. This VI is used to plot the data obteined from an accelerometer. The data is in the format  512,734,1000 (3 axis accelerometer). I´m sending this data thru serial in a rate of more or less 550Hz (big rate!!). Probably as you sad my VI don´t run as fast I want (maybe this is causing the problem). 

Now answering  your questions:

The error is in the "Scan From String" block. I cant say to you now (because the accelerometer is not with me in this moment) the exact error code, but it basicaly says that the string is not in the format that I configured it to be. When the error occurs  the string showed in the read buffer box is different from the format (512,734,1000) I  dont know why because when I use a program that monitors the serial data I cant see any data that is not  in the correct form.

I use 15 in the bytes to read config.

 

There is something I can do to make the VI faster? I thin that is the problem.

 

Thanks very much

0 Kudos
Message 4 of 8
(2,834 Views)

Without seeing the data it is hard to say what might be happening.  The first thing I would try is to set Bytes to Read to a larger value, say 50.  Then you will be certain that the Read does not terminate before receiving a termination character. Wire the error out of the Scan from String to an OR gate. Wire the stop button to the other input. The output goes to the loop termination terminal (which was connected to the stop button). This will stop the loop when the error occurs and you can see on the Read buffer indicator exactly what string was received.

 

Probably the most effective thing you can do to make the VI faster is to change to a two-loop architecture like the Producer/Consumer. The Producer loop would have only the VISA Read and an Equeue to send the data to the Consumer.  The Consumer would Dequeue the data, check and convert the string to numerics, accumulate it in an array, perform the spectral analysis, and update the displays.

 

At 9600 baud (the value you have set in your VI) you get approximately 1 character per millisecond. Reading a 15 byte message cannot occur more than 64 times per second.  To reach 550 messages per second at 15 characters per message would require a rate greater than 82500 baud. The next higher standard rate is 115200 baud.  Can your accelerometer send the data that fast?

 

Lynn

0 Kudos
Message 5 of 8
(2,827 Views)

Johnsold,

 

My accelerometer can send 500Hz  of data (type - 543,654,234). I took out the fft from the VI, I think I will not need to do fft in real time. Can you please help me to change my VI to a two-loop architecture and dont know how to do that. Thanks

 

 

 

0 Kudos
Message 6 of 8
(2,797 Views)

Someone can help me  tranforming my VI to the Producer/Consumer architecture. I dont know how to do that. Thanks

0 Kudos
Message 7 of 8
(2,782 Views)

I hope you were trying to use the Producer/Consumer Design Pattern to learn how it works while I was busy with other things today.

 

Here is a quick and dirty conversion of your VI to a two loop system.  I do not have the Power Spectrum VI or your serial device so I have not tested any of this.

 

The upper loop will read each string and place the string into the queue.  For improved speed eliminate the indicators.  They may be useful while developing and troubleshooting the program but the data they show will be changing faster than a human can see and interpret the data.

 

The lower loop will retrieve each string from the queue and do the same conversion and analysis you were doing before.  Multiply by 1 seems unnecessary, but perhaps the final version uses another value.  The way you have that array set up it will continually grow.  As it grows LV needs to allocate new memory space for it. Arrays must be stored in contiguous memory locations so this process quickly fragments memory and may soon lead to program failures due to insufficient memory.  Determine the largest array you will ever use and Initialize the array to that size. Then use Replace Array Subset inside the array rather than Build Array.  This has the additional advantage that your spectral resolution will not be changing continually.

 

Lynn

0 Kudos
Message 8 of 8
(2,776 Views)