dotMorten / NmeaParser

Library for handling NMEA message in Windows Desktop, Store, Phone, Universal, and Xamarin (Android + iOS), coming from files, bluetooth, serial port or any stream
https://dotmorten.github.io/NmeaParser/
Apache License 2.0
262 stars 89 forks source link

NmeaFileDevice does not stop when EOF #73

Closed sukesh-ak closed 4 years ago

sukesh-ak commented 4 years ago

Thank you for this component.

While using the following syntax to read out a text file content, after it reaches end of file it starts again from beginning. How do we stop once its EOF?

  var device = new NmeaFileDevice(filename, 1000);
  device.MessageReceived += Device_MessageReceived;

  Console.WriteLine($"\nOpening file {filename} and sending NMEA strings");
  await device.OpenAsync();
dotMorten commented 4 years ago

This is actually by design since it's meant for simulation (real datasources doesn't suddenly stop). I'd consider adding a property for stopping at the end, or at least an event that you can subscribe to and stop.

sukesh-ak commented 4 years ago

I agree about looping it for usual device cases other than NmeaFileDevice. I am using this library to send data to for testing simulation and unable to send just few lines from the file now.

Is this where the code needs to be changed? I took a quick look https://github.com/dotMorten/NmeaParser/blob/bbc7cb3589ebc06ebbf69d116c0aefc9dee613ba/src/NmeaParser/BufferedStreamDevice.cs#L128

dotMorten commented 4 years ago

Yeah perhaps just raise an event here, and check if the stream is still open after the event. That allows you to just cancel out in the eventhandler

sukesh-ak commented 4 years ago

Thank you for the changes @dotMorten

sukesh-ak commented 4 years ago

Can you publish this to NuGet?

dotMorten commented 4 years ago

2.1 is not quite ready yet. You can build yourself or get the artifacts from the action

sukesh-ak commented 4 years ago

Tried building but I think because of all the dependencies, it fails.

sukesh-ak commented 4 years ago

Ok No worries. I edited the project file and got it working for now.