- gpstracer_src.zip
- DeviceApplication2
- DeviceApplication2
- bin
- Debug
- DeviceApplication2.exe
- DeviceApplication2.pdb
- Release
- DeviceApplication2.exe
- DeviceApplication2.pdb
- Form1.cs
- Form1.Designer.cs
- Form1.resx
- GpsTracer.csproj
- GpsTracer.csproj.user
- log.txt
- Mapper.cs
- 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
- DeviceApplication2.csproj.FileList.txt
- GpsTracer.csproj.FileList.txt
- 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
- Program.cs
- Properties
- reader.cs
- GpsTracer.sln
- gpstracer_demo.zip
- DeviceApplication2.exe
|
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.