Hello dear members,
My code assigns a frequency to a serial instrument(an LCR meter), and reads the corresponding capacitance-resistance values. It is a frequency sweep program, so it does the same task for all the frequency values in the predetermined interval. It is working nicely, except one thing. The first values for resistance and capacitance are zero somehow. If i change the location of wait_ms in the sequential logic, then the first values become the last values of the previous run of the program. I know that I assign them as zero as the initial value of the shift register, yet I have used a very similar code for getting data from a DAQ and it was working perfectly there. The program is in the attachment, I do not know what is the issue here, if you could help it is much appreciated.
The first values for resistance and capacitance are zero somehow.
Because you are using BytesAtPort!
Get rid of that property node and wire a constant value, larger than the largest message you expect!
(You are sending a command and try to read the BytesAtPort immediatly - even before your device has a chance to process the command and send the answer. Instead there are zero bytes in the buffer and VISARead starts to read zero bytes…)
Don't use so many local variables.
Don't use InsertIntoArray when you could use BuildArray!
Don't use BuildArray when you could use autoindexing at loop borders!
Don't use sequence structures when you can use wires to enforce DATAFLOW!
I recommend to use FormatIntoString instead of ConvertFloatToString, followed by a larger ConcatString function…
After some modifications:
Thank you very much for the advice. Now what happens is that, the initial values becomes the last value of the previous run.
then you need to initialize your device in a more robust way.
As you clear the buffer it seems the device is sending the last measurement value upon your request (which doesn't make a lot of sense to me)…
Without BytesAtPort, I always get that hexadecimal error at visa read. If I attach a constant such as 99, the code doesn't run. I've implemented all the modifications you have made, still the same. The code is much more compact and computationally effective though
what is a "hexadecimal error"?
Please use VISASerialPortInit and choose the correct TermChar (as described in your device manual). Then VISARead should work as expected...