07-30-2020 05:52 PM
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.
07-30-2020 07:12 PM
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
07-30-2020 11:42 PM
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.
07-31-2020 01:22 AM - edited 07-31-2020 01:24 AM
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?)
07-31-2020 03:57 PM
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.
08-04-2020 08:51 AM - edited 08-04-2020 09:00 AM
@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."
08-04-2020 11:14 AM
@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?
08-04-2020 11:31 AM - edited 08-04-2020 11:32 AM
Try this: