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.
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.
12-27-2021 06:26 AM
Hello,
As part of an instrument control VI, I'd like to convert serial messages from the instrument to plain text. Most of them are currently 3-letter abbreviations and I'm trying to make it so the operator (not me) doesn't need to memorise/look up these messages.
I found an example somewhere and have working code (see attached screenshot) but it's starting to get a little ugly with only a small fraction of the messages done.
I have a feeling there's a neater way, I just don't know what it is, a steer would be appreciated!
Solved! Go to Solution.
12-27-2021 12:29 PM - edited 12-27-2021 01:38 PM
Unfortunately you are only showing a truncated picture. We cannot really debug a picture and prefer the actual VI.
Personally, I would use a map with the abbreviation as key and the full text as value. Now simply iterate over all words and substitute the value for all keys that are part of the map.
Your code overall seems highly flawed.
12-27-2021 01:41 PM
Thanks - I'll have a go with the map.
The rest of the code is just as much of a mess with some things half-implemented/half-baked and so on - I wouldn't wish it on anyone 😂
Thank you for the additional feedback though - it's early days so I'll keep chipping away at it and come back to the forums if I get stuck.
12-28-2021 07:39 AM
You could also have a 1D array of cluster where each cluster has two elements (source text and replacement text) or it could be a 2D string array where each row has two elements. You could even load this list from a file (like a CSV file, or tab separated, if you have commas in your text) and then edit it in something like Excel, which might make it easier to edit and add items.
If you intend to have things like line feeds in your text, as you show in the example, then you would need to escape them if you intend to save this in a file.
12-28-2021 12:54 PM
I like the idea of using an array as it means I don't need all the individual strings. I've not been able to crack it though I'm afraid - I can't work out how to search and replace from a 2D array.
I've attached the VI this time - if you have the time to show me how to do it, that would be great (sorry if it's obvious, I've just been staring at it too long now). Feel free to tear into the rest of it but please bear in mind that this isn't my trade and I'm just learning!
As a bit of background: this is a water sampling instrument that is automatic once set (i.e. there is no continuous acquisition). This is how I've been able to get away with the mad string processing - there are only a few lines involved in the setup. When I come to try and download the data off the instrument it's going to die though 😂The idea is that the VI primarily serves as a user-friendly replacement for Putty and the instruction manual.
Thanks in advance for any help!
12-28-2021 01:28 PM
Well, that VI requires quite a bit of remodeling. 😄
12-29-2021 12:30 AM
@gf34 wrote:
I can't work out how to search and replace from a 2D array.
I haven't looked at your current VI (I'm sure Altenbach's list is enough for you to chew on), but the 2D array part or 1D cluster array is easy. In fact, you already have it in your original screenshot, but there it's split into two 1D arrays. If you make it one of the suggested options you can simply iterate over the rows in the same way you did and take the relevant info out of each row inside the for loop (using either an index array or an unbundle).
12-30-2021 08:34 AM
Hello, Mk2 attached!
I got rid of the Bytes at Port but now I get a timeout error whenever there is no data (of course I don't see it until I exit the VI though) - how would I stop that from popping up each time please? It also slows down the exit by a couple of seconds.
I've attached examples of the messages from the instrument (startup, info header, acknowledgment).
Hopefully things have improved anyway...the biggest thing remaining is implementing the data download.
Thanks again
12-30-2021 08:55 AM - edited 12-30-2021 08:56 AM
Hi gf,
@gf34 wrote:
I got rid of the Bytes at Port but now I get a timeout error whenever there is no data (of course I don't see it until I exit the VI though) - how would I stop that from popping up each time please?
As soon as you implement some error handling in your VI you will discover that error instantly - and not "until you exit the VI"!
@gf34 wrote:
Hopefully things have improved anyway...the biggest thing remaining is implementing the data download.
Well, several problems/issues: