#region 读取GPS
private void opengps(string ComPoint)
{
ss_port.PortNum = ComPoint;
ss_port.BaudRate = 4800;
ss_port.ByteSize = 8;
ss_port.Parity = 0;
ss_port.StopBits = 1;
ss_port.ReadTimeout = 1000;
try
{
if (ss_port.Opened)
{
ss_port.Close();
ss_port.Open();
timer1.Enabled=true;
}
else
{
ss_port.Open();//打开串口
timer1.Enabled=true;
}
}
catch
{
// MessageBox.Show("读取GPS错误!" ,"系统提示");
}
}
private void timer1_Tick(object sender, System.EventArgs e)
{
if (ss_port.Opened)
gpsread();
else
ss_port.Open();//打开串口
}
private void gpsread()
{
byte[] aa=ss_port.Read(512);
string gpsinfo =System.Text.Encoding.ASCII.GetString(aa,0,aa.Length);
GetParam.GpsLongitude=ss_port.GetGPS(gpsinfo,"X");
GetParam.GpsLatitude=ss_port.GetGPS(gpsinfo,"Y");
GetParam.GpsSpeed=ss_port.GetGPS(gpsinfo,"V");
GetParam.GpsTime=ss_port.GetGPS(gpsinfo,"T");
if(GetParam.GpsLongitude=="-1")
GetParam.GpsState="0";
if(GetParam.GpsLongitude=="V" && GetParam.GpsLatitude=="V")
GetParam.GpsState="0";
if(GetParam.GpsLongitude!="-1" && GetParam.GpsLongitude!="V")
GetParam.GpsState="1";