From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Contract multiple delimiters for "Spreadsheet string to array"

Hi guys! I know that it is an old topic , but I will try !  🙂

 

My DAQ board sends to PC data in the following format.

!voltage1[0],voltage2[0];voltage1[1],voltage2[1];voltage1[2],voltage2[2].....voltage1[n-1],voltage2[n-1]:TIMER4,TIMER5<CR>

! is the starting character

and we have "," , ":"   and ";" as delimiters.

In the end of the packet (after ":") my board sends the values of two microcontroller timers (4 and 5).

The first data packet ends with a <CR> and my boards repeats that every 3 seconds.

 

I need to plot voltage1[n] and voltage2[n] in two separate graphs and my time base is the value of TIMER4 / n.

 

The real data is like showed below.

 

!0016442034,0000727890;0016499095,0000727024;0016543605,0000724990;0016568541,0000722157;0016578803,0000719243;0016587848,0000716010:0123456789,9876543210<CR>

 

I have used and modified altenbach's VI but some delimiters are bothering me yet.

 

 

Modified Altenbach's VI

VI.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Case value 1 detail

vi1.PNG

 

 

 

 

 

 

 

 

The result is:

screen.PNG

 

 

 

 

 

 

 

 

 

 

 

 

The VI was great to separate correctly the values of voltage1 and voltage 2 in two separate strings but I did not know how to avoid the last comma.

 

Also in Timer4 and Timer5 I could not avoid the characters ":" and "," right before the numeric values.

 

I would be grateful if anybody help to solve this issue or give me other tips to do what I need with that data.

 

Thank you everybody in advance !

0 Kudos
Message 1 of 4
(2,834 Views)

 Your strings appear to have the following format:

  • A "header/separator" character from the set [!;:] is followed by a comma-separated pair of numbers.
  • Pairs headed by ! or ; are pairs of Voltages.
  • Pairs headed by : are pairs of Timers.
  • A single character <CR> ends the string

You don't say, but (in principle) there could be multiple pairs of Timer values, and Voltages and Timers could be intermixed -- the header character can determine which is which.

 

The Scan Format %[!;:]%d,%d will isolate the header character and the pair of numbers that follow.  If used with Scan from String, it will "peel off" Voltage or Timer pairs one at a time, until there is 1 character left.  To accomodate strings ending in <CR><LF>, I used the criterion that the remaining string length was <= 2 characters.  If the header character was ! or ;, I added it to the Voltage array, while if it was ":", I added it to the Timer array.  [You could, in principle, simply exit when you output the Timer, but the code shown here is designed to be more "general" ...].

 

This simple logic can be written as follows:

Multiple delimiters.png

Note it only uses Scan from String and builds arrays with the While loop (it does not use Spreadsheet string to array).

 

Bob Schor

0 Kudos
Message 2 of 4
(2,794 Views)

Crosspost where I made an attempt that uses search split string.

0 Kudos
Message 3 of 4
(2,758 Views)

 

Lets try to do this without knowing the number of rows or columns at dev time shall we.

 

If you haven't installed "Hidden Gems" You probably should- Via VIPM

Split String.vi is in <LabVIEW>\vi.lib\Advanced String\ (That function you don't recognize doing some of the work)

Capture1.png

Danged Ctrl+U moved that constant way over there


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 4
(2,742 Views)