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

SerialPortDevice does not exist #21

Closed fjclip99 closed 8 years ago

fjclip99 commented 8 years ago

I am creating a visual studio universal app and i am using the UWP sample... But somehow on the line var device = new NmeaParser.SerialPortDevice(); i get the error SerialPortDevice does not exist in the namespace...

dotMorten commented 8 years ago

Are you using the nuget package? Dont think I updated it with UWP support. You'll have to reference the uwp project instead

fjclip99 commented 8 years ago

I have the SharpGIS.NmeaParser v 1.5.1 installed. How do I reference the uwp project?

dotMorten commented 8 years ago

Download the source, add project to your solution, then add a project reference.

fjclip99 commented 8 years ago

Ok, fixed that. Now I have one more question. Is the private void device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs args) event called always there is incomming data on the serial port?

dotMorten commented 8 years ago

It's called every time there's a valid full message received (so normally yes always)

fjclip99 commented 8 years ago

I am using just this code for now but i am not getting the event triggered:

private void device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs args)
{
    textBlock.Text = "EVENT TRIGGERED";
}

And the init. code:

private async void InitSerial() // Initialize Serial
{
    string dev = SerialDevice.GetDeviceSelector("UART0");
    var inf = await DeviceInformation.FindAllAsync(dev);
    SerialPort = await SerialDevice.FromIdAsync(inf[0].Id);
    dataReader = new DataReader(SerialPort.InputStream);

    SerialPort.BaudRate = 9600;
    SerialPort.Parity = SerialParity.None;
    SerialPort.StopBits = SerialStopBitCount.One;
    SerialPort.DataBits = 8;
    SerialPort.Parity = SerialParity.None;
    SerialPort.Handshake = SerialHandshake.None;
    var device = new NmeaParser.SerialPortDevice(SerialPort);
    device.MessageReceived += device_MessageReceived;
    await device.OpenAsync();
}

Oh, and i am sending a string from A0 to A255 to the serial port.

dotMorten commented 8 years ago

Did you try the test app and see if that work? Are you sure those are the correct parameters for your device?

Not really sure why you are sending data.

Lastly don't update your UI in that event. It fires on a background thread and would cause a crash. You have to use the dispatcher to switch to the UI thread.

dotMorten commented 8 years ago

Updated the nuget package to 1.6.0 with support for UWP (and iOS and Android - Xamarin) https://www.nuget.org/packages/SharpGIS.NmeaParser/1.6.0

fjclip99 commented 8 years ago

The parameters are correct i think, because the SerialWrite that i created is working and it is sending, however the event doesen't want to trigger... I have installed the 1.6.0 and still nothing...

dotMorten commented 8 years ago

How do you know you're sending? What GPS device is this where you can just send 0..255 and know it received it? Very few GPS devices support being written to and if they do, it's usually only RTCM data.

Serial ports are old tech. If you get any of these parameters wrong, nothing will happen. No error, just nothing. No data is sent or received.

dotMorten commented 8 years ago

Also are you sure about your "UART0" parameter ?

fjclip99 commented 8 years ago

No no, i am not using the GPS device... I forgot to mention.... I am using an Arduino... I need to make a communication between the Arduino and the Raspberry PI... I have the SerialWrite function created, it is sending the data and the Arduino is receiving it... Now I only need to make the SerialRead on the Raspberry pi (Windows universal app) so that i can receive messages like (A255, B125, etc...).

dotMorten commented 8 years ago

Huh? That's not what this library is for. You don't need this library at all.