1. Prepare
GPS (Global Positioning System), which uses 24 GPS satellite ranging and time-measuring functions for global positioning, in many systems, such as airport navigation systems, rental vehicle management and dispatch systems, and river basin disaster information management and forecasting systems, GPS has been widely used. In this paper, the GPS data collection is realized by using MSComm control, which can provide location data for information management and command scheduling.
In this paper, using the asynchronous serial transmission of GPS, the data acquisition of Garmin 12C according to the NMEA-0183 protocol is collected to the microcomputer, and the geographical coordinates received are transformed into rectangular coordinate.
Create a new project in the Delphi 5.0 IDE, named Gpsreceiver, where four tedit controls are placed on the main interface to display the received geographical coordinates and converted rectangular coordinates with the name attribute: Editlatitude, Editlongitude, Editxcoord and Editycoord; place three buttons below four Tedit controls for control and exit programs for data reception, with the "Caption" property "Receive", "disconnect" and "return" respectively A TTimer control is placed anywhere on the interface, its property interval value is "1000", which is mainly used to receive GPS data every second; a Tmscomm control. The interface after the program is run is shown in Figure 1:
Figure 1
2, write code
1 Add the following statement to the implementation section of the form
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 Add the following code to the Formshow event in form:
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;