private void ReadThread() { byte[] oneByte = new byte[1]; while (true) { try { int count = _stream.Read(oneByte); if (count == 1) { this.DataReceived(this, oneByte); } else if (count == -1) { throw new Exception("need to restart the port"); } } catch { _port.Deactivate(); Thread.Sleep(300); _port = new Cdc(); Controller.ActiveDevice = _port; _stream = _port.Stream; } } }
private void ReadThread() { byte[] oneByte = new byte[1]; while (true) { try { int count = _stream.Read(oneByte); if (count == 1) this.DataReceived(this, oneByte); else if (count == -1) throw new Exception("need to restart the port"); } catch { _port.Deactivate(); Thread.Sleep(300); _port = new Cdc(); Controller.ActiveDevice = _port; _stream = _port.Stream; } } }
public UsbCommunicationChannel(Cdc port) { _port = port; _stream = _port.Stream; new Thread(ReadThread).Start(); }