1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| unit U_RWUsb_2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, ComCtrls, AntHIDDeviceController;
type
TReport = packed record
ReportID: byte;
Data: array [0..64] of byte;
end;
TCmdInfo = record
ID: Integer;
Flags: Byte;
Changed: Byte;
end;
TForm1 = class(TForm)
HidCtrl1: TAntHidDeviceController;
M1: TMemo;
BtInfo: TButton;
BtEnvoi: TButton;
procedure HidCtrl1DeviceChange(Sender: TObject);
procedure BtInfoClick(Sender: TObject);
procedure BtEnvoiClick(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
CurrentDevice: TAntHidDevice;
Dev:TAntHidDevice;
published
end;
var
Form1: TForm1;
MyDevice: TAntHidDevice;
TabOut: array[0..64] of Byte;
implementation
uses U_Info_2;
{$R *.dfm}
Const
// MyVendorID = $16C0; // Carte ES
// MyProductID = $05DF;
MyVendorID = $16C0; // Carte Relais
MyProductID = $05DF;
procedure TForm1.HidCtrl1DeviceChange(Sender: TObject);
var
Devtrouve:Boolean;
begin
try
Dev.Free;
DevTrouve:=false;
While HidCtrl1.CheckOut(Dev) do begin
M1.Lines.Add(Dev.ProductName);
if Dev.ProductName = 'USBRelay2' then begin
//if Dev.ProductName = 'Es_Carte_1' then begin
CurrentDevice:= Dev;
DevTrouve:=true;
end;
end;
if DevTrouve then begin
end
else begin
if MessageDlg('Carte non branchée ou hors tension'+chr(13)+
'Brancher la carte et choisir OUI'+ Chr(13)+
'Pour quitter choisir NON',
mtWarning , [mbYes, mbNo], 0) = mrYes then begin
Dev.Free;
Application.Restore;
HidCtrl1.DeviceChange;
end
else
Form1.Close;
end;
except
Application.MessageBox('Erreur','ATTENTION !',MB_OK);
end;
end;
procedure TForm1.BtInfoClick(Sender: TObject);
begin
F_Info.Show;
end;
procedure TForm1.BtEnvoiClick(Sender: TObject);
var
Buf: array [0..64] of Byte;
Written: Cardinal;
ToWrite: Cardinal;
begin
if Assigned(CurrentDevice) then begin
Buf[0] := StrToIntDef( '0', 0);
ToWrite := CurrentDevice.Caps.OutputReportByteLength;
Buf[1]:= $FF;
Buf[2]:= $01;
Buf[3]:= $00;
Buf[4]:= $00;
Buf[5]:= $00;
Buf[6]:= $00;
Buf[7]:= $00;
Buf[8]:= $00;
//if not CurrentDevice.WriteFile(Buf, ToWrite, Written) then //Err := GetLastError;
CurrentDevice.WriteFile(Buf, ToWrite, Written);
end;
end;
end. |
Partager