04-23-2017 09:48 AM - edited 04-23-2017 10:00 AM
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.
04-26-2017 01:23 AM
Any help will be appreciated.
05-01-2017 07:46 AM
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