C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

GPS Reader NMEA 0-183


Posted Date: 24 Mar 2004    Resource Type: Articles    Category: .NET Framework
Author: sibish n bMember Level: Bronze    
Rating: 1 out of 5Points: 4






using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using DBComm;
using System.Text;
using System.IO;
using System.Threading;
namespace testserial
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
Graphics g;
int hh,mm,ss;
public struct statu
{
public string number;
public string elevation;
public string azimuth;
public string SNR;
}
//statu[] satellite=new statu[10];
statu[] satellite=new statu[20];
static int statview;
//string sib;
static int index=0;
Font f;

private System.Windows.Forms.Button button1;
private System.ComponentModel.IContainer components;
int indexlast,indexfirst;
static string gpstring;
int length;
int l;
RS232 r=new RS232();
string s="hee";
private System.Windows.Forms.Timer timer1;
byte[] buff=new byte[4096];
StreamWriter log=new StreamWriter(@"c:\log.txt");
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
MemoryStream m4=new MemoryStream();
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.Label label14;
private System.Windows.Forms.Label label15;
public Thread t1;
public Form1()
{

//
// Required for Windows Form Designer support
//
InitializeComponent();
g=pictureBox1.CreateGraphics();
//
// TODO: Add any constructor code after InitializeComponent call
//
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.button1 = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.label14 = new System.Windows.Forms.Label();
this.label15 = new System.Windows.Forms.Label();
this.label13 = new System.Windows.Forms.Label();
this.label12 = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label11 = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.tabControl1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.tabPage1.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor = System.Drawing.Color.DarkGreen;
this.button1.ForeColor = System.Drawing.Color.GhostWhite;
this.button1.Image = ((System.Drawing.Image)(resources.GetObject("button1.Image")));
this.button1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.button1.Location = new System.Drawing.Point(424, 288);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 40);
this.button1.TabIndex = 0;
this.button1.Text = " Start";
this.button1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// timer1
//
this.timer1.Interval = 2000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Location = new System.Drawing.Point(0, 8);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(512, 360);
this.tabControl1.TabIndex = 1;
//
// tabPage2
//
this.tabPage2.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.tabPage2.Controls.Add(this.pictureBox2);
this.tabPage2.Controls.Add(this.button1);
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(504, 334);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "Main";
this.tabPage2.Click += new System.EventHandler(this.tabPage2_Click);
//
// pictureBox2
//
this.pictureBox2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox2.Location = new System.Drawing.Point(56, 43);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(232, 248);
this.pictureBox2.TabIndex = 1;
this.pictureBox2.TabStop = false;
//
// tabPage1
//
this.tabPage1.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.tabPage1.Controls.Add(this.label14);
this.tabPage1.Controls.Add(this.label15);
this.tabPage1.Controls.Add(this.label13);
this.tabPage1.Controls.Add(this.label12);
this.tabPage1.Controls.Add(this.pictureBox1);
this.tabPage1.Controls.Add(this.label11);
this.tabPage1.Controls.Add(this.label10);
this.tabPage1.Controls.Add(this.label9);
this.tabPage1.Controls.Add(this.label7);
this.tabPage1.Controls.Add(this.label8);
this.tabPage1.Controls.Add(this.label6);
this.tabPage1.Controls.Add(this.label5);
this.tabPage1.Controls.Add(this.label4);
this.tabPage1.Controls.Add(this.label3);
this.tabPage1.Controls.Add(this.label2);
this.tabPage1.Controls.Add(this.label1);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(504, 334);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "GPS";
//
// label14
//
this.label14.Location = new System.Drawing.Point(112, 264);
this.label14.Name = "label14";
this.label14.Size = new System.Drawing.Size(88, 23);
this.label14.TabIndex = 33;
this.label14.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label15
//
this.label15.Location = new System.Drawing.Point(32, 264);
this.label15.Name = "label15";
this.label15.Size = new System.Drawing.Size(80, 23);
this.label15.TabIndex = 32;
this.label15.Text = "Altitude";
this.label15.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label13
//
this.label13.Location = new System.Drawing.Point(112, 224);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(88, 23);
this.label13.TabIndex = 31;
this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label12
//
this.label12.Location = new System.Drawing.Point(32, 224);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(80, 23);
this.label12.TabIndex = 30;
this.label12.Text = "Speed";
this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Location = new System.Drawing.Point(296, 32);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(104, 104);
this.pictureBox1.TabIndex = 29;
this.pictureBox1.TabStop = false;
//
// label11
//
this.label11.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
this.label11.Location = new System.Drawing.Point(112, 176);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(88, 16);
this.label11.TabIndex = 28;
this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label10
//
this.label10.Location = new System.Drawing.Point(32, 176);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(80, 24);
this.label10.TabIndex = 27;
this.label10.Text = "No of Satellites In Use";
this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label9
//
this.label9.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(0)));
this.label9.Location = new System.Drawing.Point(32, 136);
this.label9.Name = "label9";
this.label9.TabIndex = 26;
this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label7
//
this.label7.ForeColor = System.Drawing.Color.Red;
this.label7.Location = new System.Drawing.Point(192, 104);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(32, 16);
this.label7.TabIndex = 25;
this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label8
//
this.label8.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
this.label8.Location = new System.Drawing.Point(104, 104);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(88, 16);
this.label8.TabIndex = 24;
this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label6
//
this.label6.Location = new System.Drawing.Point(32, 104);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(72, 16);
this.label6.TabIndex = 23;
this.label6.Text = "Longitude";
this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label5
//
this.label5.ForeColor = System.Drawing.Color.Red;
this.label5.Location = new System.Drawing.Point(192, 64);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(32, 16);
this.label5.TabIndex = 22;
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label4
//
this.label4.Location = new System.Drawing.Point(32, 64);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(72, 16);
this.label4.TabIndex = 21;
this.label4.Text = "Latitude";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label3
//
this.label3.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
this.label3.Location = new System.Drawing.Point(104, 64);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(88, 16);
this.label3.TabIndex = 20;
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.Location = new System.Drawing.Point(32, 32);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 16);
this.label2.TabIndex = 19;
this.label2.Text = "Time";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label1
//
this.label1.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
this.label1.Location = new System.Drawing.Point(104, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(104, 16);
this.label1.TabIndex = 18;
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem3,
this.menuItem4});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2});
this.menuItem1.Text = "File";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "Exit";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "Edit";
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem5,
this.menuItem6});
this.menuItem4.Text = "Help";
//
// menuItem5
//
this.menuItem5.Index = 0;
this.menuItem5.Text = "Help";
//
// menuItem6
//
this.menuItem6.Index = 1;
this.menuItem6.Text = "About";
//
// groupBox1
//
this.groupBox1.Location = new System.Drawing.Point(0, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(512, 8);
this.groupBox1.TabIndex = 2;
this.groupBox1.TabStop = false;
this.groupBox1.Enter += new System.EventHandler(this.groupBox1_Enter);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.ClientSize = new System.Drawing.Size(512, 369);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.tabControl1);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.ForeColor = System.Drawing.SystemColors.HotTrack;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.KeyPreview = true;
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = " Gulliver\'s Genie";
this.Load += new System.EventHandler(this.Form1_Load);
this.tabControl1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

void ha()
{

r.CommPort=1;
r.BaudRate=RS232.BaudRates.Baud4800;
r.DataSize=RS232.DataSizes.Size8;
r.Parity=RS232.Parities.None;
r.StopBit=RS232.StopBits.Bit1;
r.InBufferSize=4096;
r.InputLength=0;
r.ReceiveThreshold=1;


if(!r.PortOpen)
r.PortOpen=true;


/*_rs232.CommPort = _port
_rs232.BaudRate = _baud
_rs232.DataSize = _data
_rs232.Parity = _parity
_rs232.StopBit = _stopBit
' or
' _rs232.Settings = "9600, n, 8, 1"
_rs232.InBufferSize = 4096
_rs232.InputLength = 0 ' read everything in the buffer.
_rs232.ReceiveThreshold = 1
_rs232.PortOpen = True

*/


//r.Output(buff);
//t1=new Thread(new ThreadStart(hee));
//t1.Start();
timer1.Enabled=true;
//Thread.Sleep(1000);
//for(;;)
//{

//}

}


private void button1_Click(object sender, System.EventArgs e)
{
if(button1.Text=="Start")
{

button1.Text="Stop";
button1.BackColor=Color.Red;
button1.ForeColor=Color.GhostWhite;
buff.Initialize();
t1=new Thread(new ThreadStart(hee));
ha();


}
else
{
try
{
t1.Abort();

}
catch
{
}
button1.Text="Start";
button1.BackColor=Color.DarkGreen;
button1.ForeColor=Color.GhostWhite;

}
//t1=new Thread(new ThreadStart(ha));
//t1.Start();


}



void drawsat()
{

// Monitor.Enter(this);
//int num,azi,ele;
f=new Font("Arial",8,FontStyle.Regular);

Pen p=new Pen(Color.Black);
SolidBrush b4=new SolidBrush(Color.White);
g.FillEllipse(b4,4,4,92,92);
g.DrawEllipse(p,4,4,92,92);
g.DrawEllipse(p,30,30,40,40);
SolidBrush b5=new SolidBrush(Color.Black);



g.FillRectangle(b4,46,1,10,10);
g.FillRectangle(b4,46,91,10,10);
g.FillRectangle(b4,91,46,10,10);
g.FillRectangle(b4,-1,46,10,10);

g.DrawString("N",f,b5,48,-1);
g.DrawString("S",f,b5,48,89);
g.DrawString("E",f,b5,93,44);
g.DrawString("W",f,b5,1,44);

//num=04;
//ele=23;
//azi=214;
plotsat();

//Monitor.Exit(this);
}
void plotsat()
{
/*double x,y;
//const float pi=3.14159265358979F;
azi=(azi-90)%360;
ele=(int)(ele/2);
x=72+ele*System.Math.Cos((azi*System.Math.PI)/180);
y=72+ele*System.Math.Sin((azi*System.Math.PI)/180);
Console.WriteLine("x is {0} y is {1}",x,y);
Pen p=new Pen(Color.Red);
g.DrawEllipse(p,(float)x,(float)y,2,2);
*/
//if(statview!=0)
//{
SolidBrush grey1=new SolidBrush(Color.Gray);
SolidBrush red1=new SolidBrush(Color.Red);
SolidBrush black=new SolidBrush(Color.Black);
int azi,eli,num;
double x,y;
for(int i=0;i {
num=System.Convert.ToInt32(satellite[i].number);
eli=System.Convert.ToInt32(satellite[i].elevation);
eli=eli-15;
azi=System.Convert.ToInt32(satellite[i].azimuth);
x=50-6+eli*System.Math.Cos((azi*System.Math.PI)/180);
y=50-5+eli*System.Math.Sin((azi*System.Math.PI)/180);
// Console.WriteLine("x is {0} y is {1}",x,y);
Pen p=new Pen(Color.Black);

if(satellite[i].SNR=="")
g.FillRectangle(grey1,(float)x,(float)y,12,10);

if(satellite[i].SNR!="")
{
if(System.Convert.ToInt16(satellite[i].SNR)>=3)
g.FillRectangle(red1,(float)x,(float)y,12,10);
}
// Console.WriteLine("SNR is {0}",satellite[i].SNR);


g.DrawRectangle(p,(float)x,(float)y,12,10);
g.DrawString(satellite[i].number,f,black,(float)x+1,(float)y-1);

//g.DrawEllipse(p,(float)x,(float)y,3,3);


}


}




void time(string str)
{
string h1=str.Substring(0,2);
string m1=str.Substring(2,2);
string s1=str.Substring(4,2);
//Console.WriteLine("hour {0} minute {1} second {2}",h1,m1,s1);
hh=Convert.ToInt16(h1);
mm=Convert.ToInt16(m1);
ss=Convert.ToInt16(s1);
if(mm>=30)
hh=hh+1;
hh=(hh+5)%24;
mm=(mm+30)%60;



//h1=hh.ToString();
h1=Convert.ToString(hh);
m1=Convert.ToString(mm);
s1=Convert.ToString(ss);

if(ss<=9)
label1.Text=h1+":"+m1+":"+"0"+s1;
else
label1.Text=h1+":"+m1+":"+s1;


}
void lati(string str)
{
string w1=str.Substring(0,2);
string w2=str.Substring(2,str.Length-2);
w1=w1+"'"+w2;
label3.Text=w1;
}
void longi(string str)
{
string w1=str.Substring(1,2);
string w2=str.Substring(3,str.Length-3);
w1=w1+"'"+w2;
label8.Text=w1;
}

void hello1(string str)
{
string[] a=new string[25];
int i=0,r,length,z;
z=str.LastIndexOf(',');
length=str.Length;
string pr=str.Substring(z+1,length-z-1);
//Console.WriteLine("pr is {0}",pr);
//string tmp;
do
{
r=str.IndexOf(',');
a[i]=str.Substring(0,r);
//Console.WriteLine("a[i] is {0} r is {1}",a[i],r);
length=str.Length;
str=str.Substring(r+1,length-r-1);
//Console.WriteLine("str is {0}",str);
//str=tmp;
i++;
//Console.WriteLine("i is {0} tmp is {1} Length is{2}",i,tmp,length);

//z=a[i].IndexOf('F');
//Console.WriteLine("z is {0}",z);
}while(!str.Equals(pr));
r=str.IndexOf('*');
a[i]=str.Substring(0,r);
string q1=a[0];
//Console.WriteLine("a[0] is ",a[0]);

switch(q1)
{
//Parse $GPGGA
case "$GPGGA":
// Console.WriteLine("poda");
time(a[1]);
//label1.Text=a[1];
lati(a[2]);
//label3.Text=a[2];
label5.Text=a[3];
longi(a[4]);
//label8.Text=a[4];
label7.Text=a[5];
int sat=System.Convert.ToInt16(a[6]);
if(sat==0)
label9.Text="Sat not Fixed";
else
label9.Text="Sat Fixed";
label11.Text=a[7];
label14.Text=a[9]+"m";
break;
//Parse $GPGSV
case "$GPGSV":
statview=System.Convert.ToInt16(a[3]);
int mn,tn;
//int sibi=1;
mn=System.Convert.ToInt16(a[2]);
tn=System.Convert.ToInt16(a[1]);
satellite[index].number=a[4];
satellite[index].elevation=a[5];
satellite[index].azimuth=a[6];
satellite[index].SNR=a[7];

index++;
satellite[index].number=a[8];
satellite[index].elevation=a[9];
satellite[index].azimuth=a[10];
satellite[index].SNR=a[11];
index++;
satellite[index].number=a[12];
satellite[index].elevation=a[13];
satellite[index].azimuth=a[14];
satellite[index].SNR=a[15];
index++;
satellite[index].number=a[16];
satellite[index].elevation=a[17];
satellite[index].azimuth=a[18];
satellite[index].SNR=a[19];
index++;
if(mn==tn)
{
index=0;
drawsat();
}

break;

case "$GPVTG":
//Console.WriteLine(" speed is {0}",a[7]);
label13.Text=a[7]+" km/h";

break;

default:
break;
}
}
void nmea(string q1)
{
int testfirst,testlast,t1,t2;
testfirst=q1.IndexOf('$');
testlast=q1.IndexOf('*');
t1=q1.IndexOf("GP");
t2=q1.LastIndexOf("GP");
Console.WriteLine("t1 is {0} t2 is {1}",t1,t2);


if(t1==t2)
{
if(testfirst!=-1&&testlast!=-1)
{
//string q2=q1.Substring(testfirst,q1.Length-testfirst);
//testfirst=q2.IndexOf("GP");
//if(testfirst!=-1)
// q1=q2.Substring(testfirst,q2.Length-testfirst);

//log.WriteLine(q1);
//log.Flush();



hello1(q1);
}


}
}

private void parse(string str)
{
// Monitor.Enter(this);
int z,z1,length;
string q1,q2,tstr;
do{
length=str.Length;
z=str.IndexOf('$');
z1=str.IndexOf('*');
q1=str.Substring(z,z1);
//z=q1.IndexOf('$');
//if(z!=-1)
//q1=q1.Substring(z,z1);
//Console.WriteLine("1st string is {0}",q1);
nmea(q1);
tstr="str "+q1;
//log.WriteLine(tstr);
// log.Flush();
q2=str.Substring(z1+1,length-z1-1);
//Console.WriteLine("rest string is {0}",q2);
str=q2;

}while(z>-1||z1>-1);





//Monitor.Exit(this);
}


void hee()
{
//t1.Join();
// Monitor.Enter(this);
for(;;)
{
try
{
l=r.InBufferCount;
s=r.Input;
//r.Break=true;
// Console.WriteLine("Length is {0}",l);
//r.EOFEnable=true;
indexfirst=s.IndexOf('$');
indexlast=s.LastIndexOf('\n');
length=s.Length;
//Console.WriteLine("indexfirst is {0} indexlast is {1}",indexfirst,indexlast);

//Thread.Sleep(100);



if(indexfirst!=-1)
gpstring=s.Substring(indexfirst,length-indexfirst-1);
if(indexlast!=-1)
{
gpstring=gpstring+s.Substring(0,indexlast);
//int t=gpstring.IndexOf('$',5);
//if(t!=-1)
// Console.WriteLine("invalid string");
//gpstring+="";
// Thread.Sleep(1000);
// gpstring1=gpstring+"?";

Console.WriteLine("gpstring is {0}",gpstring);
parse(gpstring);

// log.WriteLine(gpstring);
// log.Flush();
gpstring="";
}

//if(indexfirst!=-1)
//gpstring=s.Substring(indexfirst,length-indexfirst-1);





/*if(index==-1)
{
gpstring=s;
}
else
{
gpstring=gpstring+s;
Console.WriteLine("gp string is {0}",gpstring);
}
*/
//Console.WriteLine(s);

//Console.WriteLine("hee");

}
catch
{
}


t1.Suspend();
// Monitor.Exit(this);
}

}

private void timer1_Tick(object sender, System.EventArgs e)
{
//t1.Join();
//t1.Abort();

if(t1.ThreadState==ThreadState.Unstarted)
t1.Start();

else if(t1.ThreadState==ThreadState.Suspended)
t1.Resume();
}

private void tabPage2_Click(object sender, System.EventArgs e)
{

}
/*private void Form_Exit(object sender,System.EventArgs e)
{
t1.Abort();
}
*/
private void Form1_Load(object sender, System.EventArgs e)
{
button1.Text="Start";
}

private void groupBox1_Enter(object sender, System.EventArgs e)
{

}

private void menuItem2_Click(object sender, System.EventArgs e)
{
//try
//{
//t1.Start();
t1.Abort();

//}
//catch
//{
//}
Application.ExitThread();
Application.Exit();


}
}
}



&

			


Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Operator overloading in C#
Previous Resource: Retrieving the name and parameters of current method using Reflection
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use