Ejemplo n.º 1
0
        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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 protected override void Dispose(bool disposing)
 {
     if (disposing && this.IsOpen)
     {
         this.internalSerialStream.Flush();
         this.internalSerialStream.Close();
         this.internalSerialStream = null;
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        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);
                    }
                }
            }
        }
 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);
 }
 protected override void Dispose(bool disposing)
 {
     if (disposing && this.IsOpen)
     {
         this.internalSerialStream.Flush();
         this.internalSerialStream.Close();
         this.internalSerialStream = null;
     }
     base.Dispose(disposing);
 }
            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            
            }
Ejemplo n.º 9
0
 public void Close()
 {
     if (_BaseStream != null)
     {
         _BaseStream.Close();
         _BaseStream = null;
     }
 }
Ejemplo n.º 10
0
 public void Open(FileAccess access, FileShare sharing)
 {
     _BaseStream = new SerialStream(_Port, _BaudRate, access, sharing);
 }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
 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;
 }