LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write/Read file in a custom format

Solved!
Go to solution

Hi guys,

I would like to write a file in the following format:

AmrLV_0-1657536540751.png


The event name is a string and the signal names is an array of strings. I am reading both the event name and string names from a file and I would like to link them together and write them in that format so I later could use this file to read the array of signal names in a VI by giving the event name as an input. Something like the section and key in INI files. 

I considered doing that using INI files but I read that saving arrays in INI files is not the best idea. Could someone suggest a file format for this purpose and some bullet points how to do it?

Thanks in advance

0 Kudos
Message 1 of 10
(1,645 Views)

@AmrLV wrote:

Hi guys,

I would like to write a file in the following format:

AmrLV_0-1657536540751.png


The event name is a string and the signal names is an array of strings. I am reading both the event name and string names from a file and I would like to link them together and write them in that format so I later could use this file to read the array of signal names in a VI by giving the event name as an input. Something like the section and key in INI files. 

I considered doing that using INI files but I read that saving arrays in INI files is not the best idea. Could someone suggest a file format for this purpose and some bullet points how to do it?

Thanks in advance


If the array isn't big, you can save it as a comma-delimited string by using Array To Spreadsheet String.vi and retrieve it by using Spreadsheet String To Array.vi.  Actually, you can save an array of any size, but the file size could become unwieldy.

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 2 of 10
(1,637 Views)

Thanks for your reply, Bill! 

and how would I link the array to the event name like I showed in the Screenshot?

0 Kudos
Message 3 of 10
(1,625 Views)

Hi Amr,

 


@AmrLV wrote:

and how would I link the array to the event name like I showed in the Screenshot?


Well, we don't know your data structures…

 

How do you receive your data ("array", "event name") and how do they "link together"?

Please define the term "link" in your case…

Best regards,
GerdW


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

@AmrLV wrote:

and how would I link the array to the event name like I showed in the Screenshot?


I would use a Map.  The key is the event name and the data is the array of signals.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 10
(1,605 Views)

The Config-file content I am reading has the following structure:

Signalname 1;Event1
Signalname 2;Event2 
Signalname 3;Event1 
Signalname 4;Event2

That means that signalname 1 and signalname 3 belong to event 1 and signalname 2 and signalname 4 belong to event2.

and I have another file (lets name it Events File) where all the event names are listed, I read all event names from that file and then iterate throught the config file in order to sort the signals to the event they belong to. So the goal is to create an array from the signal names and assign them to the event they belong to in the following form for example:
Event1: [Signalname 1,Signalname 3]

It is important that I could parse this file later when I need it in another application by looking for event name and getting the array of signal names assigned to it.

0 Kudos
Message 6 of 10
(1,579 Views)

Just experimented with Maps a bit, it's a new concept to me. How do one usually go about logging map outputs?

0 Kudos
Message 7 of 10
(1,574 Views)

See if this helps.  The idea is to read the signals file by lines (an option for the Read Text File) and parse each line in a FOR loop.  That loop can build up the map by adding to each event the signal.  You can then use that map however you want.  For the reverse, you can use a FOR loop directly on the map and build up a line of the Events file and write it.

 

NOTE: This code is example only and by no means complete or even debugged.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 10
(1,565 Views)
Solution
Accepted by AmrLV

Another thread got me thinking about this issue a little more.  This may be a good place to use a "Registration Map", which uses a set as the data.  Using a set will sort the signal names and prevent duplicates.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 9 of 10
(1,557 Views)

@crossrulz wrote:

Another thread got me thinking about this issue a little more.  This may be a good place to use a "Registration Map", which uses a set as the data.  Using a set will sort the signal names and prevent duplicates.


Thank you for the crash-course on maps!

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 10 of 10
(1,544 Views)