Enhanced GPS sample update

Print This Post Print This Post

Some times ago I published my modded GPS_Sample code (see http://www.hjgode.de/wp/2009/05/12/enhanced-gps-sampe/), which is based on a MS GPSsample.

This time I added support for Int*rm*c CN50, which does NOT support reading raw GPS data using a serial connection. Instead the CN50 streams the data to the ‘communication’ port.

BTW: did you know how easy it is to create skins for use with MyMobiler?

The stream reader part is outsourced into a thread, which is based on my background thread class bgThread2 (see http://www.hjgode.de/wp/2010/06/01/mobile-development-easy-to-use-background-thread-with-gui-update/). It was very easy to implement the stream reading within the thread, so the GUI is not blocked during read waits.

        #region TheTHREAD
        private void myThreadStart()
        {
            System.Diagnostics.Debug.WriteLine("Entering thread proc");
            int _i=0;
            try
            {
                do
                {
                    //The blocking function...
                    char[] cSep = new char[] { '\r', '\n' };
                    int iRes = 0;
                    do
                    {
                        string sRes = "";
                        iRes = GPS_Sample8.ReadFileClass.readFile(_sCOM, ref sRes);
                        string[] sAll = sRes.Split(cSep);
                        foreach (string s1 in sAll)
                        {
                            SendData(bgWnd.Hwnd, iRes, s1);
                        }
                        //Application.DoEvents();
                        Thread.Sleep(100);
                    } while (iRes == 0);

                    System.Diagnostics.Debug.WriteLine("Thread sleeps...");
                    _i++;
                    Thread.Sleep(100);
                } while (bRunThread);
            }
            catch (ThreadAbortException)
            {
                System.Diagnostics.Debug.WriteLine("Thread will abort");
                bRunThread = false;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception in ThreadStart: " + ex.Message);
            }
            System.Diagnostics.Debug.WriteLine("ThreadProc ended");
        }
        #endregion

The main form code has some new functions to check for iCN50 and start/stop the stream reader background thread:

        #region CN50raw
        bgThread2 myStreamReaderThread;
        private void OpenStream()
        {
            //background thread already running?
            if (myStreamReaderThread == null)
            {
                string szPort="";
                szPort = GetGPSPort();
                if (szPort != "")
                {
                    //start a new thread
                    myStreamReaderThread = new bgThread2(szPort);
                    myStreamReaderThread.bgThread2Event += new bgThread2.bgThread2EventHandler(myStreamReaderThread_bgThread2Event);
                }
                else
                    AddRawText("No raw GPS port found");
            }
        }

        void myStreamReaderThread_bgThread2Event(object sender, bgThread2.BgThreadEventArgs bte)
        {
            AddRawText(bte.sString);
        }
        private void CloseStream()
        {
            if (myStreamReaderThread != null)
            {
                myStreamReaderThread.Dispose();
                Application.DoEvents();
                myStreamReaderThread = null;
            }
            Application.DoEvents();
            mnuRAWStart.Enabled = true;
            mnuRAWStop.Enabled = false;
        }
        #endregion

NEW 12. nov. 2012: project now hosted at google!

Downloads (VS2008 solution targeting WM6 SDK):

[Download not found]

updated source as of 9. nov 2011

[Download not found]

2 Comments

  1. Mark Zimmerman says:

    Thanks for all the good information. Are you able to share the CN50 skin for MyMobiler? I’m looking for one with the Alphanumeric keyboard, but if you have one just for the numberic keyboard I’m sure I could modify it for the alphanumeric.

    Thanks,
    Mark

  2. admin says:

    No problem

    sorry for the delay. The skin is now at http://www.hjgode.de/wp/2010/09/04/create-a-skin-for-mymobiler/

    regards

    Josef

Leave a Reply