1

Can anyone help with C# code for reading GPS sensor connected to the RPISER port of Grove Pi (hat for Raspberry Pi)?

1
  • Please add a link to your GPS sensor in your question.
    – goobering
    Jul 14, 2016 at 14:09

1 Answer 1

1

To start of with here is a simple serial code you can transform to your UAT application.

namespace ConsoleApplication1
{
    class Program
    {
        public static void Main(string[] args)
        {
            SerialPort sp = new SerialPort("/dev/ttyAMA0", 115200, Parity.None, 8, StopBits.One);
            sp.Open();
            for (int index = 0; index < 10; index++)
            {
                string result = string.Format("{0} Testing", index);
                sp.Write(result);
            }
            sp.Close();
        }
    }
}

The parameters provided in new SerialPort need to be as required for the GPS device. Typically now a days this is the frequent usage but it may vary. If you get junk output it could be the baud rate.

You may have to create a threaded/delegated implementation of the serial read to raise events in your code otherwise you will block your UI. But start with that first to confirm you can get data back from the GPS before continuing.

You can find a ton of open source application on the Microsoft Pi site Find projects that may help you, read the code, find what interests you and adopt it in your project.

PRO TIPS

  1. You can create code on your PC Visual Studio Community or Mac/Linux using Monodevlop to get test code going. Although using Visual Studio the project compiles on your machine and deploys to Pi any way.
  2. Always create separate classes for your code. It follows the Object Orientated Programming Pattern. You may want to look at some examples or do some basic C# online course. (Sorry, I dont know your competency in programming so its a good place to start)
  3. Even if testing. Once you get working code and need to transform it, create a new class and start changing it in that class.
  4. Doing this will help you create background threads by starting class based code in threaded object that raise events in your main thread. Keeping your UI unblocked. There are many ways to achieve this and is a may be of a expert level requirement to get it going.
  5. Obviosly, if you dont need UI, just build your read into the main thread. You can save data to database or relay it to another server if that is the only purpose.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.