private void SerialPort_DataReceived(UartController sender, DataReceivedEventArgs e) { if (e.Count > 0) { ReadDataFromSerialPort(); } }
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(); }
// 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(); }
public void Initialize(UartController comPort) { _serialPort = comPort; _serialPort.DataReceived += _serialPort_DataReceived; // _comPort.ErrorReceived += new SerialErrorReceivedEventHandler(ErrorReceivedHandler); }
public CommunicationsBus(string uartPort, int baudRate = 9600) { this.disposed = false; this.commandFile = null; this.protocal = CommunicationsProtocal.Uart; this.uartPort = uartPort; this.serialPort = UartController.FromName(uartPort); var uartSetting = new UartSetting() { BaudRate = baudRate, DataBits = 8, Parity = UartParity.None, StopBits = UartStopBitCount.One, Handshaking = UartHandshake.None //UartHandshake.RequestToSend }; this.serialPort.SetActiveSettings(uartSetting); this.serialPort.WriteBufferSize = 16 * 1024; this.serialPort.ReadBufferSize = 16 * 1024; this.serialPort.Enable(); }
void Setup(UartController serialPort) { SerialPort = serialPort; _serialPoller = new SerialEventPoller(SerialPort); _serialPoller.DataReceived += OnDataReceivedEvent; }
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); }
/// <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(); }
static void Main() { RtcController rtc = RtcController.GetDefault(); try { var t = rtc.GetTime(); if (t.Year == 1980) { rtc.SetTime(RtcDateTime.FromDateTime(new DateTime(2018, 10, 12, 17, 51, 00))); } } catch (Exception) { rtc.SetTime(RtcDateTime.FromDateTime(new DateTime(2018, 10, 11, 11, 51, 00))); } //string COM = "GHIElectronics.TinyCLR.NativeApis.STM32F7.UartController\\2"; UartController ser = UartController.FromName(STM32F7.UartPort.Usart1); // DISCO-F769 //UartController ser = UartController.FromName(STM32F7.UartPort.Usart3); // NUCLEO-F767 ser.SetActiveSettings(38400, 8, UartParity.None, UartStopBitCount.One, UartHandshake.None); Debug.WriteLine("Starting Program ...."); BlinkLed blink = new BlinkLed(STM32F7.GpioPin.PJ5, 500); // Disco 769 //BlinkLed blink = new BlinkLed(STM32F7.GpioPin.PB7, 500); // Nucleo 144 - F767 Thread run = new Thread(blink.Blink); run.Start(); var r = new HeapAllocTest(10); r.Allocate(); //var d = new DisplayTest(); string sallocated = ""; //Debug.WriteLine("Allocated TOTAL Memory:" + GC.GetTotalMemory(false).ToString() + " bytes!"); //d.DrawSomething("Test String...", 50,50); int x = 10, y = 10; //SDTest sd = new SDTest(); sallocated = "Memory:" + GC.GetTotalMemory(true).ToString() + " bytes!"; while (true) { x += 2; y += 2; if (x > (800 - 160) || y > 480 - 160) { x = 10; y = 10; GC.Collect(); } Thread.Sleep(1000); //d.DrawSomething(sallocated, x, y); var dt = rtc.Now; byte[] b = System.Text.Encoding.UTF8.GetBytes("Program Running !! .." + dt.ToString("dd/MM/yyyy HH:mm:ss") + "\r\n"); ser.Write(b); ser.Flush(); } }
private void Serial_DataReceived(UartController sender, DataReceivedEventArgs e) { _dataIn = _simpleSerial.Deserialize(); foreach (String str in _dataIn) { DataReceived?.Invoke(this, str, DateTime.Now); } }
public void Dispose() { if (serialDevice != null) { serialDevice.Dispose(); serialDevice = null; } }
private void ThreadTest() { this.isRuning = true; using (var uart1 = UartController.FromName(SC20260.UartPort.Uart5)) { var setting = new UartSetting() { BaudRate = 115200 }; uart1.SetActiveSettings(setting); uart1.Enable(); var totalReceived = 0; var totalSent = 0; while (this.isRuning) { this.UpdateStatusText("Total received: " + totalReceived, true); this.UpdateStatusText("Total sent: " + totalSent, false); this.UpdateStatusText(WaitForMessage, false); while (uart1.BytesToRead == 0) { Thread.Sleep(10); } var byteToRead = uart1.BytesToRead > uart1.ReadBufferSize ? uart1.ReadBufferSize : uart1.BytesToRead; var read = new byte[byteToRead]; this.UpdateStatusText("Receiving... " + byteToRead + " byte(s)", false); totalReceived += uart1.Read(read); for (var i = 0; i < read.Length; i++) { var write = new byte[1] { (byte)(read[i] + 1) }; totalSent += uart1.Write(write); uart1.Flush(); } this.UpdateStatusText("Writing back... " + byteToRead + " byte(s)", false); } } this.isRuning = false; return; }
private bool DoTestUart() { this.UpdateStatusText("Testing VCOM Uart5.", true); this.UpdateStatusText(" - Connect VCOM Uart5 to PC.", false); this.UpdateStatusText(" - Open Tera Term. Baudrate: 9600, Data: 8, Parity: None, StopBit: One.", false); this.UpdateStatusText(" - Type 'A' or 'a'", false); this.UpdateStatusText(" - The test is waiting any character on Tera Term screen.", false); var result = false; using (var uart5 = UartController.FromName(SC20260.UartPort.Uart5)) { var setting = new UartSetting() { BaudRate = 9600 }; uart5.SetActiveSettings(setting); uart5.Enable(); this.AddNextButton(); while (this.doNext == false && this.isRunning) { if (uart5.BytesToRead == 0) { Thread.Sleep(100); uart5.Write(new byte[] { (byte)('a') }); continue; } var byteToRead = uart5.BytesToRead > uart5.ReadBufferSize ? uart5.ReadBufferSize : uart5.BytesToRead; var read = new byte[byteToRead]; uart5.Read(read); for (var i = 0; i < read.Length; i++) { if (read[i] == 'a') { result = true; break; } } if (result == true) { break; } } } this.RemoveNextButton(); return(result); }
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); } }
void CloseComPort() { if (serialPort != null) { serialPort.Disable(); serialPort.Dispose(); serialPort = null; } }
/// <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(); }
/// <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(); }
public MusicalInstrumentShield(string uart) { this.uart = UartController.FromName(uart); this.uart.SetActiveSettings((int)(31250), 8, UartParity.None, UartStopBitCount.One, UartHandshake.None); this.uart.Enable(); }
private void Initialize(UartController port) { _esp = new Esp8266Serial(port); _esp.DataReceived += OnDataReceived; _esp.SocketClosed += OnSocketClosed; _esp.SocketOpened += _esp_SocketOpened; _esp.Fault += OnEspFault; _esp.Start(); ThreadPool.QueueUserWorkItem(BackgroundInitialize); }
private void Sp_DataReceived(UartController sender, GHIElectronics.TinyCLR.Devices.Uart.DataReceivedEventArgs e) { var nb = _sp.BytesToRead; var buf = new Byte[nb]; _sp.Read(buf, 0, nb); DataReceivedEventHandler tempEvent = DataReceived; tempEvent(this, new DataReceivedEventArgs(buf, nb)); }
private static void SerialDevice_DataReceived(UartController sender, DataReceivedEventArgs e) { byte[] rxBuffer = new byte[e.Count]; sender.Read(rxBuffer, 0, e.Count); Debug.WriteLine($"RX Async:{e.Count} bytes read"); String response = UTF8Encoding.UTF8.GetString(rxBuffer); Debug.WriteLine($"RX Async:{response}"); }
private void Sp_DataReceived(UartController sender, DataReceivedEventArgs e) { var nb = _sp.BytesToRead; var buf = new Byte[nb]; _sp.Read(buf, 0, nb); SpeakUpEventHandler speakEvent = SpeakDetected; speakEvent(this, new SpeakUpEventArgs(buf[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 { } }
public Esp8266WifiDevice(UartController port, GpioPin powerPin, GpioPin resetPin) { _powerPin = powerPin; _powerPin.SetDriveMode(GpioPinDriveMode.Output); _powerPin.Write(GpioPinValue.High); _resetPin = resetPin; Initialize(port); }
/// <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(); }
/// <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"); }
private void Gnss_DataReceived(UartController sender, DataReceivedEventArgs e) { var btr = _gnss.BytesToRead; while (btr != 0) { var _buffer = new Byte[btr]; _gnss.Read(_buffer, 0, btr); _sl.Add(_buffer); _buffer = null; btr = _gnss.BytesToRead; } }
public CommunicationsBus(string uartPort, int baudRate = 115200) { this.disposed = false; this.commandFile = null; this.protocal = CommunicationsProtocal.Uart; this.serialPort = UartController.FromName(uartPort); this.serialPort.SetActiveSettings(baudRate, 8, UartParity.None, UartStopBitCount.One, UartHandshake.None); this.serialPort.Enable(); this.serialPort.DataReceived += this.SerialPort_DataReceived; }
private void SerialPort_DataReceived(UartController sender, DataReceivedEventArgs e) { var rxBuffer = new byte[e.Count]; var bytesReceived = this.serialPort.Read(rxBuffer, 0, e.Count); var dataStr = Encoding.UTF8.GetString(rxBuffer, 0, bytesReceived); Debug.WriteLine(dataStr); this.TempData += dataStr; if (dataStr.IndexOf("\n") > -1) { DataReceived?.Invoke(this.TempData.Trim()); this.TempData = string.Empty; } }
/// <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 { } }