Using in a Windows Universal App (SerialPort)

Morten Nielsen edited this page May 30, 2015 · 2 revisions

To use the NMEA Parser against a serial device in a Windows 10+ Universal app, ensure the serial device capability is enabled by opening package.appxmanifest in a text editor, and add the following to the <Capabilities> section:

    <DeviceCapability Name="serialcommunication" > 
      <Device Id="any"> 
        <Function Type="name:serialPort"/> 
      </Device> 
    </DeviceCapability> 
var selector = SerialDevice.GetDeviceSelector("COM3"); //Get the serial port on port '3'
var devices = await DeviceInformation.FindAllAsync(selector);
if(devices.Any()) //if the device is found
{
	var deviceInfo = devices.First();
	var serialDevice = await SerialDevice.FromIdAsync(deviceInfo.Id);
	//Set up serial device according to device specifications:
	//This might differ from device to device
	serialDevice.BaudRate = 4800;
	serialDevice.DataBits = 8;
	serialDevice.Parity = SerialParity.None;
	var device = new NmeaParser.SerialPortDevice(serialDevice);
	device.MessageReceived += device_NmeaMessageReceived;
}
...
private void device_NmeaMessageReceived(NmeaParser.NmeaDevice sender, NmeaParser.Nmea.NmeaMessage args)
{
   // called when a message is received
}
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.