예제 #1
0
        public Result Initialise(string serialPortId, int baudRate, UartParity serialParity, int dataBits, UartStopBitCount stopBitCount)
        {
            if ((serialPortId == null) || (serialPortId == ""))
            {
                throw new ArgumentException("Invalid SerialPortId", "serialPortId");
            }
            if ((baudRate < BaudRateMinimum) || (baudRate > BaudRateMaximum))
            {
                throw new ArgumentException("Invalid BaudRate", "baudRate");
            }

            serialDevice = UartController.FromName(serialPortId);

            // set parameters
            serialDevice.SetActiveSettings(new UartSetting()
            {
                BaudRate    = baudRate,
                Parity      = serialParity,
                StopBits    = stopBitCount,
                Handshaking = UartHandshake.None,
                DataBits    = dataBits
            });

            serialDevice.Enable();

            atCommandExpectedResponse = string.Empty;

            serialDevice.DataReceived += SerialDevice_DataReceived;

            // Ignoring the return from this is intentional
            this.SendCommand("+LOWPOWER: WAKEUP", "AT+LOWPOWER: WAKEUP", SendTimeoutMinimum);

            return(Result.Success);
        }
예제 #2
0
        // TODO: if we want to make this public then we're going to have to add
        // a bunch of checks around baud rate, 8n1, etc.
        protected Mt3339(string serialPortControllerName)
        {
            serialPort = UartController.FromName(serialPortControllerName);

            var uartSetting = new UartSetting()
            {
                BaudRate    = 115200,
                DataBits    = 8,
                Parity      = UartParity.None,
                StopBits    = UartStopBitCount.One,
                Handshaking = UartHandshake.None,
            };

            serialPort.SetActiveSettings(uartSetting);

            serialPort.Enable();

            serialPort.DataReceived += SerialPort_DataReceived;

            //this.serialPort = serialPort;

            //this.serialPort.MessageReceived += SerialPort_MessageReceived;

            Init();
        }
예제 #3
0
        protected void OpenComPort(string port = "COM1", int baudRate = 38400)
        {
            CloseComPort();

            //ToDo  serialPort = new SerialPort(port, baudRate, Parity.None, 8, StopBits.One);

            //serialPort.ReadTimeout = 10 * 2;
            vc0706.ReadTimeout = 10 * 2;
            // serialPort.WriteTimeout = 10 * 2;

            //serialPort.Enable();
            serialPort = UartController.FromName(port);
            var uartSetting = new UartSetting()
            {
                BaudRate    = baudRate,
                DataBits    = 8,
                Parity      = UartParity.None,
                StopBits    = UartStopBitCount.One,
                Handshaking = UartHandshake.None,
            };

            vc0706.BaudRate = baudRate;
            serialPort.SetActiveSettings(uartSetting);

            serialPort.Enable();
        }
예제 #4
0
        /// <summary>Initializes a new instance of the <see cref="GPS2Click" /> class.</summary>
        /// <param name="socket">The socket on which the module is plugged</param>
        public GPS2Click(Hardware.Socket socket)
        {
            _sl = new SerialListener('$', '\n');
            _sl.MessageAvailable += Sl_MessageAvailable;

            _wakeUp = GpioController.GetDefault().OpenPin(socket.AnPin);
            _wakeUp.SetDriveMode(GpioPinDriveMode.Input);

            _onOff = GpioController.GetDefault().OpenPin(socket.PwmPin);
            _onOff.SetDriveMode(GpioPinDriveMode.Output);
            // Force full mode
            _onOff.Write(GpioPinValue.Low);
            Thread.Sleep(100);
            _onOff.Write(GpioPinValue.High);
            Thread.Sleep(100);
            _onOff.Write(GpioPinValue.Low);
            Thread.Sleep(1);
            _onOff.Write(GpioPinValue.High);
            Thread.Sleep(100);

            _gps2 = UartController.FromName(socket.ComPort); // Socket #1
            _gps2.SetActiveSettings(new UartSetting()
            {
                BaudRate = 4800, DataBits = 8, Parity = UartParity.None, StopBits = UartStopBitCount.One, Handshaking = UartHandshake.None
            });
            _gps2.DataReceived += Gps2_DataReceived;
            _gps2.Enable();
        }
예제 #5
0
        public static void Main()
        {
            Debug.WriteLine("devMobile.IoT.Rak811.ShieldSerial starting");

            try
            {
                serialDevice = UartController.FromName(SerialPortId);

                serialDevice.SetActiveSettings(new UartSetting()
                {
                    BaudRate    = 9600,
                    Parity      = UartParity.None,
                    StopBits    = UartStopBitCount.One,
                    Handshaking = UartHandshake.None,
                    DataBits    = 8
                });

                serialDevice.Enable();

#if SERIAL_ASYNC_READ
                serialDevice.DataReceived += SerialDevice_DataReceived;
#endif

                while (true)
                {
                    byte[] txBuffer = UTF8Encoding.UTF8.GetBytes(ATCommand);

                    int txByteCount = serialDevice.Write(txBuffer);
                    Debug.WriteLine($"TX: {txByteCount} bytes");

#if SERIAL_SYNC_READ
                    while (serialDevice.BytesToWrite > 0)
                    {
                        Debug.WriteLine($" BytesToWrite {serialDevice.BytesToWrite}");
                        Thread.Sleep(100);
                    }

                    int rxByteCount = serialDevice.BytesToRead;
                    if (rxByteCount > 0)
                    {
                        byte[] rxBuffer = new byte[rxByteCount];

                        serialDevice.Read(rxBuffer);

                        Debug.WriteLine($"RX sync:{rxByteCount} bytes read");
                        String response = UTF8Encoding.UTF8.GetString(rxBuffer);
                        Debug.WriteLine($"RX sync:{response}");
                    }
#endif

                    Thread.Sleep(20000);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FTDIClick" /> class.
 /// </summary>
 /// <param name="socket">The socket on which the FTDIClick module is plugged on MikroBus.Net board</param>
 /// <param name="baudRate">The baud rate.</param>
 /// <param name="parity">The parity.</param>
 /// <param name="dataBits">The data bits.</param>
 /// <param name="stopBits">The stop bits.</param>
 public FTDIClick(Hardware.Socket socket, Int32 baudRate = 9600, UartParity parity = UartParity.None, Int32 dataBits = 8, UartStopBitCount stopBits = UartStopBitCount.One)
 {
     _sp = UartController.FromName(socket.ComPort);
     _sp.SetActiveSettings(new UartSetting()
     {
         BaudRate = baudRate, DataBits = dataBits, Parity = parity, StopBits = stopBits, Handshaking = UartHandshake.None
     });
     _sp.Enable();
 }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpeakUpClick"/> class.
 /// </summary>
 /// <param name="socket">The socket on which the SpeakUpClick module is plugged on MikroBus.Net board</param>
 public SpeakUpClick(Hardware.Socket socket)
 {
     _sp = UartController.FromName(socket.ComPort);
     _sp.SetActiveSettings(new UartSetting()
     {
         BaudRate = 115200, DataBits = 8, Parity = UartParity.None, StopBits = UartStopBitCount.One, Handshaking = UartHandshake.None
     });
     _sp.Enable();
 }
예제 #8
0
        /// <summary>
        ///     Open the serial port and start processing the data from the serial port.
        /// </summary>
        public void Open()
        {
            //Console.WriteLine("SerialTextFile: Open");

            if (!IsEnabled)
            {
                //Console.WriteLine("SerialTextFile: _serialPort.Open");
                serialPort.Enable();
                IsEnabled = true;
            }
        }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DevantechLcd03"/> class using serial communication (UART)
 /// </summary>
 /// <param name="socket">The socket on MBN board where the Lcd is connected</param>
 public DevantechLcd03(Hardware.Socket socket)
 {
     try
     {
         _lcdSerial = UartController.FromName(socket.ComPort);
         _lcdSerial.SetActiveSettings(9600, 8, UartParity.None, UartStopBitCount.Two, UartHandshake.None);
         _lcdSerial.Enable();
         _isUart = true;
         Init();
     }
     catch { }
 }
예제 #10
0
        /// <summary>Initializes a new instance of the <see cref="GNSSClick" /> class.</summary>
        /// <param name="socket">The socket on which the module is plugged</param>
        public GNSSClick(Hardware.Socket socket)
        {
            _sl = new SerialListener('$', '\n');
            _sl.MessageAvailable += Sl_MessageAvailable;

            _gnss = UartController.FromName(socket.ComPort);
            _gnss.SetActiveSettings(9600, 8, UartParity.None, UartStopBitCount.One, UartHandshake.None);
            _gnss.DataReceived += Gnss_DataReceived;
            _gnss.Enable();
            // It seems that we need to send a command so that the module starts sending its data.
            // So we send a command to request firmware version
            SendCommand("PMTK605");
        }
예제 #11
0
        /// <summary>Initializes a new instance of the <see cref="Gnss4Click" /> class.</summary>
        /// <param name="socket">The socket on which the module is plugged</param>
        public Gnss4Click(Hardware.Socket socket)
        {
            _sl = new SerialListener('$', '\n');
            _sl.MessageAvailable += Sl_MessageAvailable;

            _gnss = UartController.FromName(socket.ComPort);
            _gnss.SetActiveSettings(new UartSetting()
            {
                BaudRate = 9600, DataBits = 8, Parity = UartParity.None, StopBits = UartStopBitCount.One, Handshaking = UartHandshake.None
            });
            _gnss.DataReceived += Gnss_DataReceived;
            _gnss.Enable();
        }
예제 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DevantechLcd03"/> class using serial communication (UART)
 /// </summary>
 /// <param name="socket">The socket on MBN board where the Lcd is connected</param>
 public DevantechLcd03(Hardware.Socket socket)
 {
     try
     {
         _lcdSerial = UartController.FromName(socket.ComPort);
         _lcdSerial.SetActiveSettings(new UartSetting()
         {
             BaudRate = 9600, DataBits = 8, Parity = UartParity.None, StopBits = UartStopBitCount.Two, Handshaking = UartHandshake.None
         });
         _lcdSerial.Enable();
         _isUart = true;
         Init();
     }
     catch { }
 }
        public Result Initialise(string serialPortId, int baudRate, UartParity serialParity, int dataBits, UartStopBitCount stopBitCount)
        {
            Result result;

            if ((serialPortId == null) || (serialPortId == ""))
            {
                throw new ArgumentException("Invalid SerialPortId", "serialPortId");
            }
            if ((baudRate < BaudRateMinimum) || (baudRate > BaudRateMaximum))
            {
                throw new ArgumentException("Invalid BaudRate", "baudRate");
            }

            serialDevice = UartController.FromName(serialPortId);

            // set parameters
            serialDevice.SetActiveSettings(new UartSetting()
            {
                BaudRate    = baudRate,
                Parity      = serialParity,
                StopBits    = stopBitCount,
                Handshaking = UartHandshake.None,
                DataBits    = dataBits
            });

            serialDevice.Enable();

            atCommandExpectedResponse = string.Empty;

            serialDevice.DataReceived += SerialDevice_DataReceived;

            // Set the Working mode to LoRaWAN
#if DIAGNOSTICS
            Debug.WriteLine($" {DateTime.UtcNow:hh:mm:ss} lora:work_mode LoRaWAN");
#endif
            result = SendCommand("Initialization OK", "at+set_config=lora:work_mode:0", CommandTimeoutDefault);
            if (result != Result.Success)
            {
#if DIAGNOSTICS
                Debug.WriteLine($" {DateTime.UtcNow:hh:mm:ss} lora:work_mode failed {result}");
#endif
                return(result);
            }

            return(Result.Success);
        }
예제 #14
0
        /// <summary>
        ///     Create a new SerialTextFile and attach the instance to the specfied serial port.
        /// </summary>
        /// <param name="port">Serial port name.</param>
        /// <param name="baudRate">Baud rate.</param>
        /// <param name="parity">Parity.</param>
        /// <param name="dataBits">Data bits.</param>
        /// <param name="stopBits">Stop bits.</param>
        /// <param name="endOfLine">Text indicating the end of a line of text.</param>
        public SerialTextFile(string UartControllerName, int baudRate, UartParity parity, int dataBits, UartStopBitCount stopBits,
                              string endOfLine)
        {
            serialPort = UartController.FromName(UartControllerName);
            var uartSetting = new UartSetting()
            {
                BaudRate    = baudRate,
                DataBits    = dataBits,
                Parity      = parity,
                StopBits    = stopBits,
                Handshaking = UartHandshake.None,
            };

            serialPort.SetActiveSettings(uartSetting);

            serialPort.Enable();
            IsEnabled = true;
            LINE_END  = endOfLine;
            serialPort.DataReceived += SerialPort_DataReceived;
        }
예제 #15
0
        public void StartUpdataing()
        {
            // open the serial connection
            serialPort.Enable();
            Debug.WriteLine("serial port opened.");

            //==== setup commands

            // get release and version
            Debug.WriteLine("Asking for release and version.");
            this.serialPort.Write(Encoding.UTF8.GetBytes(Commands.PMTK_Q_RELEASE));

            // get atntenna info
            Debug.WriteLine("Start output antenna info");
            this.serialPort.Write(Encoding.UTF8.GetBytes(Commands.PGCMD_ANTENNA));

            // turn on all data
            Debug.WriteLine("Turning on all data");
            this.serialPort.Write(Encoding.UTF8.GetBytes(Commands.PMTK_SET_NMEA_OUTPUT_ALLDATA));
        }
예제 #16
0
        public Vc0706(string serialPortName, int baudRate)
        {
            //serialPort = device.CreateSerialPort(serialPortName, baudRate);
            serialPort = UartController.FromName(serialPortName);

            var uartSetting = new UartSetting()
            {
                BaudRate    = baudRate,
                DataBits    = 8,
                Parity      = UartParity.None,
                StopBits    = UartStopBitCount.One,
                Handshaking = UartHandshake.None,
            };

            serialPort.SetActiveSettings(uartSetting);

            serialPort.Enable();

            vc0706          = new Vc0706Core();
            vc0706.BaudRate = baudRate;
            vc0706.PortName = serialPortName;
        }
예제 #17
0
        /// <summary>
        /// Construct Bluetooth module
        /// </summary>
        /// <param name="pinStatus">GpioPin Pin 3 of U Socket</param>
        /// <param name="pinReset">GpioPin Pin 6 of U Socket</param>
        /// <param name="uartId">Uart Id of U Socket</param>
        public Bluetooth(int pinStatus, int pinReset, string uartId)
        {
            // This finds the Socket instance from the user-specified socket number. This will generate user-friendly error messages if the socket is invalid. If there is more than one socket on this
            // module, then instead of "null" for the last parameter, put text that identifies the socket to the user (e.g. "S" if there is a socket type S)
            // Socket socket = Socket.GetSocket(socketNumber, true, this, null);
            rxBuffer = new byte[128];
            //this.reset = GTI.DigitalOutputFactory.Create(socket, Socket.Pin.Six, false, this);
            _reset = GpioController.GetDefault().OpenPin(pinReset);
            _reset.SetDriveMode(GpioPinDriveMode.Output);
            _reset.Write(GpioPinValue.Low);

            // this.statusInt = GTI.InterruptInputFactory.Create(socket, Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, GTI.InterruptMode.RisingAndFallingEdge, this);
            _statusInt = GpioController.GetDefault().OpenPin(pinStatus);
            _statusInt.SetDriveMode(GpioPinDriveMode.Input);
            _statusInt.DebounceTimeout = TimeSpan.FromMilliseconds(1);

            // this.serialPort = GTI.SerialFactory.Create(socket, 38400, GTI.SerialParity.None, GTI.SerialStopBits.One, 8, GTI.HardwareFlowControl.NotRequired, this);
            _serialPort = UartController.FromName(uartId);
            _serialPort.SetActiveSettings(38400, 8, UartParity.None, UartStopBitCount.One, UartHandshake.None);
            _serialPort.Enable();

            //_serialPort.DataReceived += _serialPort_DataReceived;

            //this.statusInt.Interrupt += GTI.InterruptInputFactory.Create.InterruptEventHandler(statusInt_Interrupt);
            //           this.serialPort.ReadTimeout = Timeout.Infinite;
            //           this.serialPort.Open();

            //_dataReader = new DataReader(_serialPort.InputStream);
            //_dataWriter = new DataWriter(_serialPort.OutputStream);

            Thread.Sleep(5);
            _reset.Write(GpioPinValue.High);

            _readerThread = new Thread(RunReaderThread);
            _readerThread.Start();
            Thread.Sleep(500);
        }
예제 #18
0
        public static void Main()
        {
            // Get the display ready
            var spi    = SpiController.FromName(G80.SpiBus.Spi2);
            var gpio   = GpioController.GetDefault();
            var st7735 = new ST7735Controller(spi.GetDevice(ST7735Controller.GetConnectionSettings(SpiChipSelectType.Gpio, G80.GpioPin.PD10)), gpio.OpenPin(G80.GpioPin.PE10), gpio.OpenPin(G80.GpioPin.PE12));

            st7735.SetDataAccessControl(true, true, false, false);
            st7735.Enable();
            var disp = DisplayController.FromProvider(st7735);

            disp.SetConfiguration(new SpiDisplayControllerSettings {
                Width = 160, Height = 128
            });
            var bl = gpio.OpenPin(G80.GpioPin.PC7);

            bl.Write(GpioPinValue.High);
            bl.SetDriveMode(GpioPinDriveMode.Output);
            var hdc = GraphicsManager.RegisterDrawTarget(new DrawTarget(disp));

            screen = Graphics.FromHdc(hdc);
            screen.Clear(Color.Black);

            var btn1 = gpio.OpenPin(G80.GpioPin.PE0);

            btn1.SetDriveMode(GpioPinDriveMode.InputPullUp);
            btn1.ValueChanged += Btn1_ValueChanged;

            // Serial port
            serial = UartController.FromName(G80.UartPort.Usart1);
            serial.SetActiveSettings(9600, 8, UartParity.None, UartStopBitCount.One, UartHandshake.None);
            serial.Enable();
            serial.DataReceived += Serial_DataReceived;

            Thread.Sleep(Timeout.Infinite);
        }
예제 #19
0
 public void Start()
 {
     _port.DataReceived += _port_DataReceived;
     //_port.DataReceived += PortOnDataReceived;
     _port.Enable();
 }
예제 #20
0
 /// <summary>
 ///     Opens a new serial port connection.
 /// </summary>
 internal void Enable()
 {
     _remainder = String.Empty;
     _serial.Enable();
 }
예제 #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpeakUpClick"/> class.
 /// </summary>
 /// <param name="socket">The socket on which the SpeakUpClick module is plugged on MikroBus.Net board</param>
 public SpeakUpClick(Hardware.Socket socket)
 {
     _sp = UartController.FromName(socket.ComPort);
     _sp.SetActiveSettings(115200, 8, UartParity.None, UartStopBitCount.One, UartHandshake.None);
     _sp.Enable();
 }