Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

A GPS tracer application for Windows Mobile CE 5

, 22 May 2007
A simple GPS tracer developed for Windows Mobile 2005 on Compact Framework 2.0 SDK
gpstracer_demo.zip
DeviceApplication2.exe
gpstracer_src.zip
DeviceApplication2
DeviceApplication2
bin
Debug
DeviceApplication2.exe
DeviceApplication2.pdb
Release
DeviceApplication2.exe
DeviceApplication2.pdb
GpsTracer.csproj.user
obj
Debug
DeviceApplication2.csproj.GenerateResource.Cache
DeviceApplication2.exe
DeviceApplication2.Form1.resources
DeviceApplication2.pdb
DeviceApplication2.Properties.Resources.resources
GpsTracer.csproj.GenerateResource.Cache
GpsTracer.Form1.resources
GpsTracer.Properties.Resources.resources
Refactor
ResolveAssemblyReference.cache
TempPE
Properties.Resources.Designer.cs.dll
Release
DeviceApplication2.csproj.GenerateResource.Cache
DeviceApplication2.exe
DeviceApplication2.pdb
GpsTracer.csproj.GenerateResource.Cache
GpsTracer.Form1.resources
GpsTracer.Properties.Resources.resources
Refactor
ResolveAssemblyReference.cache
TempPE
Properties.Resources.Designer.cs.dll
Properties
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.IO.Ports;


namespace GpsTracer
{
    public class reader 
    {
        static private System.IO.Ports.SerialPort m_serialPort1;
        static private Thread m_th=null;
        static private bool m_run=false;
        static public String m_readed="";
        static private String m_port;
        static private bool m_demo;
        public delegate void DataReceivedEventHandler(string data);
        public event DataReceivedEventHandler dataReceived;

        public reader(String port)
        {
         m_port = port;
        }

        public void start(bool demo)
        {
            m_demo = demo;
            

            if (m_th == null)
            {
                if(!demo && m_serialPort1==null)
                {
                    m_serialPort1 = new System.IO.Ports.SerialPort(m_port);
                }
                m_th = new Thread(methodTh);
            }
            m_run = true;
            m_th.Start();
        }

        public void stop()
        {
            m_run = false;
            Thread.Sleep(500);
            if (!m_demo)
            {
                m_serialPort1.Close();
            }
            if (m_th != null)
            {
                m_th.Abort();
                m_th = null;
            }
        }

        

        private void methodTh()
        {
            if (!m_demo)
            {
                m_serialPort1.Open();
            }

            byte[] buffer= new byte[100];
            while (m_run)
            {
                Thread.Sleep(1000);
                if (m_demo)
                {
                    dataReceived(randomString());
                }
                else
                {
                    m_readed = m_serialPort1.ReadLine();
                    if (m_readed.Length > 0)
                    {
                        dataReceived(m_readed);
                    }
                }
            }
        }

        private String randomString()
        { 
            Random r = new Random();
            String rSecond1 = (int)(r.NextDouble() * 10 - 1) + "" + (int)(r.NextDouble() * 10 - 1) + "" + (int)(r.NextDouble() * 10 - 1) + "" + (int)(r.NextDouble() * 10 - 1);
            String rSecond2 = (int)(r.NextDouble() * 10 - 1) + "" + (int)(r.NextDouble() * 10 - 1) + "" + (int)(r.NextDouble() * 10 - 1) + "" + (int)(r.NextDouble() * 10 - 1);
            String rPrime1 = (int)(r.NextDouble() * 1 - 1) + "";
            String rPrime2 = (int)(r.NextDouble() * 1 - 1) + "";
            
            return "$GPRMC,170111,A,434"+ rPrime1 + "." + rSecond1+",N,0111" + rPrime2 + "." + rSecond2+",W,000.0,360.0,060199,017.5,W*73";
         }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

leonardosalvatore
Architect Giuneco http://www.giuneco.it
Italy Italy
IT is not only work, it is a hobbie, for that i post here!

| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 22 May 2007
Article Copyright 2006 by leonardosalvatore
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid