Provides access to the RS232 UARTs (serial port) on the Raspberry Pi.
Inheritance: IDisposable
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.Serial.SerialCommandQueueProcessor"/>
		/// class with the serial port to queue commands for and the delay
		/// between processing of commands.
		/// </summary>
		/// <param name="serial">
		/// The serial port to queue commands for.
		/// </param>
		/// <param name="delay">
		/// The amount of time (in milliseconds) to delay between commands.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="serial"/> cannot be null.
		/// </exception>
		public SerialCommandQueueProcessor(Rs232SerialPort serial, Int32 delay) {
			if (serial == null) {
				throw new ArgumentNullException("serial");
			}
			this._queue = new Queue<String>();
			this._serial = serial;
			this._delay = delay;
		}
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.Serial.SerialCommandQueueProcessor"/>
 /// class with the serial port to queue commands for and the delay
 /// between processing of commands.
 /// </summary>
 /// <param name="serial">
 /// The serial port to queue commands for.
 /// </param>
 /// <param name="delay">
 /// The amount of time (in milliseconds) to delay between commands.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="serial"/> cannot be null.
 /// </exception>
 public SerialCommandQueueProcessor(Rs232SerialPort serial, Int32 delay)
 {
     if (serial == null)
     {
         throw new ArgumentNullException("serial");
     }
     this._queue  = new Queue <String>();
     this._serial = serial;
     this._delay  = delay;
 }
Example #3
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        /// <remarks>Call <see cref="Dispose"/> when you are finished using the
        /// <see cref="CyrusBuilt.MonoPi.IO.Serial.SerialCommandQueueProcessor"/>. The <see cref="Dispose"/> method leaves the
        /// <see cref="CyrusBuilt.MonoPi.IO.Serial.SerialCommandQueueProcessor"/> in an unusable state. After calling
        /// <see cref="Dispose"/>, you must release all references to the
        /// <see cref="CyrusBuilt.MonoPi.IO.Serial.SerialCommandQueueProcessor"/> so the garbage collector can reclaim the
        /// memory that the <see cref="CyrusBuilt.MonoPi.IO.Serial.SerialCommandQueueProcessor"/> was occupying.</remarks>
        public void Dispose()
        {
            if (this._isDisposed)
            {
                return;
            }

            if (!this._exiting)
            {
                lock (_padLock) {
                    this._exiting = true;
                }
            }

            if (this._queue != null)
            {
                this._queue.Clear();
            }

            if (this._processor != null)
            {
                try {
                    if (this._processor.IsAlive)
                    {
                        this._processor.Abort();
                    }
                }
                catch (ThreadAbortException) {
                    Thread.ResetAbort();
                }
            }

            if (this._serial != null)
            {
                this._serial.Dispose();
                this._serial = null;
            }

            this._processor  = null;
            this._queue      = null;
            this._isDisposed = true;
        }
		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="CyrusBuilt.MonoPi.Devices.CrystalFontzSerialLCD.CrystalFontz63xSerial"/>
		/// class. This is the default constructor.
		/// </summary>
		public CrystalFontz63xSerial() {
			this._lcd = new Rs232SerialPort(this._baud);
		}
		/// <summary>
		/// Releases all resource used by the
		/// <see cref="CyrusBuilt.MonoPi.Devices.CrystalFontzSerialLCD.CrystalFontz63xSerial"/> object.
		/// </summary>
		/// <param name="disposing">
		/// If set to <c>true</c> disposing.
		/// </param>
		private void Dispose(Boolean disposing) {
			if (this._isDisposed) {
				return;
			}

			if (disposing) {
				if (this._lcd != null) {
					this._lcd.Dispose();
					this._lcd = null;
				}

				if (this._backlightPin != null) {
					this._backlightPin.Dispose();
					this._backlightPin = null;
				}
			}

			this._isDisposed = true;
		}
		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="CyrusBuilt.MonoPi.Devices.CrystalFontzSerialLCD.CrystalFontz63xSerial"/>
		/// class with the GPIO pin to control the backlight with
		/// and the BAUD rate to negotiate with the display.
		/// </summary>
		/// <param name="backlightPin">
		/// The GPIO pin to use to control the backlight.
		/// </param>
		/// <param name="baud">
		/// The BAUD rate.
		/// </param>
		/// <exception cref="ArgumentOutOfRangeException">
		/// BAUD rate cannot be less than 2400 or greater than 19200.
		/// </exception>
		public CrystalFontz63xSerial(IRaspiGpio backlightPin, BaudRates baud) {
			this._baud = baud;
			if ((Int32)baud < 2400) {
				throw new ArgumentOutOfRangeException("baud", "Cannot be less than 2400 baud.");
			}

			if ((Int32)baud > 19200) {
				throw new ArgumentOutOfRangeException("baud", "Cannot be greater than 19200 baud.");
			}
			this._lcd = new Rs232SerialPort(baud);
			this._backlightPin = backlightPin;
		}
		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="CyrusBuilt.MonoPi.Devices.CrystalFontzSerialLCD.CrystalFontz63xSerial"/>
		/// class with a GPIO pin to use to control the backlight.
		/// </summary>
		/// <param name="backlightPin">
		/// The GPIO pin to use to control the backlight.
		/// </param>
		public CrystalFontz63xSerial(IRaspiGpio backlightPin) {
			this._lcd = new Rs232SerialPort(this._baud);
			this._backlightPin = backlightPin;
		}
		/// <summary>
		/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
		/// </summary>
		/// <filterpriority>2</filterpriority>
		/// <remarks>Call <see cref="Dispose"/> when you are finished using the
		/// <see cref="CyrusBuilt.MonoPi.IO.Serial.SerialCommandQueueProcessor"/>. The <see cref="Dispose"/> method leaves the
		/// <see cref="CyrusBuilt.MonoPi.IO.Serial.SerialCommandQueueProcessor"/> in an unusable state. After calling
		/// <see cref="Dispose"/>, you must release all references to the
		/// <see cref="CyrusBuilt.MonoPi.IO.Serial.SerialCommandQueueProcessor"/> so the garbage collector can reclaim the
		/// memory that the <see cref="CyrusBuilt.MonoPi.IO.Serial.SerialCommandQueueProcessor"/> was occupying.</remarks>
		public void Dispose() {
			if (this._isDisposed) {
				return;
			}

			if (!this._exiting) {
				lock (_padLock) {
					this._exiting = true;
				}
			}

			if (this._queue != null) {
				this._queue.Clear();
			}

			if (this._processor != null) {
				try {
					if (this._processor.IsAlive) {
						this._processor.Abort();
					}
				}
				catch (ThreadAbortException) {
					Thread.ResetAbort();
				}
			}

			if (this._serial != null) {
				this._serial.Dispose();
				this._serial = null;
			}

			this._processor = null;
			this._queue = null;
			this._isDisposed = true;
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.Serial.SerialCommandQueueProcessor"/>
		/// class with the serial port to queue commands for. This overload
		/// uses the default delay value.
		/// </summary>
		/// <param name="serial">
		/// The serial port to queue commands for.
		/// </param>
		public SerialCommandQueueProcessor(Rs232SerialPort serial)
			: this(serial, DEFAULT_DELAY) {
		}
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.Serial.SerialCommandQueueProcessor"/>
 /// class with the serial port to queue commands for. This overload
 /// uses the default delay value.
 /// </summary>
 /// <param name="serial">
 /// The serial port to queue commands for.
 /// </param>
 public SerialCommandQueueProcessor(Rs232SerialPort serial)
     : this(serial, DEFAULT_DELAY)
 {
 }