void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { try { System.IO.Ports.SerialPort p = ((System.IO.Ports.SerialPort)sender); string data = p.ReadExisting(); string[] strArr = data.Split('$'); for (int i = 0; i < strArr.Length; i++) { string strTemp = strArr[i]; string[] nmea = strTemp.Split(','); if (nmea[0] == "GPRMC") { serialPort1 = p; //Latitude if (!String.IsNullOrEmpty(nmea[8])) { degree = Convert.ToDouble(nmea[8]);// -(lines[11] == "E" ? 1 : -1) * (String.IsNullOrEmpty(lines[10]) ? 0 : Convert.ToDouble(lines[10])); pitch = 0; tilt = 0; pictureBox1.Image = Compass.DrawCompass(degree, pitch, 80, tilt, 80, pictureBox1.Size); } } } } catch { } }
public Form1() { InitializeComponent(); this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; this.Resize += Form1_Resize; // pictureBox1.Image = Compass.DrawCompass(162.5, -80, 80, -30, 80, pictureBox1.Size); pictureBox1.Image = Compass.DrawCompass(degree, pitch, 80, tilt, 80, pictureBox1.Size); ConnectGPS(); //t.Interval = 50; //t.Tick += t_Tick; //t.Enabled = true; }
//void t_Tick(object sender, EventArgs e) //{ // if ((tilt > 78.2 || tilt < -78.2) && tilt != 0) // opT = opT * -1; // if ((pitch > 78.2 || pitch < -78.2) && pitch != 0) // opP = opP * -1; // if ((degree > 359.2 || degree < 0.8) && degree != 0) // opD = opD * -1; // pitch = pitch + opP * 0.8; // tilt = tilt + opT * 0.5; // degree = degree + opD * 0.8; // pictureBox1.Image = Compass.DrawCompass(degree, pitch, 80, tilt, 80, pictureBox1.Size); //} void Form1_Resize(object sender, EventArgs e) { pictureBox1.Image = Compass.DrawCompass(degree, pitch, 80, tilt, 80, pictureBox1.Size); }