to autumn 我吧源码贴出来 大家帮我看一下 procedure TF_dqq.RadioButton5Click(Sender: TObject);var i,j,k:integer; Str,str_b: string; Buf: array [0..64] of Byte; Written: Cardinal; ToWrite: Cardinal; Err: DWORD; ds:integer;begin self.RadioButton4.OnClick(RadioButton4); sleep(200); currentDevice.OnData:=nil; if str_state='ds' then self.RadioButton6.OnClick(RadioButton6); sleep(200); // currentDevice.OnData:=nil; // if str_state='syb' then begin yx_cs:=0; zbs:=0; //showmessage('下载开始'); currentDevice.OnData:=ShowRead; for i:=low(packs_ds) to high(packs_ds) do zbs:=zbs+packs_ds; for k:=low(packs_ds) to high(packs_ds) do // for k:=0 to 2 do begin // if k=0 then // continue; if Devlistbox.Items.Count=0 then begin showmessage('设备通讯中断'); application.Terminate; end; buf[0]:=StrToIntDef('$00', 0); buf[1]:=StrToIntDef('$AF', 0); buf[2]:=StrToIntDef('$AF', 0); buf[3]:=StrToIntDef('$FC', 0); buf[4]:=StrToIntDef('$FC', 0); buf[5]:=StrToIntDef('$'+inttohex(k+1,2), 0); buf[6]:=StrToIntDef('$00', 0); for sy_b:=1 to packs_ds[k] do // for sy_b:=1 to 2 do begin str_state:='syb'; bz:=false; buf[7]:=StrToIntDef('$'+inttohex(sy_b,2), 0); Application.ProcessMessages; for i:=8 to 64 do begin Buf:=StrToIntDef('$00', 0); end; ToWrite := CurrentDevice.Caps.OutputReportByteLength; if not CurrentDevice.WriteFile(Buf,ToWrite, Written) then begin Err := GetLastError; Add(Format('写错误: %s (%x)', [SysErrorMessage(Err), Err])); end else begin for I := 1 to Written-1 do begin Str := Str + Format('%.2x ', [Buf]); //add(str); end; currentDevice.ThreadSleepTime:=1000; // currentDevice.OnData:=nil; end; end; end; end;end;procedure TF_dqq.RadioButton4Click(Sender: TObject);var i,j,k:integer; Buf: array [0..64] of Byte; Written: Cardinal; ToWrite: Cardinal; str:string; Err: DWORD; str_b: string;begin listbox1.Items.Clear; CurrentDevice := TJvHidDevice(DevListBox.Items.Objects[DevListBox.ItemIndex]); currentDevice.OnData:=ShowRead; //L_usb.Caption:=DeviceName(CurrentDevice); { if l_usb.Caption='' then begin showmessage('没有HID设备'); exit; end; } //currentDevice.OnData:=ShowRead; str_state:='csh'; buf[0]:=StrToIntDef('$00', 0); buf[1]:=StrToIntDef('$AF', 0); buf[2]:=StrToIntDef('$AF', 0); buf[3]:=StrToIntDef('$FA', 0); buf[4]:=StrToIntDef('$FA', 0); for i:=5 to 64 do begin Buf:=StrToIntDef('$00', 0); end; ToWrite := CurrentDevice.Caps.OutputReportByteLength; if not CurrentDevice.WriteFile(Buf, ToWrite, Written) then begin Err := GetLastError; Add(Format('WRITE ERROR: %s (%x)', [SysErrorMessage(Err), Err])); end else begin for I := 1 to Written-1 do Str := Str + Format('%.2x ', [Buf]); //AddToHistory(Str); //currentDevice.OnData:=ShowRead; end;end;procedure TF_dqq.RadioButton6Click(Sender: TObject);var i,j,k:integer; Str,str_b: string; Buf: array [0..64] of Byte; Written: Cardinal; ToWrite: Cardinal; Err: DWORD;begin qj_bz:=true; //for k:=1 to listbox1.Items.Count do for k:=1 to ds_z do begin //currentDevice.OnData:=nil; str_state:='ds'; buf[0]:=StrToIntDef('$00', 0); buf[1]:=StrToIntDef('$AF', 0); buf[2]:=StrToIntDef('$AF', 0); buf[3]:=StrToIntDef('$FB', 0); buf[4]:=StrToIntDef('$FB', 0); buf[5]:=StrToIntDef('$'+inttohex(k,2), 0); for i:=6 to 64 do begin Buf:=StrToIntDef('$00', 0); end; if qj_bz=true then begin ToWrite := CurrentDevice.Caps.OutputReportByteLength; if not CurrentDevice.WriteFile(Buf, ToWrite, Written) then begin Err := GetLastError; Add(Format('写错误: %s (%x)', [SysErrorMessage(Err), Err])); end else begin for I := 1 to Written-1 do Str := Str + Format('%.2x ', [Buf]); currentDevice.OnData:=ShowRead; qj_bz:=false; // currentDevice.ThreadSleepTime:=1000; // currentDevice.OnData:=nil; end; end; end; //currentDevice.OnData:=nil; //str_state:='syb';end;procedure TF_dqq.ShowRead(HidDev: TJvHidDevice; ReportID: Byte; const Data: Pointer; Size: Word);var Str,str_b: string; i,j,k:integer; Buf: array [0..64] of Byte; Written: Cardinal; ToWrite: Cardinal; Err: DWORD;begin for I := 0 to Size - 1 do begin packs:=Format('%.2x ', [Cardinal(PChar(Data))]); Str:= Str + Format('%.2x ', [Cardinal(PChar(Data))]); end; if str_state='csh' then begin if packs[4]<>'' then begin if HexToInt(trim(packs[4]))>0 then begin ds_z:=HexToInt(trim(packs[4])); for i:=1 to HexToInt(trim(packs[4])) do listbox1.Items.Add('第'+inttostr(i)+' 段'); end; end; // currentdevice.CloseFile; str_state:='ds'; exit; end; if str_state='syb' then begin zs:=HexToInt(trim(packs[5])); AddToHistory(Str); yx_cs:=yx_cs+1; if yx_cs=1 then showmessage('下载开始'); if yx_cs=zbs then begin sleep(2000); showmessage('下载结束'); end; end; if str_state='ds' then begin qj_bz:=true; ds:=ds+1; setlength(packs_ds,ds); bs:=0; if packs[4]<>'' then begin if HexToInt(trim(packs[4])+trim(packs[5]))>0 then begin bs:=HexToInt(trim(packs[4])+trim(packs[5])); packs_ds[ds-1]:=bs; end; end; if ds=ds_z then begin str_state:='syb'; exit; end; end;end;