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: 

how to treat and save data received from rs232


Dear Experts:
I cannot figure out how to treat and save data received from RS232, please help me, thank you in advance
my project:
i use PIC18f4553 to send data to computer via RS232, the pattern of data flow is: X_High bytes (8bits), X_Low bytes (8bits), Y_High bytes (8bits), Y_Low bytes (8bits), X_High bytes (8bits), X_Low bytes (8bits), ......,
here is what i plan to do:
VISA read -->put "X_High bytes (8bits)*256 + X_Low bytes (8bits)" in x column, and put "Y_High bytes (8bits)*256+ Y_Low bytes (8bits)" in y column, in the mean time, save and display these data.

0 Kudos
Message 1 of 6
(2,401 Views)

First, unless you absolutely need the speed, add a synchronization byte or bytes so that you know when a message starts or ends.

 

I just checked. The PIC 18F4553 has a 12-bit A/D converter. So you can use the 4 extra bits to designate the X and Y channels and which is the high byte and which is the low byte.

 

Doing this will help you avoid any confusion if the VISA Read ever gets out of synchronization.

 

Next, what have you tried? What parts are giving you trouble? Have you looked at the serial communications examples? (Although they may not be the most applicable examples for what you are doing, they can still be a good starting place.

 

If you are completely new to LabVIEW, work through the on-line tutorials to get started. You will save far more time than the tutorials take by what you learn.

 

Lynn

0 Kudos
Message 2 of 6
(2,396 Views)

thank you for the reply

So far, all the hard ware and VISA write are working properly. the only problem labview software for data receiving, for example, i want to set a four steps loop in which i can put high byte and low byte of x in a data array and put high byte and low byte of y in another data array, once i am out side of the loop, i can treat data and  put x and y in a data array.

i checked all the labview examples, i haven't find an appropriate one.

please give me some hints, if possible show me an example.

0 Kudos
Message 3 of 6
(2,389 Views)

Here is a very simple example. The Data from PIC is a byte array. This would be replaced by the VISA Read and the conversion from string to numeric. It appears that you already know how to do that.  The for loop would probably be replaced with a while loop and a stop button so that you could run indefinitely.

 

Index Array can be expanded to get all four elements at once. The Join Numbers primitives (from the Numeric >> Data Manipulation palette) takes care of the conversion from bytes to a number. Autoindexing creates the arrays.

 

Lynn

0 Kudos
Message 4 of 6
(2,364 Views)

Thank you.

but, how to save and display data collected while the data receiving still keeps going

0 Kudos
Message 5 of 6
(2,355 Views)

The best way is to use a Producer/Consumer design pattern or template. This moves the display and saving to a parallel loop.

 

You can build the array in a shift register and display it inside the VISA Read loop but this can lead to memory allocation problems if not handled carefully. Saving to a TDMS file is optimized for speed.

 

Lynn

0 Kudos
Message 6 of 6
(2,345 Views)