LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read, save data from serial port (write to txt or lvm), and plot data as waveform

hi,
i've been stuck with this problem for weeks and really need some help. i've been searching alot but i can't find a proper solution
 
i'm sending values from a PIC to the computer by serial connection. each value of the data ranges from 1 to 4 digits (value of 0 to 1024) and is separated by the termination key (return \n). the values are converted to string format before sending it to the serial port. i have no problem reading this values correctly using hyperterminal. but i have problem using labview to display the values, write the data to file, and plot it as a waveform.
 
writing to file:
using my 'serial_to_txt with display.vi', i can write to txt file the correct values but the data is stored horizontally with each value separated by a space. how do i make it store values vertically?
if using the style in 'serial_to_txt with display(express).vi', it can store data vertically but the values are wrong. i think there's some problem at the conversion part.
 
plotting waveform:
a) i think labview is plotting each digit individually instead of the whole value (eg. 1,2, and 3 instead of '123'). how do i solve this?
b) is there a problem at my string conversion? i'm using the 'string to array' function because to plot waveform, the input has to be in array format.
 
i really need some help with this. examples will be great if anyone has done this before.
 
thx
Regards,
Wen Keat
0 Kudos
Message 1 of 26
(9,940 Views)
Hi Wen,

your first vi just convert the string to an U8 array, that's not the proper way to convert to numbers.
Btw.: you should not replace vis from vi.lib with your own versions (serial port read), always save them with a different name!
The second vi ("express") does the same wrong conversion...

To convert your string to numbers you should use "spreadsheet string to array" - this will produce an array of numbers for displaying on the chart/graph.


Message Edited by GerdW on 03-05-2008 12:02 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 26
(9,929 Views)
hi,
thx for the help.. i realised that wat i did earlier was making it plot strings stored in array without converting it to numeric first but there's still one problem: only the y-axis is changing according to the values from the serial port but the x-axis always remain at -1, 0 and 1. so it's actually plotting a point and not a waveform. how do i make it continuously plot a waveform of the serial data (y axis) while the time axis just increases automatically?

thx
Regards,
Wen Keat
0 Kudos
Message 3 of 26
(9,901 Views)
Hi Wen,

either replace the graph by a chart or build an array of all measurement values (shift register in the while loop)...
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 26
(9,895 Views)
hi thanks alot for the help so far. currently i'm one step nearer to plotting out the complete data but there's still one problem remaining.

after the 'spreadsheet string to array' conversion part, there seems to be a consistent additional unknown values shown in between my correct data values. these value are very small values (around 0 to 10) so i'll be seeing my chart going up n down all the time in between my data values. this is also observed from the table used to output the data from that function. i know this is not a problem from the sending of data or reading of the port because the txt file where the data was written to does not show those unknown values.

since these small values are separating my data values, i'm wondering if this is caused by the 'spreadsheet string to array' function trying to convert the carriage of return string (\n) which i use to separate my data values? so how do i solve this?

thanks
Regards,
Wen Keat
0 Kudos
Message 5 of 26
(9,852 Views)
Hi Wen,

I added a changed version of your vi - there's at least one "big" problem hidden...

To help you with your string conversion problem you should show us the string you receive from the serial port:
- run the vi on your equipment
- when you received a string you stop it
- make a constant from the "read string" and save the vi
- attched the vi with the saved constant - now we will see what you receive through serial port and how the conversion seems to go wrong...
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 26
(9,843 Views)

hi,

i'm currently not in my lab so i can't try it out yet. anyway from wat i've tested earlier, the string is read in as individual characters at a time. this means that let say my data value is "123\n", it will be read as "1" then "2" then "3" and then "\n" which is 4 bytes and this continues for the rest of my other values. at my program for my PIC, it's actually suppose to be sending each data as a single string (single byte?) but i don't understand why is it read as separate bytes for each digit. i found out abt this when i tested by setting the 'number of bytes to read' instead of using the 'read number of bytes at port' subVI like i did in my VI. so let say i set the 'number of bytes to read' at 3, and the value tat is suppose to be read is 4 digits, labview will display the first 3 digits and then jump to display the 4th digit and \n and the 2 digits of the next value.

actually i dun understand if this is a problem at my PIC program part or is it because serial port will always read those as individual bytes? i've attached a copy of my PIC program in C language. have a look at the portion which do the conversion of the data to string.

thx alot for your help and patience.

Regards,
Wen Keat
0 Kudos
Message 7 of 26
(9,836 Views)

Sorry to interrupt you guys.I have seen you guys that you people have attached some files with your messages.Can you please tell me how to attach a file/vi with the question you are putting forward to the forum.i have a querry that i thought of putting in front of you but i couldnot upload the vi.

 

Sorry again for disturbing your discussion.

0 Kudos
Message 8 of 26
(9,834 Views)
Hi Robie,

below the "submit post" button you find a section labelled "Attachment" - here you can attach your files!
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 26
(9,832 Views)
Hi Wen,

sorry, I never programmed in C, so my understanding of C is limited. And there are a lot of string functions inside this c program (UARTWriteString(), putsUSART(), itoa(), UARTWriteBuffer() )...

Usually you send your data coded in ASCII, hence one char is one byte. Sending "123\n" results in 4 bytes. Conversion with LabView should work without any problems here, \n is recognized as separator between numbers. So please post some real string data (as described above) as soon as you get to the labSmiley Wink


Message Edited by GerdW on 03-13-2008 10:00 AM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 26
(9,830 Views)