From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem for VISA async read/write for serial port

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.

0 Kudos
Message 1 of 3
(3,237 Views)

Any help will be appreciated. 

0 Kudos
Message 2 of 3
(3,134 Views)

Hi aneek231,

 

Here is a link that might be relevant for your case:

 

http://digital.ni.com/public.nsf/allkb/6E1922B526572CB8862571AA00544057?OpenDocument

 

It might be the case, that your device do not fully comply with the serial specs and therefore do not support some VISA functions. Can you try with another simpler example where asynchronous I/O is not used?

 

Cheers,
Bart

0 Kudos
Message 3 of 3
(3,101 Views)