i trying create terminal hyperterminal talk gsm modem (open @ sierra wireless sl8080). modem can reset randomly or command being sent comm port. when modem resets communication lost. using
private void serialport1_datareceived(object sender,system.io.ports.serialdatareceivedeventargs e) { console.writeline(serialport1.readexisting()); }
to read device. after reset can , nothing back.
if try , read after reset get:
a first chance exception of type 'system.invalidoperationexception' occurred in system.dll unhandled exception of type 'system.invalidoperationexception' occurred in system.dll additional information: port closed.
if reset, close port get:
a first chance exception of type 'system.io.ioexception' occurred in system.dll unhandled exception of type 'system.io.ioexception' occurred in system.dll additional information: requested resource in use.
i cannot recover state out closing application totally. have been trying solve problem on year. have come lots of other solutions. using python , java/rxtx handle resets device flawlessly. stumped here more of personal challenge figure out now.
i tried using wmi detect unplugs of usb devices , close commport still same result.
have tried disposing serialport object instead of closing it?
http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.errorreceived.aspx
if serialport object becomes blocked during read operation, not abort thread. instead, either close base stream or dispose of serialport object.