private void CatchReceivedEvents(object src, SerialDataReceivedEventArgs e) { SerialDataReceivedEventHandler dataReceived = this.DataReceived; SerialStream internalSerialStream = this.internalSerialStream; if ((dataReceived != null) && (internalSerialStream != null)) { lock (internalSerialStream) { bool flag = false; try { flag = internalSerialStream.IsOpen && ((SerialData.Eof == e.EventType) || (this.BytesToRead >= this.receivedBytesThreshold)); } catch { } finally { if (flag) { dataReceived(this, e); } } } } }
protected override void Dispose(bool disposing) { if (disposing && this.IsOpen) { this.internalSerialStream.Flush(); this.internalSerialStream.Close(); this.internalSerialStream = null; } base.Dispose(disposing); }
public void Open() { if (this.IsOpen) { throw new InvalidOperationException(SR.GetString("Port_already_open")); } new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); this.internalSerialStream = new SerialStream(this.portName, this.baudRate, this.parity, this.dataBits, this.stopBits, this.readTimeout, this.writeTimeout, this.handshake, this.dtrEnable, this.rtsEnable, this.discardNull, this.parityReplace); this.internalSerialStream.SetBufferSizes(this.readBufferSize, this.writeBufferSize); this.internalSerialStream.ErrorReceived += new SerialErrorReceivedEventHandler(this.CatchErrorEvents); this.internalSerialStream.PinChanged += new SerialPinChangedEventHandler(this.CatchPinChangedEvents); this.internalSerialStream.DataReceived += new SerialDataReceivedEventHandler(this.CatchReceivedEvents); }
private void CatchPinChangedEvents(object src, SerialPinChangedEventArgs e) { SerialPinChangedEventHandler pinChanged = this.PinChanged; SerialStream internalSerialStream = this.internalSerialStream; if ((pinChanged != null) && (internalSerialStream != null)) { lock (internalSerialStream) { if (internalSerialStream.IsOpen) { pinChanged(this, e); } } } }
private void CatchErrorEvents(object src, SerialErrorReceivedEventArgs e) { SerialErrorReceivedEventHandler errorReceived = this.ErrorReceived; SerialStream internalSerialStream = this.internalSerialStream; if ((errorReceived != null) && (internalSerialStream != null)) { lock (internalSerialStream) { if (internalSerialStream.IsOpen) { errorReceived(this, e); } } } }
internal unsafe EventLoopRunner(SerialStream stream) { handle = stream._handle; streamWeakReference = new WeakReference(stream); callErrorEvents = new WaitCallback(CallErrorEvents); callReceiveEvents = new WaitCallback(CallReceiveEvents ); callPinEvents = new WaitCallback(CallPinEvents); freeNativeOverlappedCallback = new IOCompletionCallback(FreeNativeOverlappedCallback); isAsync = stream.isAsync; #if DEBUG portName = stream.portName; #endif }
public void Close() { if (_BaseStream != null) { _BaseStream.Close(); _BaseStream = null; } }
public void Open(FileAccess access, FileShare sharing) { _BaseStream = new SerialStream(_Port, _BaudRate, access, sharing); }
public void Open() { if (IsOpen) throw new InvalidOperationException(SR.GetString(SR.Port_already_open)); // Demand unmanaged code permission new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); internalSerialStream = new SerialStream(portName, baudRate, parity, dataBits, stopBits, readTimeout, writeTimeout, handshake, dtrEnable, rtsEnable, discardNull, parityReplace); internalSerialStream.SetBufferSizes(readBufferSize, writeBufferSize); internalSerialStream.ErrorReceived += new SerialErrorReceivedEventHandler(CatchErrorEvents); internalSerialStream.PinChanged += new SerialPinChangedEventHandler(CatchPinChangedEvents); internalSerialStream.DataReceived += new SerialDataReceivedEventHandler(CatchReceivedEvents); }
public Debug() { var cnf = new BaseSerialStream.Configuration("UART1"); _port = SerialPortsManager.Instance.Open(ref cnf); }
internal EventLoopRunner(SerialStream stream) { this.handle = stream._handle; this.streamWeakReference = new WeakReference(stream); this.callErrorEvents = new WaitCallback(this.CallErrorEvents); this.callReceiveEvents = new WaitCallback(this.CallReceiveEvents); this.callPinEvents = new WaitCallback(this.CallPinEvents); this.freeNativeOverlappedCallback = new IOCompletionCallback(this.FreeNativeOverlappedCallback); this.isAsync = stream.isAsync; }