LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trying continuously sample data over a COM port then write selected specific information from each line to a csv

Hello All,

 

I need some help. I am trying to write a vi that samples the data received from a COM port at a controlled rate. For example lets say every 25 ms. In my current vi, I seem to only sample the data from the com port once and then nothing else. Could someone please help me figure out how to....

 

1. Sample the data from the com port at or close to a user defined speed.

2. Write the only the useful data read from the com port into a csv file.

 

My current vi is attached. Any help you guys can give would be appreciated.

0 Kudos
Message 1 of 8
(1,577 Views)

DON'T USE BYTES AT PORT!

 

That may even be 0 since you check it right after you open the serial port.  And it will always be 0 because that is the value at the tunnel when the while loop starts.

 

You might also want to watch Crossrulz's video: VIWeek 2020/Proper way to communicate over serial

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

Thank you for the reference. I think I have successfully fixed that issue please see the attached vi. However could someone still help me find a way to write the data I am receiving into a text file. I have read suggestions of using spreadsheet to array. However I can't seem to get a 1D array out of it. It always says 2D. Can someone help me sort this out? I tried to subset the output and I can't seem to get the vi to work properly.

0 Kudos
Message 3 of 8
(1,513 Views)

Hi damian,

 

what about "DON'T USE BytesAtPort!!!" don't you understand?

 


@damianhoward wrote:

However could someone still help me find a way to write the data I am receiving into a text file. I have read suggestions of using spreadsheet to array. However I can't seem to get a 1D array out of it. It always says 2D. Can someone help me sort this out? I tried to subset the output and I can't seem to get the vi to work properly.


You already write all received data into a file, so what is the problem?

Where comes this ""spreadsheet to array" comes into play?

Why do you have problems with 1D array vs. 2D array? (You know you can set to required datatype for SpreadsheetStringToArray at one of its inputs? Did you read the LabVIEW help for this function?)

Best regards,
GerdW


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

the data i am writing into the file is of the form:

 

{"type": "log", "msg": "2611165 -3641821 -498144 -2068035 2500628 1 0", "level": 20, "time_ms": 2611165, "path": "TEST_main.cc", "line": 85}

 

However I only want the underlined segment.I am trying to get to the point where I can write the 4 values as well as some other data I will be sampling to a .csv.

I tried to use "spreadsheet to array" to delimit by quotation marks("), then you index the array to select the following portion

2611165 -3641821 -498144 -2068035 2500628 1 0

then I used "subset array" to select only the values I need.Then write those values to file. When I wired this up it didnt work and my first thought was that it could be because at the last input of spreadsheet to array it should string 2D and I was under the impression I would be getting a 1D array.

0 Kudos
Message 5 of 8
(1,467 Views)

@damianhoward wrote:

the data i am writing into the file is of the form:

 

{"type": "log", "msg": "2611165 -3641821 -498144 -2068035 2500628 1 0", "level": 20, "time_ms": 2611165, "path": "TEST_main.cc", "line": 85}

 

However I only want the underlined segment.I am trying to get to the point where I can write the 4 values as well as some other data I will be sampling to a .csv.

I tried to use "spreadsheet to array" to delimit by quotation marks("), then you index the array to select the following portion

2611165 -3641821 -498144 -2068035 2500628 1 0

then I used "subset array" to select only the values I need.Then write those values to file. When I wired this up it didnt work and my first thought was that it could be because at the last input of spreadsheet to array it should string 2D and I was under the impression I would be getting a 1D array.


You should really be using a comma as the delimiter as the data are really grouped that way.  Then just handle the strings as needed.  I would actually code it to read and parse all the fields, then just choose the one you are interested in, because you never know when someone will want the other data, as well.  Seems fairly reasonable that at least some of the rest of the data might be useful.  Then you can look like a hero when someone asks you to modify the code to get the time in milliseconds and you can say, "It's already built in.  I'll just include it as part of the data to be saved."

 

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 8
(1,410 Views)

@billko

Bill,

 

I currently am using the scan string(i dont know if i am saying it right) function to parse the strings coming in. Could you should a mock example of how i would use the comma delimiters to create and array and then index it based on the values I want? 

0 Kudos
Message 7 of 8
(1,395 Views)

Try this:

 

SpreadsheetToArray.png

Message 8 of 8
(1,389 Views)