I'm trying to read four displacement gages with Labview (2013) every 6 seconds. They are connected to my computer via USB, but acting like serial ports.
However, I get strange results in Labview. If I start by reading the gages with a software like Hyperterminal or Termite, I get the last value read in this software in Labview for each reading, even if the displacement gage value changes. If I don't use another program before, I don't read anything in Labview.
At first I thought the buffer had to be flushed, but I tried many different combinations with VISA Clear or VISA Flush Buffer, nothing worked, and I'm running out of ideas to fix this issue.
I have attached a copy of my block diagram. The part outside the sequence structure with the VISA instructions has been copied on an identical setup but with a different communication protocol and should thus work correctly.
Thanks in advance for your suggestions
I know its more or less the same, but you should try to start from the shipped example "Simple Serial" which can be found by going to the example finer Help >> Find Examples and search for it. That VI is as simple as it gets, open, wait, read, close. If that doesn't work you have other issues, but it should just work like any normal hyperterminal like program.
Also in the future instead of posting pictures of your code, post the actual code, or snippets which are images with the code embedded in the picture.
First major issue I see is that you are constantly opening and closing the serial port. This is BAD. Open the serial port at the start of the program and do not close it until the cleanup as part of the programming shutting down.
Second potential issue is your long wait between the write and the read. Does the instrument use a termination character? You currently have VISA set up to use one (the Line Feed to be more exact). If the instrument does use the termination character, then tell the VISA Read to read more bytes than you ever expect in a message. You may already be doing this. But that Wait is not needed. Just increase the timeout to something like 2 seconds. This will allow the data to be returned as soon as it comes in instead of being limited by the wait.
Other general programming style issues:
1. I see no point for either sequence structure (after the wait mentioned above is removed). Just remove them. They are just creating more noise.
2. Abuse of local variables. You should look into using Shift Registers to hold data for you instead of local variables (yes, they are very poorly named).