Exemple #1
0
        /// <summary>
        ///     Default constructor
        /// </summary>
        /// <param name="socket">The socket in which the USB UART click board is inserted into.</param>
        /// <param name="baudRate">Baud Rate enumeration of usable baud rates (ones that actually work), see <see cref="System.IO.Ports.SerialPort.BaudRate"/></param>
        /// <param name="handshake">Optional - Handshake, defaults to None, see <see cref="System.IO.Ports.Handshake"/>. <see cref="System.IO.Ports.Handshake.RequestToSend "/> is not functional and will be set to <see cref="Handshake.None"/>.</param>
        /// <exception cref="PinInUseException">A <see cref="PinInUseException"/> will be thrown if the Tx, Rx, Rst, Int, Cs, Pwm are used in a stacked module arrangement.</exception>
        public USBUARTClick(Hardware.Socket socket, BaudRate baudRate, Handshake handshake)
        {
            try
            {
                // Rst Pin is connected to FT232RL CTS Pin, Int Pin is connected to FT232RL RTS Pin, Pwm Pin is connected to FT232RL CBUS3 Pin (USB Power), Cs Pin is connected to FT232RL CBUS4 Pin (USB Sleep/Suspend)
                Hardware.CheckPins(socket, socket.Tx, socket.Rx, socket.Rst, socket.Int, socket.Cs, socket.Pwm);
                _serial = new SimpleSerial(socket.ComPort, (int)baudRate)
                {
                    Handshake = handshake == Handshake.RequestToSend ? Handshake.None : handshake
                };

                _serial.DataReceived  += _serial_DataReceived;
                _serial.ErrorReceived += _serial_ErrorReceived;
                _serial.Open();

                _powerPin = new InterruptPort(socket.Pwm, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
                _sleepPin = new InterruptPort(socket.Cs, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);

                _powerPin.OnInterrupt += powerPin_OnInterrupt;
                _sleepPin.OnInterrupt += sleepPin_OnInterrupt;

                _powerPin.EnableInterrupt();
                _sleepPin.EnableInterrupt();
            }
            catch (PinInUseException ex)
            {
                throw new PinInUseException(ex.Message);
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            serial = new SimpleSerial(args[0], 9600, true);

            serial.DataReady += Serial_DataReady;

            Console.WriteLine("Reading. Press any key to escape.");

            Console.ReadKey(false);
        }
        /// <summary>
        ///     Default constructor
        /// </summary>
        /// <param name="socket">The socket in which the USB UART click board is inserted into.</param>
        /// <param name="baudRate">The baud rate for serial commumications.</param>
        /// <param name="dataBits"></param>
        /// <param name="parity"></param>
        /// <param name="stopBitCount"></param>
        /// <param name="handShake"></param>
        public USBUARTClick(Hardware.Socket socket, BaudRate baudRate, Int32 dataBits = 8, UartParity parity = UartParity.None, UartStopBitCount stopBitCount = UartStopBitCount.One, UartHandshake handShake = UartHandshake.None)
        {
            _serial = UartController.FromName(socket.ComPort);
            _serial.SetActiveSettings((Int32)baudRate, dataBits, parity, stopBitCount, handShake);
            _serial.Enable();

            _serial.DataReceived  += Serial_DataReceived;
            _serial.ErrorReceived += Serial_ErrorReceived;

            _simpleSerial = new SimpleSerial(_serial);

            _powerPin = GpioController.GetDefault().OpenPin(socket.PwmPin);
            _powerPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            _powerPin.ValueChanged += PowerPin_ValueChanged;

            _sleepPin = GpioController.GetDefault().OpenPin(socket.Cs);
            _sleepPin.SetDriveMode(GpioPinDriveMode.Input);
            _sleepPin.ValueChanged += SleepPin_ValueChanged;
        }