Quantcast
Channel: Instrument Control (GPIB, Serial, VISA, IVI) topics
Viewing all articles
Browse latest Browse all 5565

Problem for VISA async read/write for serial port

$
0
0

Hi, I am trying to use the SimpleAsynchronousReadWrite examle for reading data asynchronously from a serial resource using "SerialSession" instead of "MessageBasedSession". I am able to read some data but after a while I get the following exception.

Managed Debugging Assistant 'CallbackOnCollectedDelegate' has detected a problem in 'C:\Users\Public\Documents\National Instruments\NI-VISA\Examples\.NET\SimpleAsynchronousReadWrite\bin\Debug\SimpleAsynchronousReadWrite.vshost.exe'.

Additional information: A callback was made on a garbage collected delegate of type 'NationalInstruments.Visa!NationalInstruments.Visa.Internal.VisaDllEventHandler::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.

I have attached the file "MainForm.cs" from the example code. I only modified mbsession to sSession for serial port. This error comes on line 329 i.e. 

asyncHandle = sSession.RawIO.BeginRead(
1024,
new VisaAsyncCallback(OnReadComplete),
null);

It seems to me some internal error from the library. May be I am doing something wrong
Can you please help me. I am using NI VISA verion 15.5 and visual studio 2015.


Viewing all articles
Browse latest Browse all 5565

Trending Articles