How write program in c# (visual studio) which connects to the GPS USB port and display NMEA data in richTextBox?

StackOverflow https://stackoverflow.com/questions/22998579

  •  01-07-2023
  •  | 
  •  

Question

I have GPS on USB connections.

GPSusb

I use program Virtual GPS which automaticly search and connect withs this GPS and display NMEA data.

I want to write a simple program in C# which will be connect with this GPS and display NMEA data in RichTextBox in Real-Time.

I need help, because I don't know where and how to start. I'm beginner in c# but I'm determined because I dont have a lot of time. I'm working now on processing nmea data (and I wrote a large part of the program, which I needed to my school work (plot chart lang and latit, display routes, parse nmea itc)). I need tips, sample code, sample article or everything which can help.

Was it helpful?

Solution

Most GPS mice for PCs are detected/recognized as a USB ACM/COM/Serial device. That means they emulate a serial port. Have a look into your device-manager to find if thats the case and which COMx port it was connected to.

You can then use the SerialPort-class (http://msdn.microsoft.com/en-us/library/system.io.ports.serialport(v=vs.110).aspx) to connect to the mouse.

A object of type SerialPort has the really nice event called "DataReceived", which is getting called when data arrives in the input buffer or (when set) when a new line of NMEA data has arrived.

Be aware that the DataReceived event gets triggered in a different thread than your GUI-thread and that you will need to invoke into your Windows-Form (or similar).

OTHER TIPS

Ok problem is resolved. Little change's .ReadExisting(); -> .ReadLine(); and one another .Invoke -> .BeginInvoke. I found a lot of serial com program and nobody look at this problem .. In this change's isn't possible crash program when we stop (disconnect port) and again start etc.

private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
    {
        RxString = serialPort1.ReadLine();
        this.BeginInvoke(new EventHandler(DisplayText));
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top