Quantcast
Channel: All LabVIEW posts
Viewing all articles
Browse latest Browse all 204074

Re: Find if string contains valid float

$
0
0

I have two suggestions.

  1. Most VISA devices sending Ascii Strings send a Termination Character (typically \n, as in \r\n) at the end of the string.  I recommend initializing your VISA with Enable Termination Character set to True, and the appropriate (default = \n) character wired in.  Then do a VISA Read with, say, 1024 characters -- if your device is sending a string of 38 (terminated by \n), the read will stop when the \n is received.
  2. I like to process String data using Scan from String.  In your case, you expect data in the form $%f;%f? (and maybe other things).  If you use this as the format specification, the one Scan from String function will parse your string, return two Dbls that you can call Voltage and Current, and will return with the Error Line "clear" unless the String did not conform to the format.  This one function replaces a half-dozen functions in your code and immediately gives you the Dbl values for your graph.
  3. [OK, so I have three points to make ...]  You should also take a look at the inverse of Scan from String, namely Format Into String, (in my opinion) does a better, clearer job of combining multiple pieces of data into a String for writing, say, to a CSV file than Concatenate.  If you want the TimeStamp as two strings, you'll need to use the functions (as you have) from the Time Palette, but then you could input the Date String, Time String, Voltage (Dbl), and Current (Dbl) using a format of %s,%s,%f,%f.  Finally, if you save all of your strings in a 1D array, you don't need the \r\n separator at the end.  Finally, to get your header "on top", just add it to the front of the array of data strings using Build Array.

Bob Schor


Viewing all articles
Browse latest Browse all 204074


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>