LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Splitting up incoming data

Hey Everyone,

 

I have some data coming in through a serial port and I'm a little stuck on how to process it. It comes it as follows:

 

T2343

A2140

B416

C3546

D6542

 

With T, A, B, C and D coding for time and the position of different parts respectively. I thought I could check each string for their first letter and then either let them pass or not based on that letter with Match Expression, but that returns an empty string which then gets converted to zero. The values need to both be written to a file (each in their own column) and get displayed on a graph (I'm using an xy graph to plot the A and B values over the time). Anyone have any ideas on how I could best approach this?

0 Kudos
Message 1 of 9
(1,479 Views)

Hi Phoenix,

 


@RisenPhoenix wrote:

I thought I could check each string for their first letter and then either let them pass or not based on that letter with Match Expression, but that returns an empty string which then gets converted to zero.


So you created a VI, but it is not working as expected? Then you made something wrong and you need to debug - as you forgot to attach your code we cannot do that part for you…

 


@RisenPhoenix wrote:

It comes it as follows:

T2343

A2140

B416

C3546

D6542


What about ScanFromString using "%1s%d" to parse each line? You will get two outputs: the first char and the numeric value after that char…

 


@RisenPhoenix wrote:

The values need to both be written to a file (each in their own column)


Based on that single char you could build an array for each category of values.

When you receive a full block of data (consisting of 5 lines/values) then you could go with a 2D array to store your 5 columns of data…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 9
(1,473 Views)

Hi GerdW,

 

Thanks for the advice already. I don't have a small version of this VI and the whole thing is rather big, but I've created a screenshot of the relevant part here, hopefully that helps. I'm quite new to LabView, so I'll look into how to receive or store 5 blocks of data at once. The way it works now, it seems, is that every time it reads I just get one line so I was trying to send that to the correct place right away. If you have any more tips or points based on the screenshot, I'd be happy to hear them.

0 Kudos
Message 3 of 9
(1,462 Views)

 Hi Phoenix,

 

see this as a concept suggestion:

Not the most efficient (or error proof) way, but should work…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 9
(1,455 Views)

@RisenPhoenix  ha scritto:

Hi GerdW,

 

Thanks for the advice already. I don't have a small version of this VI and the whole thing is rather big, but I've created a screenshot of the relevant part here, hopefully that helps. I'm quite new to LabView, so I'll look into how to receive or store 5 blocks of data at once. The way it works now, it seems, is that every time it reads I just get one line so I was trying to send that to the correct place right away. If you have any more tips or points based on the screenshot, I'd be happy to hear them.


This picture is not enough. AFAIK, your code should work, if the string is received. Do you actually receive the whole string? Why you read 32 characters? What character(s) separate the individual lines? How do you initialize the serial port?

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 5 of 9
(1,447 Views)

I guess the question is if these value appear in a certain order or least that every consecutive set of five contains one of each tag characters. What should happen if a set of five is incomplete for example if one tag appears more than once in quick succession.

0 Kudos
Message 6 of 9
(1,393 Views)

Here's a quick draft how to process the case where for each consecutive set of five readings, all tags appear exactly once, but in random order. You can easily append a new row to the file in the true case and graph the desired columns.

 

Basically we fill an array of five until all have new data, then append it to a 2D array, resetting the array of five.

 

altenbach_0-1614389543141.png

 

 

Message 7 of 9
(1,388 Views)

Hi everyone,

 

Thanks for all the help, it inspired me to tinker around a bit and find a solution. I've added the subVI to show what I came to, should it be useful to others. In the end I was able to configure the device that sends data over the serial port to send it all in one line with a semicolon in between, making things a little easier. The outputs are split over an array that can be written straight to a file and a separate channel for time and 2 positions to be displayed in a graph. If anyone sees any glaring (style) errors I would love to hear them and improve on this, but at least this seems to work.

0 Kudos
Message 8 of 9
(1,341 Views)

Hi Risen,

 


@RisenPhoenix wrote:

If anyone sees any glaring (style) errors I would love to hear them and improve on this, but at least this seems to work.


Why do you need to split the string into 5 values by duplicating code 5 times?

And why do you hesitate to use polymorphism for the scaling (as I suggested before)?

Best regards,
GerdW


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