Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

NI-VISA - problem with getting data from the serial interface with C# and .NET1.1

Hallo,

I want to query (Session.query) the serial interface with NI-VISA (MessagebasedSession) and C# with .NET1.1.
I always get the same exception: "ASRL1::INSTR-Fehler: Length cannot be less than zero.\r\nParameter name: length"
although the query-function is called with the correct parameters: mbSession.Query(strCommand, mbSession.AvailableNumber)
with mbSession.AvailableNumber definitely >= 0!
Has anyone an idea for this problem?

Greetings KIJO
0 Kudos
Message 1 of 4
(3,894 Views)

Hello KIJO,
The problem you are encountering is a known bug in the NI-VISA .NET API. If the string you are trying to read has null characters embedded in it, you will encounter this exception. The problem has been fixed in VISA 3.3 (the latest version). I recommend upgrading to VISA 3.3. If you can not upgrade at this time, you can use the overload of Query that takes and returns a byte array rather than the overload that takes and returns a string, and use the .NET Encoding class to convert the resultant byte array to a string.

0 Kudos
Message 2 of 4
(3,893 Views)
Dear Glenn,

thank you for your reply.
Both proposals worked. Unfortunately with the upgrade to NI-VISA 3.3 the Visual Studio .Net application
starts up now with an error message from NI measurement studio.
So I think I have to upgrade this too.

Greetings
KIJO
0 Kudos
Message 3 of 4
(3,855 Views)
Dear Glenn,

sorry that I contact you once more, but although I "repaired" my Measurement Studio 7.0 Professional
installation the MS Visual Studio starts still up with an error after the former installation of NI-VISA 3.3.
I have enclosed you the error message.
May be you have still an idea how I can fix this bug.

Many thanks in advance
Josef Kitzbichler
0 Kudos
Message 4 of 4
(3,852 Views)