要求建立TCP连接,改传输数据的格式如:>位置,,鄂A12345,,本地,武汉,000003$GPRMC 114229.487 A 2832.2475 N 12058.3416 E 0.13 309.62 120598 *10#1 ,<
另外据说ClientSocket2.Socket.SendBuf(SendGpsMsg,SizeOf(SendGpsMsg));是传不了数据的``
总程序在下面
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
tt,gpsmsg,sTdate:string;
begin
tt:=Socket.Receivetext;
Memo1.Text:=Memo1.Text+#10#13+tt;
if pos('位置',tt)<>0 then
begin
separateData(tt); //State:=#0;
Move(SendGpsMsg.CarNumber,str[3],SizeOf(SendGpsMsg.CarNumber));
// SendGpsMsg.CarNumber:=ASCtoString(IntToHex(byte(str[3])));
gpsmsg:=str[6]+' '+str[3]+' '+str[7];
PutReviewInfo(gpsmsg);
if S[5]='A' then
SendGpsMsg.GpsState:=byte('1')
// Move(SendGpsMsg.GpsState,'1',SizeOf(SendGpsMsg.GpsState));
else if S[5]='V' then
SendGpsMsg.GpsState:=byte('0');
sTdate:='20'+copy(S[12],5,2)+copy(S[12],3,2)+copy(S[12],1,2)+copy(S[4],1,6);
Move(SendGpsMsg.Tdate,sTdate,SizeOf(SendGpsMsg.Tdate));
SendGpsMsg.Abcd:= GetLon; // htonl(GetLon);
// Move(SendGpsMsg.Abcd,htonl(GetLon),SizeOf(SendGpsMsg.Abcd));
SendGpsMsg.Abcde:= GetLat; //htonl(GetLat);
SendGpsMsg.Speed:= floattostr(GetSpeed);
SendGpsMsg.Angle:= S[11];
SendGpsMsg.Alarm:= byte('0');
SendGpsMsg.CarState:= byte('0'); ClientSocket2.Socket.SendBuf(SendGpsMsg,SizeOf(SendGpsMsg));
end;
end;
function TForm1.GetSpeed:double;
var
Speed,data:string;
begin if S[10]='' then S[10]:='0';
try Speed:=FloatToStr(StrToFloat(S[10])*1.852);
data:='.';
if StrPos(pChar(Speed),pChar(data)) = nil then
Result:=StrToFloat(Speed)
else Result:=StrToFloat(copy(Speed,1,pos('.',Speed)+1));
except
Result:=0.0;
end;
end;
function TForm1.GetLon:double;
var I,J:integer;
Lon:string;
LonDeg:pChar;
LonMin:pChar;
begin Lon:=string(S[8]);
if Lon<>'' then
begin
GetMem(LonDeg,Length('000'));
StrCopy(LonDeg,pChar(string(Lon[1])));
for I:=2 to 3 do
begin StrCat(LonDeg,pChar(string(Lon[I])));
end; GetMem(LonMin,Length('000'));
StrCopy(LonMin,pChar(string(Lon[4])));
for J:=5 to Length(Lon) do
begin StrCat(LonMin,pChar(string(Lon[J])));
end;
try
Result:=StrToFloat(string(LonDeg))
+StrToFloat(string(LonMin))/60 ;
if S[9]='W' then Result:=Result*(-1);
except
Result:=0.0;
end;
FreeMem(LonDeg);
FreeMem(LonMin);
end
else Result:=0.0;
end;
{}
function TForm1.GetLat:double;
var I,J:integer;
Lat:string;
LatDeg:pChar;
LatMin:pChar;
begin Lat:=string(S[6]);
if Lat<>'' then
begin
GetMem(LatDeg,Length('000'));
StrCopy(LatDeg,pChar(string(Lat[1])));
StrCat(LatDeg,pChar(string(Lat[2])));
GetMem(LatMin,Length('000'));
StrCopy(LatMin,pChar(string(Lat[3])));
for J:=4 to Length(Lat) do
begin StrCat(LatMin,pChar(string(Lat[J])));
end;
try
Result:=StrToFloat(string(LatDeg))
+StrToFloat(string(LatMin))/60 ;
if S[7]='s' then Result:=Result*(-1);
except
Result:=0.0;
end;
FreeMem(LatDeg);
FreeMem(LatMin);
end
else Result:=0.0;
end;
procedure TForm1.separateData(var pData:string);
var
A,B,I:integer;
Data:string;
begin
A:=0;
B:=2;
Data:=pData;
for I:=2 to Length(Data) do
begin
if (Data[I]=',') or (Data[I]='<') then
begin
A:=A+1;
str[A]:=Copy(Data,B,I-B);
B:=I+1; end
end;
end;
procedure TForm1.PutReviewInfo(var pInfo:string);
var
info:string;
I,A,B:integer;
begin A:=0;
B:=1;
info:=pInfo;
for I:=1 to Length(info) do
begin
if (info[I]=' ') or (info[I]='<') then
begin
A:=A+1;
S[A]:=Copy(info,B,I-B);
B:=I+1;
end
end;end;procedure TForm1.FormShow(Sender: TObject);
begin
ClientSocket1.Close;
ClientSocket1.Address:=Edit1.Text;
ClientSocket1.Port:=StrToInt(Edit2.Text); ClientSocket1.Open;
ClientSocket2.Close;
ClientSocket2.Address:=Edit3.Text;
ClientSocket2.Port:=StrToInt(Edit4.Text); ClientSocket2.Open;
end;procedure TForm1.ClientSocket2Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Label6.Caption:='连接正常';
Timer2.Enabled:=False;
end;procedure TForm1.ClientSocket2Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Label6.Caption:='连接失败';
ClientSocket2.Close;
Timer2.Enabled:=True;
end;procedure TForm1.ClientSocket2Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
Label6.Caption:='连接错误'; ErrorCode:=0;
ClientSocket2.Close;
Timer2.Enabled:=True;
end;procedure TForm1.Timer2Timer(Sender: TObject);
begin
ClientSocket2.Close;
ClientSocket2.Address:=Edit3.Text;
ClientSocket2.Port:=StrToInt(Edit4.Text); ClientSocket2.Open;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
ClientSocket1.Close;
ClientSocket1.Address:=Edit1.Text;
ClientSocket1.Port:=StrToInt(Edit2.Text); ClientSocket1.Open;
ClientSocket2.Close;
ClientSocket2.Address:=Edit3.Text;
ClientSocket2.Port:=StrToInt(Edit4.Text); ClientSocket2.Open;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if Edit10.Text<>'' then
begin
SendCarMsg.Carnumber:=Edit10.Text;
SendCarMsg.Scompany:=Edit11.Text;
SendCarMsg.Acode:= Edit12.Text;
SendCarMsg.Color:= Edit13.Text;
SendCarMsg.Seat:= Edit14.Text;
SendCarMsg.Kind:= byte(pchar(Edit15.Text));
SendCarMsg.GpsKind:= Edit16.Text;
SendCarMsg.Gpsdate:= Edit17.Text;
ClientSocket2.Socket.SendBuf(SendCarMsg,SizeOf(SendCarMsg));
Edit10.Text:='';
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if Edit5.Text<>'' then
begin
SendCompanyMsg.Name:=Edit5.Text;
SendCompanyMsg.Address:=Edit6.Text;
SendCompanyMsg.Smen:= Edit7.Text;
SendCompanyMsg.Phone:= Edit8.Text;
SendCompanyMsg.Kind:= byte(pchar(Edit9.Text));
ClientSocket2.Socket.SendBuf(SendCompanyMsg,SizeOf(SendCompanyMsg));
Edit5.Text:='';
end;
end;end.
谁能帮我啊``
另外据说ClientSocket2.Socket.SendBuf(SendGpsMsg,SizeOf(SendGpsMsg));是传不了数据的``
总程序在下面
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
tt,gpsmsg,sTdate:string;
begin
tt:=Socket.Receivetext;
Memo1.Text:=Memo1.Text+#10#13+tt;
if pos('位置',tt)<>0 then
begin
separateData(tt); //State:=#0;
Move(SendGpsMsg.CarNumber,str[3],SizeOf(SendGpsMsg.CarNumber));
// SendGpsMsg.CarNumber:=ASCtoString(IntToHex(byte(str[3])));
gpsmsg:=str[6]+' '+str[3]+' '+str[7];
PutReviewInfo(gpsmsg);
if S[5]='A' then
SendGpsMsg.GpsState:=byte('1')
// Move(SendGpsMsg.GpsState,'1',SizeOf(SendGpsMsg.GpsState));
else if S[5]='V' then
SendGpsMsg.GpsState:=byte('0');
sTdate:='20'+copy(S[12],5,2)+copy(S[12],3,2)+copy(S[12],1,2)+copy(S[4],1,6);
Move(SendGpsMsg.Tdate,sTdate,SizeOf(SendGpsMsg.Tdate));
SendGpsMsg.Abcd:= GetLon; // htonl(GetLon);
// Move(SendGpsMsg.Abcd,htonl(GetLon),SizeOf(SendGpsMsg.Abcd));
SendGpsMsg.Abcde:= GetLat; //htonl(GetLat);
SendGpsMsg.Speed:= floattostr(GetSpeed);
SendGpsMsg.Angle:= S[11];
SendGpsMsg.Alarm:= byte('0');
SendGpsMsg.CarState:= byte('0'); ClientSocket2.Socket.SendBuf(SendGpsMsg,SizeOf(SendGpsMsg));
end;
end;
function TForm1.GetSpeed:double;
var
Speed,data:string;
begin if S[10]='' then S[10]:='0';
try Speed:=FloatToStr(StrToFloat(S[10])*1.852);
data:='.';
if StrPos(pChar(Speed),pChar(data)) = nil then
Result:=StrToFloat(Speed)
else Result:=StrToFloat(copy(Speed,1,pos('.',Speed)+1));
except
Result:=0.0;
end;
end;
function TForm1.GetLon:double;
var I,J:integer;
Lon:string;
LonDeg:pChar;
LonMin:pChar;
begin Lon:=string(S[8]);
if Lon<>'' then
begin
GetMem(LonDeg,Length('000'));
StrCopy(LonDeg,pChar(string(Lon[1])));
for I:=2 to 3 do
begin StrCat(LonDeg,pChar(string(Lon[I])));
end; GetMem(LonMin,Length('000'));
StrCopy(LonMin,pChar(string(Lon[4])));
for J:=5 to Length(Lon) do
begin StrCat(LonMin,pChar(string(Lon[J])));
end;
try
Result:=StrToFloat(string(LonDeg))
+StrToFloat(string(LonMin))/60 ;
if S[9]='W' then Result:=Result*(-1);
except
Result:=0.0;
end;
FreeMem(LonDeg);
FreeMem(LonMin);
end
else Result:=0.0;
end;
{}
function TForm1.GetLat:double;
var I,J:integer;
Lat:string;
LatDeg:pChar;
LatMin:pChar;
begin Lat:=string(S[6]);
if Lat<>'' then
begin
GetMem(LatDeg,Length('000'));
StrCopy(LatDeg,pChar(string(Lat[1])));
StrCat(LatDeg,pChar(string(Lat[2])));
GetMem(LatMin,Length('000'));
StrCopy(LatMin,pChar(string(Lat[3])));
for J:=4 to Length(Lat) do
begin StrCat(LatMin,pChar(string(Lat[J])));
end;
try
Result:=StrToFloat(string(LatDeg))
+StrToFloat(string(LatMin))/60 ;
if S[7]='s' then Result:=Result*(-1);
except
Result:=0.0;
end;
FreeMem(LatDeg);
FreeMem(LatMin);
end
else Result:=0.0;
end;
procedure TForm1.separateData(var pData:string);
var
A,B,I:integer;
Data:string;
begin
A:=0;
B:=2;
Data:=pData;
for I:=2 to Length(Data) do
begin
if (Data[I]=',') or (Data[I]='<') then
begin
A:=A+1;
str[A]:=Copy(Data,B,I-B);
B:=I+1; end
end;
end;
procedure TForm1.PutReviewInfo(var pInfo:string);
var
info:string;
I,A,B:integer;
begin A:=0;
B:=1;
info:=pInfo;
for I:=1 to Length(info) do
begin
if (info[I]=' ') or (info[I]='<') then
begin
A:=A+1;
S[A]:=Copy(info,B,I-B);
B:=I+1;
end
end;end;procedure TForm1.FormShow(Sender: TObject);
begin
ClientSocket1.Close;
ClientSocket1.Address:=Edit1.Text;
ClientSocket1.Port:=StrToInt(Edit2.Text); ClientSocket1.Open;
ClientSocket2.Close;
ClientSocket2.Address:=Edit3.Text;
ClientSocket2.Port:=StrToInt(Edit4.Text); ClientSocket2.Open;
end;procedure TForm1.ClientSocket2Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Label6.Caption:='连接正常';
Timer2.Enabled:=False;
end;procedure TForm1.ClientSocket2Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Label6.Caption:='连接失败';
ClientSocket2.Close;
Timer2.Enabled:=True;
end;procedure TForm1.ClientSocket2Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
Label6.Caption:='连接错误'; ErrorCode:=0;
ClientSocket2.Close;
Timer2.Enabled:=True;
end;procedure TForm1.Timer2Timer(Sender: TObject);
begin
ClientSocket2.Close;
ClientSocket2.Address:=Edit3.Text;
ClientSocket2.Port:=StrToInt(Edit4.Text); ClientSocket2.Open;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
ClientSocket1.Close;
ClientSocket1.Address:=Edit1.Text;
ClientSocket1.Port:=StrToInt(Edit2.Text); ClientSocket1.Open;
ClientSocket2.Close;
ClientSocket2.Address:=Edit3.Text;
ClientSocket2.Port:=StrToInt(Edit4.Text); ClientSocket2.Open;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if Edit10.Text<>'' then
begin
SendCarMsg.Carnumber:=Edit10.Text;
SendCarMsg.Scompany:=Edit11.Text;
SendCarMsg.Acode:= Edit12.Text;
SendCarMsg.Color:= Edit13.Text;
SendCarMsg.Seat:= Edit14.Text;
SendCarMsg.Kind:= byte(pchar(Edit15.Text));
SendCarMsg.GpsKind:= Edit16.Text;
SendCarMsg.Gpsdate:= Edit17.Text;
ClientSocket2.Socket.SendBuf(SendCarMsg,SizeOf(SendCarMsg));
Edit10.Text:='';
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if Edit5.Text<>'' then
begin
SendCompanyMsg.Name:=Edit5.Text;
SendCompanyMsg.Address:=Edit6.Text;
SendCompanyMsg.Smen:= Edit7.Text;
SendCompanyMsg.Phone:= Edit8.Text;
SendCompanyMsg.Kind:= byte(pchar(Edit9.Text));
ClientSocket2.Socket.SendBuf(SendCompanyMsg,SizeOf(SendCompanyMsg));
Edit5.Text:='';
end;
end;end.
谁能帮我啊``
解决方案 »
- 请教如何获取图片的原始尺寸的宽度和高度?
- 关于delphi中类强烈转换的问题
- clientsocket中如何发送以下数据?
- 我在TScrollBox中放了一个图形,我想在图形放大后 让图形居中,让TScrollBox的滚动条也居中,即让TScrollBox滚动一下
- 怎样使用delphi7中的Indv的IdUDPClient和IdUDPServer控件,在线等
- 求救!!高手请帮帮我!
- TreeView 的递归问题--在线
- 如何判断当前用户是否为administrator
- 如何在listview中实现拖动,各位大虾救命
- 一个巨菜的问题~!~!~!~!~!
- 从右往左截取N个字符!!!
- 请教使用IDHTTP下载文件的时候,如何强制取消
如果是字符串,不要用SendBuf,要用SendText