private Result SendCommand(string expectedResponse, string command, TimeSpan timeout) { if ((expectedResponse == null) || (expectedResponse == string.Empty)) { throw new ArgumentException($"expectedResponse invalid length cannot be empty", "expectedResponse"); } if ((command == null) || (command == string.Empty)) { throw new ArgumentException($"command invalid length cannot be empty", "command"); } if ((timeout < SendTimeoutMinimum) || (timeout > SendTimeoutMaximum)) { throw new ArgumentException($"timeout invalid must be greater than or equal to {SendTimeoutMinimum.TotalSeconds} seconds and less than or equal to {SendTimeoutMaximum.TotalSeconds} seconds", "timeout"); } this.atCommandExpectedResponse = expectedResponse; serialDevice.Write(UTF8Encoding.UTF8.GetBytes(command + EndOfLineMarker)); this.atExpectedEvent.Reset(); if (!this.atExpectedEvent.WaitOne((int)timeout.TotalMilliseconds, false)) { return(Result.ATResponseTimeout); } this.atCommandExpectedResponse = string.Empty; return(result); }
private static void Btn1_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e) { if (e.Edge == GpioPinEdge.FallingEdge) { serial.Write(Encoding.UTF8.GetBytes("Hi " + count++ + Environment.NewLine)); } }
private Result SendCommand(string expectedResponse, string command, TimeSpan timeout) { Debug.Assert(expectedResponse != null); Debug.Assert(command != null); if (string.IsNullOrEmpty(expectedResponse)) { throw new ArgumentException($"expectedResponse invalid length cannot be empty", "expectedResponse"); } if (string.IsNullOrEmpty(command)) { throw new ArgumentException($"command invalid length cannot be empty", "command"); } this.atCommandExpectedResponse = expectedResponse; serialDevice.Write(UTF8Encoding.UTF8.GetBytes(command + EndOfLineMarker)); this.atExpectedEvent.Reset(); if (!this.atExpectedEvent.WaitOne((int)timeout.TotalMilliseconds, false)) { return(Result.ATCommandResponseTimeout); } this.atCommandExpectedResponse = string.Empty; return(result); }
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(); } }
/// <summary> /// Write the buffer of data to the COM port (i.e. the display). /// </summary> /// <param name="buffer">Bytes of data to be sent to the display.</param> private void Send(byte[] buffer) { // critical section so we don't have mixed messages lock (_lock) { comPort.Write(buffer, 0, buffer.Length); } }
public void Write(byte[] payload) { if (_enableVerboseOutput) { Dump("SEND:", payload); } _port.Write(payload, 0, payload.Length); }
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); } }
/// <summary> /// Sets the cursor at specified coordinates /// </summary> /// <param name="x">The column (1 to 20)</param> /// <param name="y">The line (1 to 4)</param> /// <example> /// <code language="C#"> /// // Sets the cursor position on column 10 of line 2 /// _lcd.Cursor(10,2); /// </code> /// </example> public void SetCursor(Byte x, Byte y) { if (x <= 0 || x > 20 || y <= 0 || y > 4) { return; } if (_isUart) { _lcdSerial.Write(new Byte[] { 3, y, x }); } else { lock (Hardware.LockI2C) { _lcdI2C.Write(new Byte[] { 0, 3, y, x }); } } }
protected void SendCommandToCamera(Command command, byte[] args) { var commandIndex = 0; _command[commandIndex++] = CommandSend; _command[commandIndex++] = CameraSerial; _command[commandIndex++] = (byte)command; var argsLength = 0; if (args != null) { argsLength = args.Length; _command[commandIndex++] = (byte)argsLength; Array.Copy(args, 0, _command, commandIndex, argsLength); } else { _command[commandIndex++] = 0; } _serialPort.Write(_command, 0, argsLength + 4); }
/// <summary>Sends a command to the GNSS 4 module.</summary> /// <param name="cmd">The command, without both the starting '$' and the ending '*'.</param> public void SendCommand(String cmd) { _gnss.Write(Encoding.UTF8.GetBytes($"${cmd}*{CalculateChecksum(cmd):X2}\r\n")); _gnss.Flush(); }
/// <summary> /// Sends data to the FTDI chip. /// </summary> /// <param name="data">Array of bytes containing data to send</param> /// <example> /// <code language="C#"> /// public static void Main() /// { /// try /// { /// _ftdi = new FTDIClick(Hardware.SocketOne); /// /// _ftdi.SendData(Encoding.UTF8.GetBytes("Hello world !")); /// } /// catch (PinInUseException) /// { /// Debug.Print("Error accessing the FTDI Click board"); /// } /// /// Thread.Sleep(Timeout.Infinite); /// } /// </code> /// </example> public void SendData(Byte[] data) => _sp.Write(data, 0, data.Length);
/// <summary> /// Send a <see cref="System.String"/> of data to the USB client connected to the USBUART click. /// </summary> /// <param name="data">String data to send.</param> /// <example> /// <code language = "C#"> /// _usbUart.SendData("Received your message - " + message); /// </code> /// <code language = "VB"> /// _usbUart.SendData("Received your message - " <![CDATA[&]]> message) /// </code> /// </example> public void SendData(String data) => _serial.Write(Encoding.UTF8.GetBytes(data));
/// <summary>Sends a command to the GNSS 4 module.</summary> /// <param name="cmd">The command, with both the starting '$' and the ending '*'.</param> public void SendCommand(String cmd) { _gnss.Write(Encoding.UTF8.GetBytes($"{cmd}{NMEAParser.CalculateChecksum(Encoding.UTF8.GetBytes(cmd)):X2}\r\n")); _gnss.Flush(); }
/// <summary> /// Writes the specified string to the serial port. /// </summary> /// <param name="txt" /> internal void Write(String txt) { _serial.Write(Encoding.UTF8.GetBytes(txt), 0, txt.Length); }