/// <summary> /// Tests suffix/terminator delimited message reception. /// </summary> protected void TestSuffixDelimiter() { // TEST PARAM // whether or not to return the message with the tokens in it bool preseveDelimiter = true; // instantiate our serial port this.serialPort = Device.CreateSerialMessagePort( serialPortName, delimiterBytes, preseveDelimiter, baudRate: 115200); Console.WriteLine("\tCreated"); // open the serial port this.serialPort.Open(); Console.WriteLine("\tOpened"); // wire up message received handler this.serialPort.MessageReceived += SerialPort_MessageReceived; // write to the port. while (true) { foreach (var sentence in BuildVariableLengthTestSentences()) { //var dataToWrite = Encoding.ASCII.GetBytes($"{sentence}{DelimiterToken}"); var dataToWrite = Encoding.ASCII.GetBytes($"{sentence}").Concat(delimiterBytes).ToArray(); //var dataToWrite = Encoding.ASCII.GetBytes($"{sentence}") + delimiter; var written = this.serialPort.Write(dataToWrite); Console.WriteLine($"\nWrote {written} bytes"); // sleep Thread.Sleep(2000); } } }
/// <summary> /// Test for https://github.com/WildernessLabs/Meadow_Issues/issues/102 /// </summary> protected void TestSuffixDelimeterAndBufferLengthForNulls() { // instantiate our serial port this.serialPort = Device.CreateSerialMessagePort( serialPortName, Encoding.UTF8.GetBytes("\r\n"), false, baudRate: 115200); Console.WriteLine("\tCreated"); // open the serial port this.serialPort.Open(); Console.WriteLine("\tOpened"); // wire up message received handler this.serialPort.MessageReceived += (object sender, SerialMessageData e) => { Console.WriteLine($"Message Lenght: {e.Message.Length}"); if (e.Message.Length == 11) { Console.WriteLine("Things are groovy."); } else { Console.WriteLine("Things are not so groovy."); } }; var dataToWrite = Encoding.ASCII.GetBytes($"TestMessage\r\n"); var written = this.serialPort.Write(dataToWrite); Console.WriteLine($"\nWrote {written} bytes"); }
void Initialize() { Console.WriteLine("Initialize hardware..."); display = new Ssd1309(Device.CreateI2cBus()); Console.WriteLine("Display created"); graphics = new GraphicsLibrary(display); graphics.CurrentFont = new Font8x8(); Console.WriteLine("Graphics library created"); //COM4 - Pins D00 & D01 on the Meadow F7 port = Device.CreateSerialMessagePort( Device.SerialPortNames.Com4, suffixDelimiter: Encoding.ASCII.GetBytes("\r\n"), preserveDelimiter: true, 9600); Console.WriteLine("Serial port created"); port.MessageReceived += (object sender, SerialMessageData e) => { nmea.ProcessNmeaMessage(e.GetMessageString(Encoding.ASCII)); }; nmea = new NmeaSentenceProcessor(); var ggaParser = new GgaDecoder(); ggaParser.PositionReceived += GgaParser_OnPositionReceived; nmea.RegisterDecoder(ggaParser); // open serial port.Open(); }
protected void TestDoubleMessageWithSuffix() { // TEST PARAM // whether or not to return the message with the tokens in it bool preseveDelimiter = false; // instantiate our serial port this.serialPort = Device.CreateSerialMessagePort( serialPortName, delimiterBytes, preseveDelimiter, baudRate: 115200); Console.WriteLine("\tCreated"); // open the serial port this.serialPort.Open(); Console.WriteLine("\tOpened"); // wire up message received handler this.serialPort.MessageReceived += SerialPort_MessageReceived; var dataToWrite = Encoding.ASCII.GetBytes($"{GetDoubleInOne()}").Concat(delimiterBytes).ToArray(); var written = this.serialPort.Write(dataToWrite); Console.WriteLine($"\nWrote {written} bytes"); // sleep Thread.Sleep(2000); }
// 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(ISerialMessagePort serialPort) { this.serialPort = serialPort; this.serialPort.MessageReceived += SerialPort_MessageReceived; Init(); }
/// <summary> /// Main constructor /// </summary> /// <param name="p">Serial port to use for communication</param> public ComCommunication(ISerialMessagePort p) { locker = new object(); port = p; port.Open(); port.MessageReceived += Port_MessageReceived; SendMessage("Waiting for connection..."); }
void Initialize() { ISerialMessagePort serial = Device.CreateSerialMessagePort( Device.SerialPortNames.Com4, suffixDelimiter: Encoding.ASCII.GetBytes("\r\n"), preserveDelimiter: true, baudRate: 9600); gps = new GPSWing(serial); }
void Initialize() { uptime = new Stopwatch(); uptime.Start(); serialPort = Device.CreateSerialMessagePort( Device.SerialPortNames.Com4, suffixDelimiter: Encoding.UTF8.GetBytes("\r\n"), preserveDelimiter: true); serialPort.MessageReceived += SerialPort_MessageReceived; InitDecoders(); heartbeatLed = new RgbPwmLed( Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue, commonType: Meadow.Peripherals.Leds.IRgbLed.CommonType.CommonAnode); }
void Initialize() { Console.WriteLine("Initialize hardware..."); onboardLed = new RgbPwmLed(device: Device, redPwmPin: Device.Pins.OnboardLedRed, greenPwmPin: Device.Pins.OnboardLedGreen, bluePwmPin: Device.Pins.OnboardLedBlue, 3.3f, 3.3f, 3.3f, Meadow.Peripherals.Leds.IRgbLed.CommonType.CommonAnode); bus = Device.CreateI2cBus(); display = new CharacterDisplay(bus, 39, 2, 16); port = Device.CreateSerialMessagePort(Device.SerialPortNames.Com4, suffixDelimiter: new byte[] { 10 }, preserveDelimiter: true, 921600, 8, Parity.None, StopBits.One); port.Open(); port.MessageReceived += Port_MessageReceived; }
public MeadowApp() { //this.commandButton = new PushButton(Device, Device.Pins.D10, debounceDuration: 50); //this.commandButton.Clicked += this.CommandButton_Button_Clicked; ////this.commandButton.PressEnded += CommandButton_PressEnded; //this.debounceTimer.Elapsed += DebounceTimer_Elapsed; var motorLeft = new HBridgeMotor ( a1Pin: Device.CreatePwmPort(Device.Pins.D05), a2Pin: Device.CreatePwmPort(Device.Pins.D06), enablePin: Device.CreateDigitalOutputPort(Device.Pins.D07) ); var motorRight = new HBridgeMotor ( a1Pin: Device.CreatePwmPort(Device.Pins.D02), a2Pin: Device.CreatePwmPort(Device.Pins.D03), enablePin: Device.CreateDigitalOutputPort(Device.Pins.D04) ); carController = new CarController(motorLeft, motorRight); this.commands[0] = this.Back; this.commands[1] = this.Right; this.commands[2] = this.Forward; this.commands[3] = this.Left; this.commands[4] = this.Stop; this.serialPort = Device.CreateSerialMessagePort(Device.SerialPortNames.Com1, suffixDelimiter: Encoding.UTF8.GetBytes("\r\n"), preserveDelimiter: true, baudRate: 115200); this.serialPort.Open(); this.serialPort.MessageReceived += SerialPort_MessageReceived; //Console.WriteLine("Serial port " + this.serialPort.PortName + " is " + (this.serialPort.IsOpen ? "open" : "closed")); this.serialPort.Write(Encoding.UTF8.GetBytes("serial port is open\r\n")); this.UpdateOnboardLed("red"); Thread.Sleep(Timeout.Infinite); }
/// <summary> /// Create an IDxxLA RFID reader using an existing port. /// </summary> /// <param name="serialPort"></param> /// <remarks> /// Be sure to use suitable settings when creating the serial port. /// Default <see cref="BaudRate" /> and <see cref="DataBits" /> are exposed as constants. /// </remarks> public IDxxLA(ISerialMessagePort serialPort) { SerialPort = serialPort; SerialPort.MessageReceived += SerialPort_MessageReceived; }
public HC12Communication(ISerialMessagePort p) : base(p) { communicationType = Type.RF; }
public GPSWing(ISerialMessagePort serialMessagePort) : base(serialMessagePort) { }