?? hardwareinitialize_f.~pas
字號:
end; }
strGB_CarType:=edtCarType.Text;
strSpeedCheck:=Chr($28)+Chr($28);
intHigh:=Round((65535-StrToInt(edtParameter.Text)*8*0.1)) div 256;
intLow:=Round((65535-StrToInt(edtParameter.Text)*8*0.1))-intHigh*256;
strKmCheck:=Chr(intLow)+ Chr(intHigh);
strMemClearCheck:=Chr($FF)+Chr($FF)+Chr($FF);
Result:=True;
end;
end;
procedure TfrmHardWardInit.btnOKClick(Sender: TObject);
begin
if getData=True then
begin
if DataCheck=False then
ShowMessage('數(shù)據(jù)不完整,不能初始化')
else
begin
btnUSBItem.Enabled:=True;
btnSendData.Enabled:=True;
end;
end;
end;
procedure TfrmHardWardInit.btnOpenComClick(Sender: TObject);
var
//intASCII:Integer;
//DType:Integer;
sDir: string;
begin
if (strCom='usb') then
begin
{for intASCII:=67 to 90 do
begin
strUsbDrive:=Chr(intASCII)+':\';
DType:=GetDriveType(PChar(strUsbDrive));
if DType=DRIVE_REMOVABLE then
begin
panUSBSign.Color:=clLime;
ShowMessage('串口打開成功');
RadioGroup.Enabled:=False;
btnOpenCom.Enabled:=False;
btnCloseComm.Enabled:=True;
btnOK.Enabled:=True;
Exit;
end
end;
ShowMessage('未找到USB移動存儲器');
Exit;
end;}
sDir := '';
if SelectDirectory('選擇路徑', '', sDir) then
begin
strUsbDrive:=sDir+'\';
//panUSBSign.Color:=clLime;
ShowMessage('已選擇下載路徑');
RadioGroup.Enabled:=False;
btnOpenCom.Enabled:=False;
btnCloseComm.Enabled:=True;
btnOK.Enabled:=True;
Exit;
end;
end;
if TestComm<>nil then
begin
ShowMessage('串口已打開');
Exit;
end;
TestComm:=TComm.Create(nil);
if not TestComm.InitComm(strCom,9600,8,ONESTOPBIT,1) then
begin
MessageBox(Handle,'打開串口錯誤!','串口錯誤',MB_OK or MB_ICONSTOP);
TestComm.FreeComm;
TestComm:=nil;
Exit;
end;
if strCom='Com1' then
panCOM1Sign.Color:=clLime;
if strCom='Com2' then
panCOM2Sign.Color:=clLime;
if strCom='Com3' then
panCOM3Sign.Color:=clLime;
if strCom='Com4' then
panCOM4Sign.Color:=clLime;
if strCom='Com5' then
panCOM5Sign.Color:=clLime;
if strCom='Com6' then
panCOM6Sign.Color:=clLime;
ShowMessage('串口打開成功');
RadioGroup.Enabled:=False;
btnOpenCom.Enabled:=False;
btnCloseComm.Enabled:=True;
btnOK.Enabled:=True;
end;
procedure TfrmHardWardInit.FormCreate(Sender: TObject);
var
i: Integer;
strSql: String;
begin
ADOConnection.ConnectionString := DataString;
ADOConnection.Connected := True;
strCom:='Com1';
intSendNum:=0;
rReceiveStatus:=rComStop;
TempString:='';
Application.OnMessage := AppMessage;
strUsbDrive:='';
strSql:='select Car_PRovince_Type from List_Car_Province';
ADOQuery.Active :=false;
ADOQuery.SQL.Clear;
ADOQuery.SQL.Add(strSql);
ADOQuery.Open;
for i:=0 to ADOQuery.RecordCount-1 do
begin
lbCarLicList.Items.Add(ADOQuery.FieldByName('Car_PRovince_Type').AsString+'-');
ADOQuery.Next;
end;
end;
procedure TfrmHardWardInit.RadioGroupClick(Sender: TObject);
begin
if RadioGroup.ItemIndex=0 then
strCom:='Com1';
if RadioGroup.ItemIndex=1 then
strCom:='Com2';
if RadioGroup.ItemIndex=2 then
strCom:='Com3';
if RadioGroup.ItemIndex=3 then
strCom:='Com4';
if RadioGroup.ItemIndex=4 then
strCom:='Com5';
if RadioGroup.ItemIndex=5 then
strCom:='Com6';
end;
procedure TfrmHardWardInit.btnSendDataClick(Sender: TObject);
var
strSql,strLogTime: String;
begin
//寫日志
intSendNum:=0;
ProgressBar.Position:=0;
btnSendData.Enabled:=False;
strLogTime:=DateTimeToStr(Now);
strSql:='INSERT INTO commlog (Car_VIN,mode_log,time_log) VALUES('''+edtVIN.Text+''',''下傳'','''+strLogTime+''')';
if ADOQuery.Active then
ADOQuery.Active:=False;
ADOQuery.SQL.Clear;
ADOQuery.SQL.Add(strSql);
ADOQuery.ExecSQL;
////
CheckThread:=TCheckThread.Create(True); //create but don't run
CheckThread.bCheckThread:=True; //設(shè)置讀標(biāo)志
CheckThread.Priority:=tpLower; //set the priority lower than normal
CheckThread.Resume; //now run the thread
formatData;
if strCom='usb' then
SendToUSB
else
SendData;
end;
procedure TfrmHardWardInit.FormDestroy(Sender: TObject);
begin
if CheckThread<>nil then
begin
CheckThread.bCheckThread:=False;
if (WaitForSingleObject(CheckThread.Handle,1000)=WAIT_TIMEOUT) then
CheckThread.Terminate;
CheckThread.Free;
CheckThread:=nil;
end;
if TestComm<>nil then
TestComm.Destroy;
end;
procedure TfrmHardWardInit.formatData;
var
strDriver1: String;
strDriver2: String;
strDriver3: String;
strDriver4: String;
strDriver5: String;
strDriverLicence1: String;
strDriverLicence2: String;
strDriverLicence3: String;
strDriverLicence4: String;
strDriverLicence5: String;
i: Integer;
byteXor: Byte;
begin
arrCommand[0]:= '557A010000002E';
arrCommand[1]:= '557A010000002E';
arrCommand[2]:= '557A010000002E';
arrCommand[3]:= '557A010000002E';
arrCommand[4]:= '557A010000002E';
arrCommand[5]:= '557A020000002D';
arrCommand[6]:= '557A040000002B';
arrCommand[7]:= '557A0600000029';
arrCommand[8]:= '557A120000003D';
arrCommand[9]:= '557A130000003C';
arrCommand[10]:='557A140000003B';
arrCommand[11]:='557A200000000F';
byteXor:=$00;
if edtDriverID1.Text='' then
strDriver1:='0'
else
strDriver1:=edtDriverID1.Text;
if edtDriverID2.Text='' then
strDriver2:='0'
else
strDriver2:=edtDriverID2.Text;
if edtDriverID3.Text='' then
strDriver3:='0'
else
strDriver3:=edtDriverID3.Text;
if edtDriverID4.Text='' then
strDriver4:='0'
else
strDriver4:=edtDriverID4.Text;
if edtDriverID5.Text='' then
strDriver5:='0'
else
strDriver5:=edtDriverID5.Text;
if edtDriverLicence1.Text='' then
strDriverLicence1:=Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)
else
strDriverLicence1:=edtDriverLicence1.Text;
if edtDriverLicence2.Text='' then
strDriverLicence2:=Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)
else
strDriverLicence2:=edtDriverLicence2.Text;
if edtDriverLicence3.Text='' then
strDriverLicence3:=Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)
else
strDriverLicence3:=edtDriverLicence3.Text;
if edtDriverLicence4.Text='' then
strDriverLicence4:=Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)
else
strDriverLicence4:=edtDriverLicence4.Text;
if edtDriverLicence5.Text='' then
strDriverLicence5:=Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)+Chr($00)
else
strDriverLicence5:=edtDriverLicence5.Text;
arrSendData[0]:=Chr($AA)+Chr($75)+Chr($01)+Chr(21)+Chr($00)+Chr($00)+ //命令字01 數(shù)據(jù)塊長度105byte
Chr(StrToInt('$'+Copy(Format('%.6x',[StrToInt(strDriver1)]),1,2)))+
Chr(StrToInt('$'+Copy(Format('%.6x',[StrToInt(strDriver1)]),3,2)))+
Chr(StrToInt('$'+Copy(Format('%.6x',[StrToInt(strDriver1)]),5,2)))+ //3byte Hex
strDriverLicence1;
//駕駛員編號1-5、駕駛證號1-5
for i:=0 to Length(arrSendData[0]) do
byteXor:=byteXor Xor Byte(arrSendData[0][i]);
arrSendData[0]:=arrSendData[0]+Chr(byteXor);
byteXor:=$00;
arrSendData[1]:=Chr($AA)+Chr($75)+Chr($01)+Chr(21)+Chr($00)+Chr($00)+ //命令字01 數(shù)據(jù)塊長度105byte
Chr(StrToInt('$'+Copy(Format('%.6x',[StrToInt(strDriver2)]),1,2)))+
Chr(StrToInt('$'+Copy(Format('%.6x',[StrToInt(strDriver2)]),3,2)))+
Chr(StrToInt('$'+Copy(Format('%.6x',[StrToInt(strDriver2)]),5,2)))+ //3byte Hex
strDriverLicence2;
//駕駛員編號1-5、駕駛證號1-5
for i:=0 to Length(arrSendData[1]) do
byteXor:=byteXor Xor Byte(arrSendData[1][i]);
arrSendData[1]:=arrSendData[1]+Chr(byteXor);
byteXor:=$00;
arrSendData[2]:=Chr($AA)+Chr($75)+Chr($01)+Chr(21)+Chr($00)+Chr($00)+ //命令字01 數(shù)據(jù)塊長度105byte
Chr(StrToInt('$'+Copy(Format('%.6x',[StrToInt(strDriver3)]),1,2)))+
Chr(StrToInt('$'+Copy(Format('%.6x',[StrToInt(strDriver3)]),3,2)))+
Chr(StrToInt('$'+Copy(Format('%.6x',[StrToInt(strDriver3)]),5,2)))+ //3byte Hex
strDriverLicence3; //18byte ASCII
//駕駛員編號1-5、駕駛證號1-5
for i:=0 to Length(arrSendData[2]) do
byteXor:=byteXor Xor Byte(arrSendData[2][i]);
arrSendData[2]:=arrSendData[2]+Chr(byteXor);
byteXor:=$00;
arrSendData[3]:=Chr($AA)+Chr($75)+Chr($01)+Chr(21)+Chr($00)+Chr($00)+ //命令字01 數(shù)據(jù)塊長度105byte
Chr(StrToInt('$'+Copy(Format('%.6x',[StrToInt(strDriver4)]),1,2)))+
Chr(StrToInt('$'+Copy(Format('%.6x',[StrToInt(strDriver4)]),3,2)))+
Chr(StrToInt('$'+Copy(Format('%.6x',[StrToInt(strDriver4)]),5,2)))+ //3byte Hex
strDriverLicence4; //18byte ASCII
//駕駛員編號1-5、駕駛證號1-5
for i:=0 to Length(arrSendData[3]) do
byteXor:=byteXor Xor Byte(arrSendData[3][i]);
arrSendData[3]:=arrSendData[3]+Chr(byteXor);
byteXor:=$00;
arrSendData[4]:=Chr($AA)+Chr($75)+Chr($01)+Chr(21)+Chr($00)+Chr($00)+ //命令字01 數(shù)據(jù)塊長度105byte
Chr(StrToInt('$'+Copy(Format('%.6x',[StrToInt(strDriver5)]),1,2)))+
Chr(StrToInt('$'+Copy(Format('%.6x',[StrToInt(strDriver5)]),3,2)))+
Chr(StrToInt('$'+Copy(Format('%.6x',[StrToInt(strDriver5)]),5,2)))+ //3byte Hex
strDriverLicence5; //18byte ASCII
//駕駛員編號1-5、駕駛證號1-5
for i:=0 to Length(arrSendData[4]) do
byteXor:=byteXor Xor Byte(arrSendData[4][i]);
arrSendData[4]:=arrSendData[4]+Chr(byteXor);
byteXor:=$00;
arrSendData[5]:=Chr($AA)+Chr($75)+Chr($02)+Chr($06)+Chr($00)+Chr($00)+ //命令字02 數(shù)據(jù)塊長度6byte
Chr(StrToInt('$'+Copy(FormatDateTime('yymmddhhmmss',Now),1,2)))+
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -