⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 delphi中详细方法.txt

📁 mscomm组件问题的FAQ
💻 TXT
字号:
1) 在FORM的implementation部分添加以下声明 

var 
nn,x,y,sm,n,weidud,jinchad,firstpxl,secondpxl,a,b,longitude,longitudemargin,latitude:double; 
weidustr,weidustrcpy,longitudestr1cpy,longitudestrccpy, 
weidustr1,weidustr2,jinchastr,jinchastr1,jinchastr2,longitudestr1, 
longitudestr11,longitudestr12,longitudestrc,longitudestrc1,longitudestrc2:string; 
gpsstrlist:tstringlist; 
gpsstr,gpsstrcpy:string; 
gpsstrlen:integer; 

  2)在FORM的FORMSHOW事件中添加如下代码: 

procedure Tmainfrm.FormShow(Sender: TObject); 
begin 
mscomm1.CommPort:=1; //默认串口1 
mscomm1.InBufferSize:=1024; 
mscomm1.Settings:='600,n,8,1'; //波特率为600 
if not mscomm1.PortOpen then 
mscomm1.PortOpen:=true; //打开串口 
mscomm1.InBufferCount:=0; 
mscomm1.RThreshold:=512; 
mscomm1.InputLen:=0; 
timer1.Enabled:=false; //关闭定时器 
a:=6378245.0; b:=6356863.0; //参考椭球的长短轴 
firstpxl:=(a*a-b*b)/a/a; //第一偏心率 
secondpxl:=(a*a-b*b)/b/b; //第二偏心率 
end; 


  3)为定时器Timer1添加OnTimer事件添加如下代码: 

procedure Tmainfrm.Timer1Timer(Sender: TObject); 
var 
i:integer; 
tmpstr,strq,strq1,strq2,tmpstr1,tmpstr2:string; 
latitudestr,longitudestr:string; 
begin 
i:=0; 
gpsstr:=mscomm1.input; 
gpsstrcpy:=gpsstr; 
while strlen(pchar(gpsstr))>0 do begin 
tmpstr:=copy(gpsstr,pos(#10,gpsstr),pos(#13,gpsstr)-1); 
delete(gpsstr,1,pos(#10,gpsstr)); 
if copy(tmpstr,1,pos(',',tmpstr)-1)='$GPRMC' then begin 
delete(tmpstr,1,pos(',',tmpstr));//,strlen(pchar(tmpstr))-pos(',',tmpstr)+1); 
delete(tmpstr,1,pos(',',tmpstr)); 
if copy(tmpstr,1,pos(',',tmpstr)-1)='A' then begin 
delete(tmpstr,1,pos(',',tmpstr)); 
latitudestr:=copy(tmpstr,1,pos(',',tmpstr)-1); 
editlatitude.Text:=''; 
strq1:=copy(latitudestr,1,2); strq2:=copy(latitudestr,3,6); 
editlatitude.Text:=strq1+'°'+strq2+''''; 
weidud:=strtofloat(copy(latitudestr,1,2))+strtofloat(copy(latitudestr,3,6))/60; 
weidud:=weidud*3.141592654/180; 
delete(tmpstr,1,pos(',',tmpstr)); 
delete(tmpstr,1,pos(',',tmpstr)); 
longitudestr:=copy(tmpstr,1,pos(',',tmpstr)-1); 
longitude:=strtofloat(copy(longitudestr,1,3))+strtofloat(copy(longitudestr,4,6))/60; 
editlongitude.Text:=''; 
strq1:=copy(longitudestr,1,3); strq2:=copy(longitudestr,4,6); 
editlongitude.Text:=strq1+'°'+strq2+''''; 
jinchad:=abs(longitude-strtoint(centerlongitudestr)); 
jinchad:=jinchad*3.141592654/180; 
end; 
break; 
end; 
end; 
n:=a/sqrt(1-firstpxl*sin(weidud)*sin(weidud)); 
sm:=6367558.496*weidud-16036.48*sin(2*weidud)+16.828* 
  sin(4*weidud)-0.022*sin(6*weidud)+0.00003*sin(8*weidud); 
nn:=sqrt(firstpxl)*cos(weidud); 
x:=sm+n*sin(weidud)*cos(weidud)*jinchad*jinchad/2+n*jinchad* 
  jinchad*jinchad*jinchad*sin(weidud)*cos(weidud)*cos(weidud)*cos(weidud)*(5-   
  tan(weidud)*tan(weidud)+9*nn*nn+4*nn*nn*nn*nn)/24+n*power(jinchad,6)* 
  sin(weidud)*power(cos(weidud),5)*(61-58*tan(weidud)*tan(weidud)+tan(weidud) 
  *tan(weidud)*tan(weidud)*tan(weidud)+270*nn*nn*nn*nn-330*nn*nn*tan(weidud)*tan(weidud))/270; //纵坐标 
y:=n*jinchad*cos(weidud)+n*jinchad*jinchad*jinchad*cos(weidud)*cos(weidud)*cos(weidud)*(1-tan(weidud)*tan(weidud)+nn*nn)/6+n*power(jinchad,5)*power(cos(weidud),5)*(5-18*tan(weidud)*tan(weidud)+tan(weidud)*tan(weidud)*tan(weidud)* 
tan(weidud)+14*nn*nn-58*nn*nn*tan(weidud)*tan(weidud))/120; //横坐标 
editxcoord.Text:=formatfloat('00000.00',x); 
editycoord.Text:=formatfloat('00000.00',y); 
end; 


  4)为按钮“接收”添加代码: 

messagebeep(1); 
editlatitude.Text:=''; //接收前先清除显示内容 
editlongitude.Text:=''; 
editycoord.Text:=''; 
editxcoord.Text:=''; 
timer1.Enabled:= true; //打开计时器 

  5)为按钮“断开”添中代码: 

messagebeep(1); 
editlatitude.Text:=''; //清除显示内容 
editlongitude.Text:=''; 
editycoord.Text:=''; 
editxcoord.Text:=''; 
timer1.Enabled:= false; //关闭计时器 

  6)为按钮“返回”添加代码: 

procedure Tmainfrm.FormClose(Sender: TObject; var Action: TCloseAction); 
begin 
if application.MessageBox('您真的想退出吗?','GPS输入',mb_okcancel)=idok then begin 
timer1.Enabled:=false; 
if mscomm1.PortOpen then 
mscomm1.PortOpen:=false; 
gpsstrlist.Free; 
action:=cafree; 
end 
else 
action:=canone; 
end; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -