Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SoftSerialPort"/> class.
        /// </summary>
        /// <param name="receivePin">The receive pin.</param>
        /// <param name="transmitPin">The transmit pin.</param>
        /// <param name="baudRate">The baud rate.</param>
        /// <param name="dataBits">The data bits.</param>
        /// <param name="invert">if set to <c>true</c> [invert].</param>
        internal SoftSerialPort(GpioPin receivePin, GpioPin transmitPin, UartRate baudRate, int dataBits, bool invert)
        {
            BoardException.ValidateResult(
                Serial.GpioSerialReadOpen((UserGpio)receivePin.PinNumber, Convert.ToUInt32(baudRate), Convert.ToUInt32(dataBits)));

            Handle   = (UserGpio)receivePin.PinNumber;
            DataBits = dataBits;
            BaudRate = (int)baudRate;

            if (invert)
            {
                Serial.GpioSerialReadInvert(Handle, true);
                Invert = true;
            }

            _transmitPin = transmitPin;
        }
 /// <summary>
 /// Opens a software (bit-banged) serial port.
 /// </summary>
 /// <param name="receivePin">The receive pin.</param>
 /// <param name="transmitPin">The transmit pin.</param>
 /// <param name="baudRate">The baud rate.</param>
 /// <returns>The software serial port</returns>
 public SoftSerialPort OpenSoftSerialPort(GpioPin receivePin, GpioPin transmitPin, UartRate baudRate) =>
 new SoftSerialPort(receivePin, transmitPin, baudRate, 8, false);
 /// <summary>
 /// Opens a software (bit-banged) serial port.
 /// </summary>
 /// <param name="receivePin">The receive pin.</param>
 /// <param name="transmitPin">The transmit pin.</param>
 /// <param name="baudRate">The baud rate.</param>
 /// <param name="dataBits">The data bits.</param>
 /// <param name="invert">if set to <c>true</c> [invert].</param>
 /// <returns>The software serial port</returns>
 public SoftSerialPort OpenSoftSerialPort(GpioPin receivePin, GpioPin transmitPin, UartRate baudRate, int dataBits, bool invert) =>
 new SoftSerialPort(receivePin, transmitPin, baudRate, dataBits, invert);
 /// <summary>
 /// Opens the specified UART port.
 /// </summary>
 /// <param name="portName">Name of the port.</param>
 /// <param name="baudRate">The baud rate.</param>
 /// <returns>The UART port object</returns>
 public UartPort OpenUartPort(string portName, UartRate baudRate) =>
 new UartPort(portName, baudRate);
Exemplo n.º 5
0
        /// <summary>
        /// This function opens a serial device at a specified baud rate
        /// and with specified flags.  The device name must start with
        /// /dev/tty or /dev/serial.
        ///
        /// The baud rate must be one of 50, 75, 110, 134, 150,
        /// 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200,
        /// 38400, 57600, 115200, or 230400.
        ///
        /// No flags are currently defined.  This parameter should be set to zero.
        /// </summary>
        /// <param name="sertty">the serial device to open</param>
        /// <param name="baud">the baud rate in bits per second, see below</param>
        /// <returns>Returns a handle (&gt;=0) if OK, otherwise PI_NO_HANDLE, or PI_SER_OPEN_FAILED.</returns>
        public static UIntPtr SerOpen(string sertty, UartRate baud)
        {
            var result = BoardException.ValidateResult(SerOpenUnmanaged(sertty, (uint)baud, 0));

            return(new UIntPtr((uint)result));
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UartPort"/> class.
 /// </summary>
 /// <param name="portName">Name of the port.</param>
 /// <param name="baudRate">The baud rate.</param>
 internal UartPort(string portName, UartRate baudRate)
 {
     Handle   = Uart.SerOpen(portName, baudRate);
     BaudRate = (int)baudRate;
     PortName = portName;
 }