Create a gist now

Instantly share code, notes, and snippets.

anonymous /SerialExample.cs
Created May 9, 2017

What would you like to do?
using GHIElectronics.TinyCLR.Devices.SerialCommunication;
using GHIElectronics.TinyCLR.Pins;
using GHIElectronics.TinyCLR.Storage.Streams;
using System.Threading;
namespace SerialExample {
class Program {
static void Main() {
var ser = SerialDevice.FromId(FEZPandaIII.SerialPort.Com1);
ser.BaudRate = 9600;
ser.StopBits = SerialStopBitCount.One;
ser.Parity = SerialParity.None;
ser.DataBits = 8;
ser.Handshake = SerialHandshake.None;
var reader = new DataReader(ser.InputStream);
var writer = new DataWriter(ser.OutputStream);
writer.WriteString("Ready\r\n");
writer.Store();
while (true) {
var read = reader.Load(10);
if (read > 0) {
var str = reader.ReadString(read);
writer.WriteString(str);
writer.Store();
}
Thread.Sleep(10);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment