Note that there are some explanatory texts on larger screens.

plurals
  1. POOpened SerialPort crashes C# application
    primarykey
    data
    text
    <p>The computer is connected to measuring device via a physical COM1. I have simple form where I open a serial port, tell the device that I'm alive and occasionally the device sends data. (every some minutes)</p> <pre><code>Thread _readThread = new Thread(Read); SerialPort _serialPort = new SerialPort("COM1", 9600); _serialPort.Parity = Parity.None; _serialPort.DataBits = 8; _serialPort.StopBits = StopBits.One; _serialPort.Handshake = Handshake.None; _serialPort.DtrEnable = true; _serialPort.Open(); _readThread.Start(); _serialPort.Write("#listening"); </code></pre> <p>The read function (which works):</p> <pre><code>public void Read() { string message = _serialPort.ReadLine(); } </code></pre> <p>After approximately one minute the application crashes (even while debugging). It reports an ObjectDisposedException (for the underlying stream?). The message tells that the SafeHandle was closed. Stack strace is below:</p> <p><em>at Microsoft.Win32.UnsafeNativeMethods.GetOverlappedResult(SafeFileHandle hFile, NativeOverlapped</em> lpOverlapped, Int32&amp; lpNumberOfBytesTransferred, Boolean bWait) at System.IO.Ports.SerialStream.EventLoopRunner.WaitForCommEvent() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()*</p> <p>Any ideas? The problem is reported widely but usually involve the device beeing physically detached from the PC.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload