Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Exception from HRESULT: 0x80040015

Hello,

 

I am just writing a method with C# programming, it need send/read content via a RS485 port. It will be failed with the exception "Exception from HRESULT: 0x80040015". When I debug the method, I found that this exception is occured in Read. the big different in the method is the serial communication instance initial once, and use it send/read more time. then release it. this method will beused 3 times. and each send command about 256 characters, the receive conntent about 1000 characters, I am not sure if it is caused by buffer in PC. but I have use the serial.flush() to cleare the buffer...

 

the exception: 

System.Runtime.InteropServices.COMException (0x80040015): Exception from HRESULT: 0x80040015
at Ivi.Visa.Interop.IMessage.ReadString(Int32 count)

 

the method:

...

rm = new ResourceManager();
msg= (IMessage)rm.Open("ASRL3::INSTR", AccessMode.NO_LOCK, 0, "");

msg.TerminationCharacter = (byte)'$';
msg.TerminationCharacterEnabled = false;


ISerial  serial = (ISerial)msg;

//Configure baudrate of com. port
serial.BaudRate = 115200;
serial.DataBits = 8;
serial.Timeout = 2;
serial.SetBufferSize(Ivi.Visa.Interop.BufferMask.IO_IN_AND_OUT_BUFS, 65000);

 

msg.WriteString(string.Concat(initial_cmd, "\r"));
System.Threading.Thread.Sleep(500);
string initialresult = msg.ReadString(1024);

....

serial.Flush(Ivi.Visa.Interop.BufferMask.IO_IN_AND_OUT_BUFS, true);

 

msg.WriteString(string.Concat(cmd1, "\r"));
System.Threading.Thread.Sleep(500);
string initialresult = msg.ReadString(1024);

....

serial.Flush(Ivi.Visa.Interop.BufferMask.IO_IN_AND_OUT_BUFS, true);

 

msg.WriteString(string.Concat(cmd2, "\r"));
System.Threading.Thread.Sleep(500);
string initialresult = msg.ReadString(1024);

....

serial.Flush(Ivi.Visa.Interop.BufferMask.IO_IN_AND_OUT_BUFS, true);

 

....

System.Runtime.InteropServices.Marshal.FinalReleaseComObject(msg);

 

Thanks for your analysis in advance!

0 Kudos
Message 1 of 2
(7,919 Views)

I'm not 100% sure, but I think that's a timeout error. You said that the receive content is "about 1000 characters". What's the exact value of "about"? You seem to indicate in the code that it's 1024. Is it "about", or is it exactly 1024? Could it be 999? 1010? I ask because if it's not 1024 characters, then you will get a timeout error. You've turned off termination character, which means that VISA will not stop reading when it sees the "$" character. So, I'm not sure why you're setting the termination character and then disabling its use. If you do not use termination character, then VISA will expect to see 1024 characters. If there are less, you will get a timeout.

0 Kudos
Message 2 of 2
(7,912 Views)