예제 #1
0
        /// <summary> Initializes this object. </summary>
        public void Initialize()
        {
            // _queueSpeed.Name = "Serial";
            // Find installed serial ports on hardware
            _currentSerialSettings.PortNameCollection = SerialPort.GetPortNames();

            // If serial ports are found, we select the first one
            if (_currentSerialSettings.PortNameCollection.Length > 0)
            {
                _currentSerialSettings.PortName = _currentSerialSettings.PortNameCollection[0];
            }

            // Create queue thread and wait for it to start

            _queueThread = new Thread(ProcessQueue)
            {
                Priority = ThreadPriority.Normal,
                Name     = "Serial"
            };
            ThreadRunState = ThreadRunStates.Start;
            _queueThread.Start();
            while (!_queueThread.IsAlive)
            {
                Thread.Sleep(50);
            }
        }
예제 #2
0
        /// <summary> Connects to a serial port defined through the current settings. </summary>
        /// <returns> true if it succeeds, false if it fails. </returns>
        public bool StartListening()
        {
            // Closing serial port if it is open

            if (IsOpen())
            {
                Close();
            }

            // Setting serial port settings
            _serialPort = new SerialPort(
                _currentSerialSettings.PortName,
                _currentSerialSettings.BaudRate,
                _currentSerialSettings.Parity,
                _currentSerialSettings.DataBits,
                _currentSerialSettings.StopBits)
            {
                DtrEnable = _currentSerialSettings.DtrEnable
            };


            // Subscribe to event and open serial port for data
            ThreadRunState = ThreadRunStates.Start;
            return(Open());
        }
        /// <summary> Initializes this object. </summary>
        public void Initialize()
        {
            // _queueSpeed.Name = "Bluetooth";

            _queueThread = new Thread(ProcessQueue)
            {
                Priority = ThreadPriority.Normal,
                Name     = "Bluetooth"
            };
            ThreadRunState = ThreadRunStates.Start;
            _queueThread.Start();
            while (!_queueThread.IsAlive)
            {
                Thread.Sleep(50);
            }
        }
        private void Poll(ThreadRunStates threadRunState)
        {
            var bytes = UpdateBuffer();

            if (threadRunState == ThreadRunStates.Start)
            {
                if (bytes > 0)
                {
                    // Send an event
                    if (NewDataReceived != null)
                    {
                        NewDataReceived(this, null);
                    }
                    // Signal so that processes waiting on this continue
                }
            }
        }
예제 #5
0
        private void Poll(ThreadRunStates threadRunState)
        {
            var bytes = BytesInBuffer();

            _queueSpeed.SetCount(bytes);
            _queueSpeed.CalcSleepTimeWithoutLoad();
            _queueSpeed.Sleep();
            if (threadRunState == ThreadRunStates.Start)
            {
                if (bytes > 0)
                {
                    if (NewDataReceived != null)
                    {
                        NewDataReceived(this, null);
                    }
                }
            }
        }
예제 #6
0
 /// <summary> Stops listening to the serial port. </summary>
 /// <returns> true if it succeeds, false if it fails. </returns>
 public bool StopListening()
 {
     ThreadRunState = ThreadRunStates.Stop;
     var state = Close();
     return state;
 }
예제 #7
0
        /// <summary> Connects to a serial port defined through the current settings. </summary>
        /// <returns> true if it succeeds, false if it fails. </returns>
        public bool StartListening()
        {
            // Closing serial port if it is open

            if (IsOpen()) Close();

            // Setting serial port settings
            _serialPort = new SerialPort(
                _currentSerialSettings.PortName,
                _currentSerialSettings.BaudRate,
                _currentSerialSettings.Parity,
                _currentSerialSettings.DataBits,
                _currentSerialSettings.StopBits)
                {
                    DtrEnable = _currentSerialSettings.DtrEnable
                };

            // Subscribe to event and open serial port for data
            ThreadRunState = ThreadRunStates.Start;
            return Open();
        }
예제 #8
0
        /// <summary> Kills this object. </summary>
        public void Kill()
        {
            // Signal thread to stop
            ThreadRunState = ThreadRunStates.Stop;

            //Wait for thread to die
            Join(500);
            if (_queueThread.IsAlive) _queueThread.Abort();

            // Releasing serial port
            if (IsOpen()) Close();
            if (_serialPort != null)
            {
                _serialPort.Dispose();
                _serialPort = null;
            }
        }
예제 #9
0
        /// <summary> Initializes this object. </summary>
        public void Initialize()
        {
            // _queueSpeed.Name = "Serial";
            // Find installed serial ports on hardware
            _currentSerialSettings.PortNameCollection = SerialPort.GetPortNames();

            // If serial ports are found, we select the first one
            if (_currentSerialSettings.PortNameCollection.Length > 0)
                _currentSerialSettings.PortName = _currentSerialSettings.PortNameCollection[0];

            // Create queue thread and wait for it to start

            _queueThread = new Thread(ProcessQueue)
                {
                    Priority = ThreadPriority.Normal,
                    Name = "Serial"
                };
            ThreadRunState = ThreadRunStates.Start;
            _queueThread.Start();
            while (!_queueThread.IsAlive) { Thread.Sleep(50); }
        }
예제 #10
0
 /// <summary> Stops listening to the serial port. </summary>
 /// <returns> true if it succeeds, false if it fails. </returns>
 public bool StopListening()
 {
     ThreadRunState = ThreadRunStates.Start;
     //_pollBuffer.StopAndWait();
     return(Close());
 }
예제 #11
0
 /// <summary> Stops listening to the serial port. </summary>
 /// <returns> true if it succeeds, false if it fails. </returns>
 public bool StopListening()
 {
     ThreadRunState = ThreadRunStates.Start;
     //_pollBuffer.StopAndWait();
     return Close();
 }
예제 #12
0
 /// <summary> Stops listening to the serial port. </summary>
 /// <returns> true if it succeeds, false if it fails. </returns>
 public bool StopListening()
 {
     ThreadRunState = ThreadRunStates.Start;
     return(Close());
 }
예제 #13
0
 /// <summary> Stops listening to the serial port. </summary>
 /// <returns> true if it succeeds, false if it fails. </returns>
 public bool StopListening()
 {
     ThreadRunState = ThreadRunStates.Start;
     return Close();
 }
예제 #14
0
 /// <summary> Kills this object. </summary>
 public void Kill()
 {
     ThreadRunState = ThreadRunStates.Stop;
     //Wait for thread to die
     Join(500);
     if (QueueThread.IsAlive) QueueThread.Abort();
 }