procedure TfrmMain.Timer1Timer(Sender: TObject);
var
i:Integer;
str:string;
begin
flagspeed := false;
ClearCommError(ComHandle1,dwCOM_ErrFlag1,@csCOM_State1);
if csCOM_State1.cbInQue=0 then
begin
Exit;
end;
ReadFile(ComHandle1,baRBuf1[0],csCOM_State1.cbInQue,dwRB1,nil);
str:='';
for i:=0 to dwRB1-1 do
begin
if (baRBuf1[i]=1) then
begin
SpeedCount1:=0;
CanTakeSpeed1:=True;
SpeedBuf1[0]:=0;
SpeedBuf1[1]:=0;
SpeedBuf1[2]:=0;
end;
if ((CanTakeSpeed1=True) and (baRBuf1[i]>10)) then
begin
SpeedBuf1[SpeedCount1]:=baRBuf1[i];
SpeedCount1:=SpeedCount1+1;
end;
if (SpeedCount1=3) then
begin
Application.ProcessMessages;
Speed1:=SpeedProcess1;
str:='1'+' '+IntToStr(StrToInt('$'+IntToHex(SpeedBuf1[0],2)));
str:=str+' '+IntToStr(StrToInt('$'+IntToHex(SpeedBuf1[1],2)));
str:=str+' '+IntToStr(StrToInt('$'+IntToHex(SpeedBuf1[2],2)));
Str:=Str+' Take_'+IntToStr(Speed1);
if (str<>'') then
begin
Application.ProcessMessages;
SpeedDisp1.Lines.Add(str);
end;
if (SpeedDisp1.Lines.Count>=200) then
SpeedDisp1.Lines.Delete(0);
if (Speed1>=SpeedTake) then
begin
//Timer1.Enabled:=False;
//拍照
if Capture then
begin
PicProcess;
tickStart1:=GetTickCount;
while (GetTickCount-tickStart1<10000) do
Application.ProcessMessages;
end;
Timer1.Enabled:=True;
//拍照结束后清除速度
ClearCommError(HComcam1,dwCOM_ErrFlagcam1,@csCOM_Statecam1);
SpeedCount1:=0;
CanTakeSpeed1:=False;
end;
end;
end;
function TfrmMain.Capture: Boolean;
var
nowStatus :Integer;
destfname : string ;
fsdestfname : Tfilestream ;
iTotalRB,itotall :Integer;
begin
Result:=False;
tickStart1:=GetTickCount;
bTimeOut1:=False;
//拍照
baSendBufCam1[0]:=$b1;
WriteFile(HComCam1,baSendBufCam1,1,dwSendBytesCam1,nil);
sb1.Panels[0].Text:='正在连接相机1...';
Application.ProcessMessages;
//接收图片
iTotalRB:=0;
itotall:=0;
nowStatus:=0;
//接收$a0
while ((nowStatus=0) and (not bTimeOut1)) do
begin
if (GetTickCount-tickStart1>5000) then ///////////////////////
bTimeOut1:=True;
ClearCommError(HComCam1,dwCOM_ErrFlagCam1,@csCOM_StateCam1);
if csCOM_StateCam1.cbInQue=0 then
begin
continue ;
end;
ReadFile(HComCam1,baRBufCam1[0],csCOM_StateCam1.cbInQue,dwRBCam1,nil);
if (baRBufCam1[0]=$a0) then
begin
nowStatus:=1;
end;
end;
if nowStatus = 1 then
begin
//Timer1.Enabled := True;/////////////////////////////////////////////////////
//发送$A9
baSendBufCam1[0]:= $a9;
WriteFile(HComCam1,baSendBufCam1,1,dwSendBytesCam1,nil);
nowStatus:=2; //等待接收数据
sb1.Panels[0].Text:='正在接收数据...';
Application.ProcessMessages;
while ((nowStatus=2) and (not bTimeOut1)) do
begin
if (GetTickCount-tickStart1>120000) then
bTimeOut1:=True;
ClearCommError(HComCam1,dwCOM_ErrFlagCam1,@csCOM_StateCam1);
if csCOM_StateCam1.cbInQue=0 then
begin
continue ;
end;
ReadFile(HComCam1,baRBufCam1[iTotalRB],csCOM_StateCam1.cbInQue,dwRBCam1,nil);
iTotalRB:=iTotalRB+dwRBCam1;
if (itotalRB > 34) and (itotall = 0) then
begin
itotall:=baRBufCam1[25]*16777216+baRBufCam1[24]*65535+baRBufCam1[23]*256+baRBufCam1[22]+22;
end;
if (itotalRB>34)and(itotalRB>=itotall) then
begin
destfname:='c:\1.jpg';
fsdestfname:=Tfilestream.Create(destfname,fmcreate);
fsdestfname.Write(baRBufCam1[34],itotall-12);
fsdestfname.Write(baRBufCam1[0],26);
fsdestfname.Free;
nowStatus:=3;
Result:=True;
sb1.Panels[0].Text:='图片下载完成';
Application.ProcessMessages;
end;
end;
if bTimeOut1 then
begin
//重启相机
baSendBufCam1[0]:=$a7;
WriteFile(HComCam1,baSendBufCam1,1,dwSendBytesCam1,nil);
sb1.Panels[0].Text:='图片下载超时,正重启...';
Application.ProcessMessages;
//延时1分钟,等待相机重启
tickStart1:=GetTickCount;
while (GetTickCount-tickStart1<60000) do
Application.ProcessMessages;
sb1.Panels[0].Text:='图片下载超时,重启完成';
Application.ProcessMessages;
end;
end;
end;
procedure TfrmMain.PicProcess;
var
picName:string;
Speeddiff:integer;
begin
if flagspeed = false then
speeddiff := speed1
else
speeddiff := speed2;
try
MyJpeg.LoadFromFile('c:\1.jpg');
bmp.assign(MyJpeg);
//图片上加字
bmp.Canvas.Font.Name := '宋体' ;
bmp.Canvas.Font.Size := 30 ;
bmp.Canvas.Font.Color:= clRed ;
bmp.Canvas.TextOut(3,3,'LX6010D '+formatdatetime('yyyymmddhhmmss',now)
+' 速度:'+IntToStr(Speeddiff)+' 限速:'+IntToStr(SpeedLimit)+' '+TakePlace);//违法信息 picName:=AppPath+'pic\'+formatdatetime('yyyymmdd',now);
if not DirectoryExists(picName) then
ForceDirectories(picName);
picName:=AppPath+'pic\'+formatdatetime('yyyymmdd',now)+'\'
+formatdatetime('yyyymmddhhmmss',now)
+format('%3.3d',[SpeedLimit])+format('%3.3d',[speeddiff])+'.jpg'; MyJpeg.Assign(bmp);
MyJpeg.SaveToFile(picName);
img.Picture.LoadFromFile(picName);
Application.ProcessMessages;
except
sb1.Panels[0].Text:='图片错误!';
Application.ProcessMessages;
end;
end;
end;现在我想实现在拍照的同时能实时的速度数据!!即实现
if (str<>'') then
begin
Application.ProcessMessages;
SpeedDisp1.Lines.Add(str);
end;
if (SpeedDisp1.Lines.Count>=200) then
SpeedDisp1.Lines.Delete(0);
这段代码功能我现在的问题是如果超速了在拍摄照片的过程中有下一个速度来的话不能实时的显示出来
望大虾们指点任何解决啊???????
var
i:Integer;
str:string;
begin
flagspeed := false;
ClearCommError(ComHandle1,dwCOM_ErrFlag1,@csCOM_State1);
if csCOM_State1.cbInQue=0 then
begin
Exit;
end;
ReadFile(ComHandle1,baRBuf1[0],csCOM_State1.cbInQue,dwRB1,nil);
str:='';
for i:=0 to dwRB1-1 do
begin
if (baRBuf1[i]=1) then
begin
SpeedCount1:=0;
CanTakeSpeed1:=True;
SpeedBuf1[0]:=0;
SpeedBuf1[1]:=0;
SpeedBuf1[2]:=0;
end;
if ((CanTakeSpeed1=True) and (baRBuf1[i]>10)) then
begin
SpeedBuf1[SpeedCount1]:=baRBuf1[i];
SpeedCount1:=SpeedCount1+1;
end;
if (SpeedCount1=3) then
begin
Application.ProcessMessages;
Speed1:=SpeedProcess1;
str:='1'+' '+IntToStr(StrToInt('$'+IntToHex(SpeedBuf1[0],2)));
str:=str+' '+IntToStr(StrToInt('$'+IntToHex(SpeedBuf1[1],2)));
str:=str+' '+IntToStr(StrToInt('$'+IntToHex(SpeedBuf1[2],2)));
Str:=Str+' Take_'+IntToStr(Speed1);
if (str<>'') then
begin
Application.ProcessMessages;
SpeedDisp1.Lines.Add(str);
end;
if (SpeedDisp1.Lines.Count>=200) then
SpeedDisp1.Lines.Delete(0);
if (Speed1>=SpeedTake) then
begin
//Timer1.Enabled:=False;
//拍照
if Capture then
begin
PicProcess;
tickStart1:=GetTickCount;
while (GetTickCount-tickStart1<10000) do
Application.ProcessMessages;
end;
Timer1.Enabled:=True;
//拍照结束后清除速度
ClearCommError(HComcam1,dwCOM_ErrFlagcam1,@csCOM_Statecam1);
SpeedCount1:=0;
CanTakeSpeed1:=False;
end;
end;
end;
function TfrmMain.Capture: Boolean;
var
nowStatus :Integer;
destfname : string ;
fsdestfname : Tfilestream ;
iTotalRB,itotall :Integer;
begin
Result:=False;
tickStart1:=GetTickCount;
bTimeOut1:=False;
//拍照
baSendBufCam1[0]:=$b1;
WriteFile(HComCam1,baSendBufCam1,1,dwSendBytesCam1,nil);
sb1.Panels[0].Text:='正在连接相机1...';
Application.ProcessMessages;
//接收图片
iTotalRB:=0;
itotall:=0;
nowStatus:=0;
//接收$a0
while ((nowStatus=0) and (not bTimeOut1)) do
begin
if (GetTickCount-tickStart1>5000) then ///////////////////////
bTimeOut1:=True;
ClearCommError(HComCam1,dwCOM_ErrFlagCam1,@csCOM_StateCam1);
if csCOM_StateCam1.cbInQue=0 then
begin
continue ;
end;
ReadFile(HComCam1,baRBufCam1[0],csCOM_StateCam1.cbInQue,dwRBCam1,nil);
if (baRBufCam1[0]=$a0) then
begin
nowStatus:=1;
end;
end;
if nowStatus = 1 then
begin
//Timer1.Enabled := True;/////////////////////////////////////////////////////
//发送$A9
baSendBufCam1[0]:= $a9;
WriteFile(HComCam1,baSendBufCam1,1,dwSendBytesCam1,nil);
nowStatus:=2; //等待接收数据
sb1.Panels[0].Text:='正在接收数据...';
Application.ProcessMessages;
while ((nowStatus=2) and (not bTimeOut1)) do
begin
if (GetTickCount-tickStart1>120000) then
bTimeOut1:=True;
ClearCommError(HComCam1,dwCOM_ErrFlagCam1,@csCOM_StateCam1);
if csCOM_StateCam1.cbInQue=0 then
begin
continue ;
end;
ReadFile(HComCam1,baRBufCam1[iTotalRB],csCOM_StateCam1.cbInQue,dwRBCam1,nil);
iTotalRB:=iTotalRB+dwRBCam1;
if (itotalRB > 34) and (itotall = 0) then
begin
itotall:=baRBufCam1[25]*16777216+baRBufCam1[24]*65535+baRBufCam1[23]*256+baRBufCam1[22]+22;
end;
if (itotalRB>34)and(itotalRB>=itotall) then
begin
destfname:='c:\1.jpg';
fsdestfname:=Tfilestream.Create(destfname,fmcreate);
fsdestfname.Write(baRBufCam1[34],itotall-12);
fsdestfname.Write(baRBufCam1[0],26);
fsdestfname.Free;
nowStatus:=3;
Result:=True;
sb1.Panels[0].Text:='图片下载完成';
Application.ProcessMessages;
end;
end;
if bTimeOut1 then
begin
//重启相机
baSendBufCam1[0]:=$a7;
WriteFile(HComCam1,baSendBufCam1,1,dwSendBytesCam1,nil);
sb1.Panels[0].Text:='图片下载超时,正重启...';
Application.ProcessMessages;
//延时1分钟,等待相机重启
tickStart1:=GetTickCount;
while (GetTickCount-tickStart1<60000) do
Application.ProcessMessages;
sb1.Panels[0].Text:='图片下载超时,重启完成';
Application.ProcessMessages;
end;
end;
end;
procedure TfrmMain.PicProcess;
var
picName:string;
Speeddiff:integer;
begin
if flagspeed = false then
speeddiff := speed1
else
speeddiff := speed2;
try
MyJpeg.LoadFromFile('c:\1.jpg');
bmp.assign(MyJpeg);
//图片上加字
bmp.Canvas.Font.Name := '宋体' ;
bmp.Canvas.Font.Size := 30 ;
bmp.Canvas.Font.Color:= clRed ;
bmp.Canvas.TextOut(3,3,'LX6010D '+formatdatetime('yyyymmddhhmmss',now)
+' 速度:'+IntToStr(Speeddiff)+' 限速:'+IntToStr(SpeedLimit)+' '+TakePlace);//违法信息 picName:=AppPath+'pic\'+formatdatetime('yyyymmdd',now);
if not DirectoryExists(picName) then
ForceDirectories(picName);
picName:=AppPath+'pic\'+formatdatetime('yyyymmdd',now)+'\'
+formatdatetime('yyyymmddhhmmss',now)
+format('%3.3d',[SpeedLimit])+format('%3.3d',[speeddiff])+'.jpg'; MyJpeg.Assign(bmp);
MyJpeg.SaveToFile(picName);
img.Picture.LoadFromFile(picName);
Application.ProcessMessages;
except
sb1.Panels[0].Text:='图片错误!';
Application.ProcessMessages;
end;
end;
end;现在我想实现在拍照的同时能实时的速度数据!!即实现
if (str<>'') then
begin
Application.ProcessMessages;
SpeedDisp1.Lines.Add(str);
end;
if (SpeedDisp1.Lines.Count>=200) then
SpeedDisp1.Lines.Delete(0);
这段代码功能我现在的问题是如果超速了在拍摄照片的过程中有下一个速度来的话不能实时的显示出来
望大虾们指点任何解决啊???????
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货