03-31-2014 12:59 PM - edited 03-31-2014 01:15 PM
Hello everyone. I am currently programming a vi that takes an input string from a serial device and parses that string. The only issue I am having is that, (presumably) in between reads, when the buffer empties, the vi will parse this empty buffer and return an error message because the now empty string doesn't conform to the standard string that is expected. How do I go about fixing this, assuming I have interpretted the source of the error correctly?
Edit: I wanted to add that searching turned up advice that suggested setting the Visa read control to synchronous. This doesn't seem to have made a difference.
Edit 2: Attached the vi as well. Here's what's going on. The device being read is an infrared thermometer that has an operational range of 550-3000C. When the temperature is below 550, the output is "HCC -U-". This output is terminated by a carriage return and line feed. When the tempartue is above 550, the output is "HUCxxxx" where the x's represent the digits. This string is read and the parsed. If the HCC is found, it then searches for " -U-". If found, this is displayed. Otherwise "ERROR" is displayed. In the event that HUC is found, the 4 characters after it are displayed and graphed.
To observe what is happening, I have a text box to show the contents of the read buffer and then another to display the parsed string. There is a final text box (output string 2) that shows the temperature should a numerical value register. I have also thrown in a led that lights up when the string parses properly and turns off in the event that "ERROR" is displayed.
Here is what is happening: when the temperature is below 550, I first see HCC -U- in the read buffer display, -U- in the parsed display and my led lights up. Then, presumably the buffer is emptied because I see the display empty, the parsed display now shows ERROR and the led goes off.
Solved! Go to Solution.
03-31-2014 01:00 PM
What do you have so far?
03-31-2014 01:06 PM
Attached the vi to my original post now; should've done that sooner!
03-31-2014 01:13 PM
You really should post your code, but it sounds like you are constantly reading from the serial port and parsing regardless of the data or no data.
You should enable termination character in the serial port setup, and set the term char to equal the termination of your data string.
Then read until the term char is encountered or a time out.
If timeout = true then do not parse
03-31-2014 01:18 PM - edited 03-31-2014 01:19 PM
So the pyrometer has a polling rate of 600ms. To make up for this, I've set a 500ms delay between opening the serial port and reading it (much like in the serial read/write example. I've also set the timeout to 500ms. Should I do this differently?
Alternatively, how do I determine if a timeout has occured?
03-31-2014 01:24 PM
Try something like this.
03-31-2014 01:30 PM
Set the VISA read bytes to a much higher amount than you expect to read
Set the timeout to somewhat longer than it should take to get a 'good' read
03-31-2014 02:32 PM
The error code filtering along with the larger bits at port and timeout setings seems to have fixed this at first glance! I'm going to do some more testing and will post back soon.
03-31-2014 02:37 PM
Good to hear you are on your way.
You might want to also think about eventually adding some other error detection for cases where you do not get good data or only partial data.
03-31-2014 03:57 PM
Read in some number of bytes into a shift register.
Look for the preamble in the shift register.
If there's a "length" of the message that comes back, that makes it even easier. Read that number of bytes out of the port, and there's your message.
Or search for the next preamble and pluck out one message from the other.
Either way, shift registers are your friends here.
If returned string is null, don't put anything into the SR.