.net - Opened SerialPort crashes C# application -
computers have connected to the measuring device via a physical COM1 simple as I have, where I opened serial port , Tell the device that I am alive and occasionally sends device data. (Every few minutes)
thread_readThread = new thread (read); SerialPort _serialPort = New SerialPort ("COM1", 9600); _serialPort.Parity = Samata. One; _serialPort.DataBits = 8; _serialPort.StopBits = StopBits.One; _serialPort.Handshake = Handshake.None; _serialPort.DtrEnable = true; _serialPort.Open (); _readThread.Start (); _serialPort.Write ("#sleep"); reading function (which works):
read public void () {string message = _serialPort.ReadLine (); } App crashes (even during debugging) after approximately one minute. This object reports disjoint exposure (for the underlying stream?). The message indicates that sehahhandles were closed. Stack strace is below:
on Microsoft.Win32.UnsafeNativeMethods.GetOverlappedResult (SafeFileHandle hFile, NativeOverlapped lpOverlapped, Int32 & amp; lpNumberOfBytesTransferred, Boolean bWait) System.IO.Ports.SerialStream On. EventLoopRunner.WaitForCommEvent () * on System.Threading.ThreadHelper.ThreadStart_Context (object state) System.Threading.ThreadHelper.ThreadStart System.Threading.ExecutionContext.Run on () (ExecutionContext executionContext, ContextCallback callback, object state)
Any thoughts? The problem is widely described, but usually the device involved physically beeing separately from the PC.
.
Also, is there any chance that has been collected objects containing _serialPort dereferenced and garbage? If you are ever accessing _serialPort from any other thread, try creating a private variable in it (read).
Comments
Post a Comment