Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VB .NET reports "Length cannot be less than zero"

... when calling Device.ReadString()
0 Kudos
Message 1 of 3
(3,063 Views)
Have you tried running the shipping example that installs with the VISA support called SimpleReadWrite. It should be installed on your computer at
C:\Program Files\National Instruments\MeasurementStudio70\DotNET\Examples\Visa\SimpleReadWrite.

I just ran it and it works fine. Even if you try to perform a ReadString() with nothing attached it should just return a time out error.

JoshuaP
National Instruments
0 Kudos
Message 2 of 3
(3,063 Views)
I discovered the problem. I was reading the results from ReadString() into a string buffer. The values being returned by the device were binary, and there was a binary 0 within the string, which caused everyting to blow up. The problem is that the .NET framework handles strings differently than it did in VB6, where a binary 0 within a string wasn't a problem. I changed to reading the results of ReadString() into a byte array and everything works fine now. I guess .NET reads a binary 0 literally (nul), which wreaks havoc.

Lesson learned. Another step up the .NET learning curve.
0 Kudos
Message 3 of 3
(3,063 Views)