07-11-2022 05:54 AM
Hi guys,
I would like to write a file in the following format:
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
Solved! Go to Solution.
07-11-2022 06:04 AM - edited 07-11-2022 06:06 AM
@AmrLV wrote:
Hi guys,
I would like to write a file in the following format:
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.
07-11-2022 06:26 AM
Thanks for your reply, Bill!
and how would I link the array to the event name like I showed in the Screenshot?
07-11-2022 06:56 AM
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…
07-11-2022 07:03 AM
@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.
07-11-2022 08:32 AM
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.
07-11-2022 08:35 AM
Just experimented with Maps a bit, it's a new concept to me. How do one usually go about logging map outputs?
07-11-2022 09:08 AM - edited 07-11-2022 09:09 AM
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.
07-11-2022 09:44 AM - edited 07-11-2022 09:45 AM
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.
07-11-2022 10:12 AM
@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!