[IronPython] Serial Port Commn: unhandled ObjectDisposedException though exception handler provided
Michael Foord
fuzzyman at voidspace.org.uk
Wed Nov 19 16:19:38 CET 2008
Well... I know nothing about these APIs and am guessing, but the
traceback is in an AsyncCallback happening on another thread - so an
exception handler in this thread isn't going to catch it.
Why do you close the port before opening it?
ReadTo doesn't look like an Async API [1]. You snipped the top line of
the traceback which includes any mention of the line number where it was
raised. Have you put a print in to confirm that your exception handling
block is never entered?
Michael
http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.readto.aspx
Sheetal.Pawar at lntinfotech.com wrote:
>
>
> Hi,
>
> I am writing a serial port communication application using Iron
> Python. Following is a sample code:
>
> try:
>
> BaudRate = 9600
> DataBits = 8
>
> #create a serial port instance for the desired port as specified
> serialPort = System.IO.Ports.SerialPort( "COM1")
>
> serialPort.BaudRate = BaudRate
>
> serialPort.DataBits = DataBits
>
> #open the port
> serialPort.Close()
> serialPort.Open()
>
> serialPort.ReadTimeout = 30000
>
> returnValue = serialPort.ReadTo( "xx" )
> except:
> print "error"
> returnValue = ""
>
> serialPort.Close()
> serialPort.Dispose()
>
>
>
> Here if i abort my application using Cntrl + C on the iron python
> console, then i get ObjectDisposedException unhandled though i have
> provided an exception handler.
>
> I tried to abort the application while it was waiting for some data to
> be read and the timeout had not occured. The application exits and I
> get the exception after it exits.
>
> Stack Trace:
>
> at Microsoft.Win32.Win32Native.SetEvent(SafeWaitHandle handle)
> at System.Threading.EventWaitHandle.Set()
> at System.IO.Ports.SerialStream.AsyncFSCallback(UInt32 errorCode,
> UInt32 numBytes, NativeOverlapped* pOverlapped)
> at
> System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32
> errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
>
> Please let me know what can be the issue.
>
> Thanks & regards,
> Sheetal
>
>
>
>
>
>
> ______________________________________________________________________
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
--
http://www.ironpythoninaction.com/
More information about the Ironpython-users
mailing list