/// <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); } }
/// <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 } } }
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); } } } }
/// <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; }
/// <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> 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; } }
/// <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); } }
/// <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()); }
/// <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(); }
/// <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()); }
/// <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(); }
/// <summary> Kills this object. </summary> public void Kill() { ThreadRunState = ThreadRunStates.Stop; //Wait for thread to die Join(500); if (QueueThread.IsAlive) QueueThread.Abort(); }