Update of /cvsroot/jvcl/dev/JVCL3/examples/JvHIDController/ReadWriteDemo
In directory sc8-pr-cvs1:/tmp/cvs-serv4702/JVCL3/examples/JvHIDController/ReadWriteDemo
Added Files:
DevReader.dfm DevReader.pas Info.dfm Info.pas
SimpleHIDWrite.dof SimpleHIDWrite.dpr SimpleHIDWrite.res
Log Message:
- Copied jvcl/devtools and jvcl/examples dev/JVCL3
- Copied JVCLConvert *.dat files to dev/JVCL3/converter
--- NEW FILE: DevReader.dfm ---
object Form1: TForm1
Left = 192
Top = 116
AutoScroll = False
Caption = 'HID Reader'
ClientHeight = 484
ClientWidth = 444
Color = clBtnFace
Constraints.MinHeight = 500
Constraints.MinWidth = 450
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
OnActivate = FormActivate
OnDestroy = DevListBoxClick
PixelsPerInch = 96
TextHeight = 16
object Read: TSpeedButton
Left = 72
Top = 451
Width = 81
Height = 22
AllowAllUp = True
Anchors = [akLeft, akBottom]
GroupIndex = 1
Caption = 'Read'
OnClick = ReadClick
end
object Write: TSpeedButton
Left = 160
Top = 451
Width = 81
Height = 22
AllowAllUp = True
Anchors = [akLeft, akBottom]
Caption = 'Write'
OnClick = WriteClick
end
object Save: TSpeedButton
Left = 248
Top = 451
Width = 81
Height = 22
AllowAllUp = True
Anchors = [akLeft, akBottom]
Caption = 'Save'
OnClick = SaveClick
end
object Label1: TLabel
Left = 41
Top = 300
Width = 64
Height = 16
Anchors = [akLeft, akRight, akBottom]
AutoSize = False
Caption = 'ReportID'
end
object Info: TSpeedButton
Left = 8
Top = 451
Width = 49
Height = 22
Anchors = [akLeft, akBottom]
Caption = 'Info'
OnClick = InfoClick
end
object DevListBox: TListBox
Left = -1
Top = 0
Width = 444
Height = 81
Anchors = [akLeft, akTop, akRight]
ItemHeight = 16
TabOrder = 0
OnClick = DevListBoxClick
end
object HistoryListBox: TListBox
Left = 0
Top = 84
Width = 444
Height = 205
Anchors = [akLeft, akTop, akRight, akBottom]
ItemHeight = 16
TabOrder = 1
end
object ReportID: TEdit
Left = 8
Top = 296
Width = 25
Height = 24
Anchors = [akLeft, akBottom]
TabOrder = 2
end
object Edit1: TEdit
Left = 8
Top = 328
Width = 25
Height = 24
Anchors = [akLeft, akBottom]
TabOrder = 3
end
object SaveDialog1: TSaveDialog
DefaultExt = 'txt'
Filter = 'Text Files *.txt|*.txt|All Files *.*|*.*'
Options = [ofOverwritePrompt, ofHideReadOnly, ofEnableSizing, ofDontAddToRecent]
Title = 'Save History'
Left = 312
end
object HidCtl: TJvHidDeviceController
OnEnumerate = HidCtlEnumerate
OnDeviceChange = HidCtlDeviceChange
Left = 368
end
end
--- NEW FILE: DevReader.pas ---
unit DevReader;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, JvHidControllerClass, JvComponent;
type
TReport = packed record
ReportID: Byte;
Bytes: array [0..63] of Byte;
end;
TDevThread = class(TThread)
public
Dev: TJvHidDevice;
NumBytesRead: Cardinal;
Data: TReport;
procedure Execute; override;
procedure HandleData;
end;
TForm1 = class(TForm)
DevListBox: TListBox;
HistoryListBox: TListBox;
Read: TSpeedButton;
Write: TSpeedButton;
Save: TSpeedButton;
SaveDialog1: TSaveDialog;
ReportID: TEdit;
Edit1: TEdit;
Label1: TLabel;
HidCtl: TJvHidDeviceController;
Info: TSpeedButton;
procedure HidCtlDeviceChange(Sender: TObject);
function HidCtlEnumerate(const HidDev: TJvHidDevice;
const Idx: Integer): Boolean;
procedure ReadClick(Sender: TObject);
procedure DevListBoxClick(Sender: TObject);
procedure SaveClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure WriteClick(Sender: TObject);
procedure InfoClick(Sender: TObject);
public
DevList: TList;
Edits: array [0..63] of TEdit;
TheDev: TJvHidDevice;
DevThread: TDevThread;
procedure ShowRead;
end;
var
Form1: TForm1;
implementation
uses
Info;
{$R *.DFM}
procedure TForm1.HidCtlDeviceChange(Sender: TObject);
var
Dev: TJvHidDevice;
I: Integer;
begin
Read.Down := False;
if Assigned(DevListBox) then
begin
if DevList <> nil then
begin
for I := 0 to DevList.Count - 1 do
begin
Dev := DevList.Items[I];
Dev.Free;
end;
DevList.Clear;
end
else
DevList := TList.Create;
HistoryListBox.Clear;
DevListBox.Clear;
HidCtl.Enumerate;
if DevListBox.Items.Count > 0 then
begin
DevListBox.ItemIndex := 0;
DevListBoxClick(Self);
end;
end;
end;
function TForm1.HidCtlEnumerate(const HidDev: TJvHidDevice;
const Idx: Integer): Boolean;
var
Dev: TJvHidDevice;
begin
if Assigned(DevListBox) then
begin
if HidDev.ProductName <> '' then
DevListBox.Items.Add(HidDev.ProductName)
else
DevListBox.Items.Add(Format('Device VID=%x PID=%x',
[HidDev.Attributes.VendorID, HidDev.Attributes.ProductID]));
HidCtl.CheckOutByIndex(Dev, Idx);
DevList.Add(Dev);
end;
Result := True;
end;
procedure TForm1.DevListBoxClick(Sender: TObject);
var
I: Integer;
begin
Read.Down := False;
HistoryListBox.Clear;
if Assigned(Edits[0]) and
(DevListBox.Items.Count > 0) and (DevListBox.ItemIndex >= 0) then
begin
TheDev := DevList[DevListBox.ItemIndex];
for I := 0 to TheDev.Caps.OutputReportByteLength - 1 do
Edits[I].Visible := True;
for I := TheDev.Caps.OutputReportByteLength-1 to 63 do
Edits[I].Visible := False;
Write.Enabled := TheDev.Caps.OutputReportByteLength <> 0;
end;
end;
procedure TForm1.ShowRead;
var
I: Integer;
Str: string;
begin
Str := Format('R %.2x ', [DevThread.Data.ReportID]);
for I := 0 to DevThread.NumBytesRead - 2 do
Str := Str + Format('%.2x ', [DevThread.Data.Bytes[I]]);
HistoryListBox.ItemIndex := HistoryListBox.Items.Add(Str);
end;
procedure TDevThread.HandleData;
begin
Synchronize(Form1.ShowRead);
end;
procedure TDevThread.Execute;
var
SleepRet: DWORD;
procedure Dummy(ErrorCode: DWORD; Count: DWORD; Ovl: POverlapped); stdcall;
begin
end;
begin
SleepRet := WAIT_IO_COMPLETION;
while not Terminated do
begin
// read data
SleepRet := WAIT_IO_COMPLETION;
if not Dev.ReadFileEx(Data, Dev.Caps.InputReportByteLength, @Dummy) then
Break;
// wait for read to complete
repeat
SleepRet := SleepEx(200, True);
until Terminated or (SleepRet = WAIT_IO_COMPLETION);
// show data read
if not Terminated then
begin
NumBytesRead := Dev.HidOverlappedReadResult;
HandleData;
end;
end;
// cancel ReadFileEx call or the callback will
// crash your program
if SleepRet <> WAIT_IO_COMPLETION then
Dev.CancelIO(omhRead);
end;
procedure TForm1.InfoClick(Sender: TObject);
begin
if (DevListBox.Items.Count > 0) and (DevListBox.ItemIndex >= 0) then
with TInfoForm.Create(Self) do
begin
ShowModal;
Free;
end;
end;
procedure TForm1.ReadClick(Sender: TObject);
begin
if (DevListBox.Items.Count > 0) and (DevListBox.ItemIndex >= 0) then
begin
TheDev := DevList[DevListBox.ItemIndex];
if Read.Down then
begin
DevThread := TDevThread.Create(True);
DevThread.FreeOnTerminate := False;
DevThread.Dev := TheDev;
DevThread.Resume;
end
else
begin
DevThread.Terminate;
DevThread.WaitFor;
FreeAndNil(DevThread);
end;
end;
end;
procedure TForm1.WriteClick(Sender: TObject);
var
I: Integer;
Buf: array [0..64] of Byte;
Written: Cardinal;
ToWrite: Cardinal;
Str: string;
begin
if (DevListBox.Items.Count > 0) and (DevListBox.ItemIndex >= 0) then
begin
TheDev := DevList[DevListBox.ItemIndex];
Buf[0] := StrToIntDef('$' + ReportID.Text, 0);
ReportID.Text := Format('%.2x', [Buf[0]]);
ToWrite := TheDev.Caps.OutputReportByteLength;
for I := 1 to ToWrite-1 do
begin
Buf[I] := StrToIntDef('$' + Edits[I-1].Text, 0);
Edits[I-1].Text := Format('%.2x', [Buf[I]]);
end;
TheDev.WriteFile(Buf, ToWrite, Written);
Str := Format('W %.2x ', [Buf[0]]);
for I := 1 to Written-1 do
Str := Str + Format('%.2x ', [Buf[I]]);
HistoryListBox.ItemIndex := HistoryListBox.Items.Add(Str);
end;
end;
procedure TForm1.SaveClick(Sender: TObject);
begin
ForceCurrentDirectory := True;
if SaveDialog1.Execute then
HistoryListBox.Items.SaveToFile(SaveDialog1.FileName);
end;
procedure TForm1.FormActivate(Sender: TObject);
var
I, J: Integer;
begin
if Assigned(Edits[0]) then
Exit;
Edits[0] := Edit1;
for I := 1 to 63 do
Edits[I] := TEdit.Create(Self);
for J := 0 to 3 do
for I := 0 to 15 do
with Edits[J*16 + I] do
begin
Visible := False;
Left := Edit1.Left + I*(Edit1.Width+2);
Top := Edit1.Top + J*(Edit1.Height+2);
Width := Edit1.Width;
Anchors := Edit1.Anchors;
Parent := Edit1.Parent;
TabOrder := 2 + J*16 + I;
end;
DevListBoxClick(Self);
end;
end.
--- NEW FILE: Info.dfm ---
object InfoForm: TInfoForm
Left = 302
Top = 120
Width = 573
Height = 409
BorderIcons = [biSystemMenu]
Caption = 'HID Device Info'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Position = poOwnerFormCenter
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 16
object Label1: TLabel
Left = 232
Top = 8
Width = 41
Height = 16
Caption = 'Strings'
end
object Label2: TLabel
Left = 8
Top = 72
Width = 25
Height = 16
Caption = 'VID:'
end
object Label3: TLabel
Left = 8
Top = 88
Width = 25
Height = 16
Caption = 'PID:'
end
object Label4: TLabel
Left = 8
Top = 104
Width = 49
Height = 16
Caption = 'Version:'
end
object Vid: TLabel
Left = 64
Top = 72
Width = 20
Height = 16
Caption = 'Vid'
end
object Pid: TLabel
Left = 64
Top = 88
Width = 20
Height = 16
Caption = 'Pid'
end
object Vers: TLabel
Left = 64
Top = 104
Width = 28
Height = 16
Caption = 'Vers'
end
object Label5: TLabel
Left = 8
Top = 136
Width = 84
Height = 16
Caption = 'Report Length'
end
object Label6: TLabel
Left = 8
Top = 160
Width = 31
Height = 16
Caption = 'Input:'
end
object Label7: TLabel
Left = 8
Top = 176
Width = 41
Height = 16
Caption = 'Output:'
end
object Label8: TLabel
Left = 8
Top = 192
Width = 49
Height = 16
Caption = 'Feature:'
end
object InputLen: TLabel
Left = 72
Top = 160
Width = 7
Height = 16
Caption = '0'
end
object OutputLen: TLabel
Left = 72
Top = 176
Width = 7
Height = 16
Caption = '0'
end
object FeatureLen: TLabel
Left = 72
Top = 192
Width = 7
Height = 16
Caption = '0'
end
object Label9: TLabel
Left = 8
Top = 24
Width = 86
Height = 16
Caption = 'Product name:'
end
object Label10: TLabel
Left = 8
Top = 8
Width = 84
Height = 16
Caption = 'Vendor name:'
end
object VendorName: TLabel
Left = 96
Top = 8
Width = 81
Height = 16
Caption = 'VendorName'
end
object ProductName: TLabel
Left = 96
Top = 24
Width = 83
Height = 16
Caption = 'ProductName'
end
object Label11: TLabel
Left = 8
Top = 40
Width = 59
Height = 16
Caption = 'Serial No:'
end
object SerialNo: TLabel
Left = 96
Top = 40
Width = 53
Height = 16
Caption = 'SerialNo'
end
object Label12: TLabel
Left = 400
Top = 8
Width = 68
Height = 16
Caption = 'Languages'
end
object DevStrings: TListBox
Left = 232
Top = 24
Width = 161
Height = 345
Anchors = [akLeft, akTop, akRight, akBottom]
ItemHeight = 16
TabOrder = 0
end
object LangStrings: TListBox
Left = 400
Top = 24
Width = 161
Height = 345
Anchors = [akTop, akRight, akBottom]
ItemHeight = 16
TabOrder = 1
end
end
--- NEW FILE: Info.pas ---
unit Info;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TInfoForm = class(TForm)
DevStrings: TListBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Vid: TLabel;
Pid: TLabel;
Vers: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
InputLen: TLabel;
OutputLen: TLabel;
FeatureLen: TLabel;
Label9: TLabel;
Label10: TLabel;
VendorName: TLabel;
ProductName: TLabel;
Label11: TLabel;
SerialNo: TLabel;
LangStrings: TListBox;
Label12: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
InfoForm: TInfoForm;
implementation
uses
DevReader;
{$R *.DFM}
procedure TInfoForm.FormCreate(Sender: TObject);
var
I: Integer;
begin
with Form1 do
begin
VendorName.Caption := TheDev.VendorName;
ProductName.Caption := TheDev.ProductName;
SerialNo.Caption := TheDev.SerialNumber;
Vid.Caption := IntToHex(TheDev.Attributes.VendorID, 4);
Pid.Caption := IntToHex(TheDev.Attributes.ProductID, 4);
Vers.Caption := IntToHex(TheDev.Attributes.VersionNumber, 4);
if TheDev.Caps.InputReportByteLength > 0 then
InputLen.Caption := IntToHex(TheDev.Caps.InputReportByteLength-1, 1);
if TheDev.Caps.OutputReportByteLength > 0 then
OutputLen.Caption := IntToHex(TheDev.Caps.OutputReportByteLength-1, 1);
if TheDev.Caps.FeatureReportByteLength > 0 then
FeatureLen.Caption := IntToHex(TheDev.Caps.FeatureReportByteLength-1, 1);
for I := 1 to 255 do
if TheDev.DeviceStrings[I] <> '' then
DevStrings.Items.Add(Format('%3d) %s',[I+1,TheDev.DeviceStrings[I]]));
for I := 0 to TheDev.LanguageStrings.Count - 1 do
LangStrings.Items.Add(TheDev.LanguageStrings[I]);
end;
end;
end.
--- NEW FILE: SimpleHIDWrite.dof ---
[Directories]
OutputDir=..\..\..\Bin
UnitOutputDir=..\..\..\Dcu
SearchPath=..\..\..\Source;..\..\..\Common
--- NEW FILE: SimpleHIDWrite.dpr ---
program SimpleHIDWrite;
uses
Forms,
DevReader in 'DevReader.pas' {Form1},
Info in 'Info.pas' {InfoForm};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
--- NEW FILE: SimpleHIDWrite.res ---
(This appears to be a binary file; contents omitted.)
|