Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

System.ArgumentOutOfRangeException: Length cannot be less than zero by excuting Board.Readstring(Address address, Int32 count, Int32 terminationByte) if count = 20000.

Gpib communication with HP Infinium scope.
Trying to retrieve the learnstring.
First a command is sent to the scope -> “*LRN?”
Now, the learnstring can be read, this string is approximately 14000 bytes long.

strReading = m_board.ReadString(address, strReading.Length, intTerminationByte);

address = {PrimaryAddress=7, SecundaryAddress=0}
strReading.Length = 20000
intTerminationByte = 256

After executing the m_board.ReadString function, a System.ArgumentOutOfRangeException is raised.

Screenshots are added in a attachment
0 Kudos
Message 1 of 2
(6,045 Views)
Hi,

This exact same question has already been posted by another customer. This was the problem:

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

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.

Regards.

JV
0 Kudos
Message 2 of 2
(6,033 Views)