LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read two columns of data from the Serial Port

Solved!
Go to solution

Hello,

 

I am trying to read two columns of data from the serial port.

 

Example:

 

52439       52430

52437       52440

52209       52214

51065       51070

52390       52206

 

I am using the Visa serial function and I can read the first column of data from the serial port, but I cannot figure out how to read the second column.

I want to graph both sets of data.

I have attached my VI.

 

Thank You For Your Help.

 

0 Kudos
Message 1 of 8
(4,716 Views)

What do you mean by reading  a column from serial data?  Serial data is serial, it doesn't com in columns.  Just a string of data.

 

How is the data actually arriving?  Is it 2 values that are separated by a delimiter such as a tab character?

 

If so, use Read from string and set the format string to account for the 2 pieces of data.

Message 2 of 8
(4,708 Views)

Yes its two values that are separated by a tab character.

And could you please elaborate the "read from string" suggestion.

 

Thank You

0 Kudos
Message 3 of 8
(4,705 Views)
Solution
Accepted by topic author P_Dhaliwal

The Scan from String function takes a "Format String" on the top (right-click the function and choose Help, which explains all the inputs).  In particular, you can say "Give me two numbers separated by a tab" and the output will be two numbers (either integers or floats, depending on the format you choose).  In particular, %d\t%d specifies Decimal Integer, <tab>, Decimal Integer.

0 Kudos
Message 4 of 8
(4,687 Views)

Could you please run your VI until the "read string" indicator contains data. Now stop the VI and right-click the terminal of "read String" and select "create constant". Copy this newly created diagram constant to the diagram of a new VI, save the VI under a new name, and attach it here. Thanks!

0 Kudos
Message 5 of 8
(4,682 Views)

@P_Dhaliwal wrote:

Hello,

 

I am trying to read two columns of data from the serial port.

 

Example:

 

52439       52430

52437       52440

52209       52214

51065       51070

52390       52206

 

I am using the Visa serial function and I can read the first column of data from the serial port, but I cannot figure out how to read the second column.

I want to graph both sets of data.

I have attached my VI.

 

Thank You For Your Help.

 


What other members are explaining to you, should look like this below snippet...

 

Read 2D array

 

Code (saved in LabVIEW version 2010) is attached.


I am not allergic to Kudos, in fact I love Kudos.

 Make your LabVIEW experience more CONVENIENT.


0 Kudos
Message 6 of 8
(4,670 Views)

moderator1983 wrote: What other members are explaining to you, should look like this below snippet...

I don't think so, your code will most likely not work at all. He is reading 20 characters at a time, presumably coresponding to one row with two values. In the current data example, we have 5 digits, 7 spaces, and another five digits. This does not add up to 20 chars, so there might be other delimiters or we migh even have a frame shift that needs to be handled. That's why I wanted to see a typcal raw string before making any premature conclusions.

 

Looking at the original code, we have many issues that also need to be addressed.

 

  • We have the pt-by-pt filter. Should it apply to all sequential points or should it apply now to each column seperately?
  • Same for the threshold detector...
  • Merging two scalars into dynamic data seems silly since there is no timing information. A plain bundle would suffice.
  • Why is the array initialized with an size=1 array instead of an empty array? (not even needed, see below)
  • Also "build array" is more appropriate than "insert into array". (not even needed, see below)
  • Actually, the accumulated build array is never used (except for the last element!) but grows forever, possibly leading to memory problems. All that is ever needed is the previous element, which can be kept as scalar in a shift register or feedback node and memory use is constant.

In summary, the current code is higly flawed. It need to be cleaned up as well as adapted to two values per read as required. We need more information to continue helping.

Message 7 of 8
(4,644 Views)

Thanks for the help. 😃

0 Kudos
Message 8 of 8
(4,599 Views)