NmeaParser/docs/concepts/SerialPortNetCore.md

17 lines
622 B
Markdown
Raw Normal View History

2020-01-20 03:30:43 +01:00
# Creating a Serial Port device in a .NET Core app
```csharp
2020-01-29 06:15:51 +01:00
string portname = "COM3"; // Change to match the name of the port your device is connected to
int baudrate = 9600; // Change to the baud rate your device communicates at (usually specified in the manual)
var port = new System.IO.Ports.SerialPort(portname, baudrate);
2020-01-20 03:30:43 +01:00
var device = new NmeaParser.SerialPortDevice(port);
2020-01-29 06:15:51 +01:00
device.MessageReceived += OnNmeaMessageReceived;
2020-01-20 03:30:43 +01:00
device.OpenAsync();
...
2020-01-29 06:15:51 +01:00
private void OnNmeaMessageReceived(NmeaParser.NmeaDevice sender, NmeaParser.NmeaMessageReceivedEventArgs args)
2020-01-20 03:30:43 +01:00
{
// called when a message is received
}
```