⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbio.pas

📁 6个用VB和DELPHI编写的FOR USB驱动程序
💻 PAS
📖 第 1 页 / 共 3 页
字号:
{
(c) 2001-2002 Thesycon Systemsoftware & Consulting GmbH


This program was developed with Delphi 5.

This is a sample program for the USBIOCOM interface. It
requires the registered USBIOCOM interface and the USBIO
device driver. Furthermore, an USB device is required.
This program does not use the complete functionality of 
the USBIOCOM interface. It is intended as a demonstration
of a typical usage scenario.

To compile the project the USBIOCOM object must be imported
into Delphi. Select "Project/Import Typelibrary ..." and import
the USBIOCOM object. Delphi generates a wrapper class
USBIOCOMLib_TLB.
Note: We deliver such a class with this project.
You should overwrite this class in the folder
where the project is installed.

An USB mouse or keyboard can be used as a demo device.
Note that those devices cannot be used as Windows 
input devices at the same time, e.g. as the system keyboard.

For more information about the USBIOCOM interface and the 
USBIO device driver refer to the documentation that can be 
found in usbiocom.pdf and usbioman.pdf.

For latest updates visit http://www.thesycon.de.


How to use this sample application:

1. Connect an USB device with at least one IN endpoint to the PC.

2. Use the USBIO install wizard to install the USBIO device driver
for this device.

3. Make sure that the USBIOCOM interface is registered on the PC.
Normally, this is done during installation.
You can run the command 
>regsvr32 usbiocom.dll
to register the USBIOCOM interface manually.

4. Run this application and carry out the following actions:
a) press "Enumerate" ->  Number of devices should be at least 1
b) press "Open"
c) switch to the "Interface" page
d) enter interface and alternate setting, press "Add Interface"
e) press "Set Conf"
f) enter the endpoint number (address), add 128 ($80) for IN endpoints
g) press "Bind"
h) switch to the "Read" page
i) press "Start Read"
j) press keys on the keyboard or move the mouse, 
   the file should contain the received data

}


unit USBIO;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, OleServer, USBIOCOMLib_TLB,ActiveX, ComCtrls, USBIOoutput,
  ExtCtrls;

type
  TMainDlg = class(TForm)
    ErrorText: TEdit;
    ClearError: TButton;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Enumerate: TButton;
    NumberOfDevices: TEdit;
    OpenDevice: TButton;
    DeviceNumber: TEdit;
    CloseDevice: TButton;
    GroupBox2: TGroupBox;
    DriverInfo: TButton;
    ApiVersion: TEdit;
    DriverVersion: TEdit;
    BuildVersion: TEdit;
    DriverFlags: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    GroupBox3: TGroupBox;
    GetStringDesc: TButton;
    StringDesc: TEdit;
    StringIndex: TEdit;
    TabSheet3: TTabSheet;
    GroupBox4: TGroupBox;
    AddInterface: TButton;
    DeleteInterface: TButton;
    InterfaceIndex: TEdit;
    AlternateSetting: TEdit;
    MaxTransferSize: TEdit;
    GroupBox5: TGroupBox;
    SetConf: TButton;
    ConfIndex: TEdit;
    UnConfigure: TButton;
    GroupBox6: TGroupBox;
    Bind: TButton;
    PipeNumber: TEdit;
    UnBind: TButton;
    TabSheet4: TTabSheet;
    GroupBox7: TGroupBox;
    StartReading: TButton;
    BufferSize: TEdit;
    NoOfBuffer: TEdit;
    MaxErrorCount: TEdit;
    StopRead: TButton;
    IsIso: TCheckBox;
    FileName: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    ProgressBar1: TProgressBar;
    TabSheet5: TTabSheet;
    GroupBox8: TGroupBox;
    CyclePort: TButton;
    ResetDevice: TButton;
    getframeno: TButton;
    frmno: TEdit;
    GroupBox9: TGroupBox;
    GetDevicePathName: TButton;
    GetDevicePathNamefield: TEdit;
    PowerState: TGroupBox;
    getpowerstate: TButton;
    getpowerstatefield: TEdit;
    setpowerstate: TButton;
    powerstatecombo: TComboBox;
    GroupBox10: TGroupBox;
    getstatus: TButton;
    statusindex: TEdit;
    statuscombo: TComboBox;
    statusout: TEdit;
    Label18: TLabel;
    Label19: TLabel;
    Devicedescriptorbox: TGroupBox;
    getdevicedescriptor: TButton;
    Feature: TTabSheet;
    Featurebox: TGroupBox;
    setfeature: TButton;
    featurecombo: TComboBox;
    featurefield: TEdit;
    featureindexfield: TEdit;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    clearfeature: TButton;
    GroupBox11: TGroupBox;
    GetDesc: TButton;
    DescType: TEdit;
    DescIndex: TEdit;
    DescSize: TEdit;
    Label23: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    TabSheet6: TTabSheet;
    GroupBox12: TGroupBox;
    StartWrite: TButton;
    StopWrite: TButton;
    writebuffersize: TEdit;
    writenumberofbuffers: TEdit;
    writeerrorcount: TEdit;
    Label26: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    writeisocheck: TCheckBox;
    writefile: TEdit;
    WriteStatusCheck: TCheckBox;
    OpenDialog1: TOpenDialog;
    OpenFile: TButton;
    FromFileCheck: TCheckBox;
    FilledWith: TEdit;
    Label29: TLabel;
    SaveDialog1: TSaveDialog;
    SaveFile: TButton;
    DataRate: TEdit;
    Label30: TLabel;
    Label31: TLabel;
    WriteToFile: TCheckBox;
    Label32: TLabel;
    Timer1: TTimer;
    PnPNotification: TGroupBox;
    EnablePnPNotification: TButton;
    DisablePnPNotification: TButton;
    TabSheet7: TTabSheet;
    showwindow: TButton;
    hidewindow: TButton;
    clearoutput: TButton;
    ClassOrVendorRequestBox: TGroupBox;
    VendorDirectionCombo: TComboBox;
    VendorTypeCombo: TComboBox;
    VendorRecipientCombo: TComboBox;
    VendorDirectionLabel: TLabel;
    VendorTypeLabel: TLabel;
    VendorRecipientLabel: TLabel;
    VendorRequestLabel: TLabel;
    VendorValueText: TEdit;
    VendorValueLabel: TLabel;
    VendorIndexText: TEdit;
    VendorIndexLabel: TLabel;
    VendorBufferSizeText: TEdit;
    VendorBufferText: TEdit;
    VendorBufferSizeLabel: TLabel;
    VendorBufferLabel: TLabel;
    VendorSendButton: TButton;
    VendorRequest: TEdit;
    DisableProgressBar: TCheckBox;
    procedure EnumerateClick(Sender: TObject);
    procedure OpenDeviceClick(Sender: TObject);
    procedure ClearErrorClick(Sender: TObject);
    procedure CloseDeviceClick(Sender: TObject);
    procedure DriverInfoClick(Sender: TObject);
    procedure GetStringDescClick(Sender: TObject);
    procedure DeleteInterfaceClick(Sender: TObject);
    procedure AddInterfaceClick(Sender: TObject);
    procedure SetConfClick(Sender: TObject);
    procedure UnConfigureClick(Sender: TObject);
    procedure StartReadingClick(Sender: TObject);
    procedure StopReadClick(Sender: TObject);
    procedure BindClick(Sender: TObject);
    procedure UnBindClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ShowError(Status: integer);
   
    procedure CyclePortClick(Sender: TObject);
    procedure ResetDeviceClick(Sender: TObject);
    procedure getframenoClick(Sender: TObject);
    procedure GetDevicePathNameClick(Sender: TObject);
    procedure getpowerstateClick(Sender: TObject);
    procedure setpowerstateClick(Sender: TObject);
    procedure getstatusClick(Sender: TObject);
    procedure setfeatureClick(Sender: TObject);
    procedure clearfeatureClick(Sender: TObject);
    procedure getdevicedescriptorClick(Sender: TObject);
    procedure showwindowClick(Sender: TObject);
    procedure hidewindowClick(Sender: TObject);
    procedure GetDescClick(Sender: TObject);
    procedure clearoutputClick(Sender: TObject);
    procedure StartWriteClick(Sender: TObject);
    procedure OpenFileClick(Sender: TObject);
    procedure StopWriteClick(Sender: TObject);
    procedure SaveFileClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Timer1Timer(Sender: TObject);
    procedure EnablePnPNotificationClick(Sender: TObject);
    procedure DisablePnPNotificationClick(Sender: TObject);
    procedure VendorSendButtonClick(Sender: TObject);

    // The following are the call-back functions.
    // They have to be implemented in the scope of a class; 
    // we use the main dialog class here.
    procedure ReadComplete(Sender: TObject; var Obj: OleVariant);
    procedure WriteComplete(Sender: TObject;  var Obj: OleVariant);
    procedure WriteStatus(Sender: TObject;  var Obj: OleVariant);
    procedure PnPAddNotification(Sender: TObject;  var Obj: OleVariant);
    procedure PnPRemoveNotification(Sender: TObject;  var Obj: OleVariant);


  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  // main dialog with the GUI
  MainDlg: TMainDlg;

  // The instance of the USBIOCOM interface.
  // TUSBIOInterface is defined in USBIOCOMlib_TLB which is
  // generated automatically from the USBIOCOM type library.
  // The instance must be initialized with TUSBIOInterface.Create(MainDlg).
  // Furthermore, the call-back functions have to be assigned.
  // For these steps, see the procedure InitUSBIOCom at the end of this file.
  USBIOInterface:  TUSBIOInterface;

  // The default GUID of the USBIO driver interface.
  // IMPORTANT: This should be replaced by a private GUID in a production version.
  // For details, refer to the manual and usbio.inf.
  USBIO_Default_GUID : string = '{325ddf96-938c-11d3-9e34-0080c82727f4}';


  // some helper variables
  status: integer;
  helpstatus : longword;
  UserId: integer;
  OutputFile: file;
  InputFile: textfile;
  IsIsoFlag: Boolean;
  FileOpenFlag: Boolean = false;
  IsReadStarted: Boolean = false;
  IsWriteStarted: Boolean = false;
  WriteSt: Boolean = false;
  // global arrays for read and isoread
  readbuffer,infobuffer,writebuffer, StatusArray: PSAFEARRAY;
  StartTime: double;
  TotalData: integer;

  // forward declarations
  procedure SendBuffer();
  procedure InitUSBIOCom();

implementation

{$R *.DFM}

// *****************************************************
// Enumeration Page
// *****************************************************
procedure TMainDlg.EnumerateClick(Sender: TObject);
var
  Device: integer;
begin
  USBIOInterface.EnumerateDevices(USBIO_Default_GUID,Device);
  MainDlg.NumberOfDevices.Text := inttostr(Device);
end;

// open device
procedure TMainDlg.OpenDeviceClick(Sender: TObject);
begin
  USBIOInterface.OpenDevice(strtoint(MainDlg.DeviceNumber.Text),status);
  ShowError(status);
end;

// close device
procedure TMainDlg.CloseDeviceClick(Sender: TObject);
begin
  USBIOInterface.CloseDevice;
end;

// get driver info
procedure TMainDlg.DriverInfoClick(Sender: TObject);
var
  api,drv,drvbuild,flags : integer;
begin
  USBIOInterface.GetDriverInfo(api,drv,drvbuild,flags,status);
  ShowError(status);
  if status = USBIO_ERR_SUCCESS then
  begin
    MainDlg.ApiVersion.Text := IntToHex(api div 256,1) + '.'+IntToHex(api mod 256,2);
    MainDlg.DriverVersion.Text := inttostr(drv div 256)+'.'+inttostr(drv mod 256);
    MainDlg.BuildVersion.Text := inttostr(drvbuild);
    MainDlg.DriverFlags.Text := inttostr(flags);
  end;
end;

// Enable PnP Notification
procedure TMainDlg.EnablePnPNotificationClick(Sender: TObject);
begin
  USBIOInterface.EnablePnPNotification(USBIO_Default_GUID,Status);
  ShowError(Status);
end;

// Disable PnP Notification
procedure TMainDlg.DisablePnPNotificationClick(Sender: TObject);
begin
  USBIOInterface.DisablePnPNotification(USBIO_Default_GUID,Status);
  ShowError(Status);
end;

// PnPAddNotification
procedure TMainDlg.PnPAddNotification(Sender: TObject; var Obj: OleVariant);
begin
  ErrorText.Text:='Device added !!!';
end;

// PnPRemoveNotification
procedure TMainDlg.PnPRemoveNotification(Sender: TObject; var Obj: OleVariant);
begin
  ErrorText.Text:='Device removed !!!';
end;


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -