DELPHI HBP-1100U 欧姆龙血压计的USB调用方法


本文整理自网络,侵删。

 
安装HIDcontroller控件。
1、用USB设备名获取VID,PID,建立临时缓冲区。
2、checkout建立usb设备的线程
3、拔插下来checkin销毁线程
4、通过ondata事件获取数据指针
5、通过数据指针对16进制数进行转换10进制,并处理显示



unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,StdCtrls, JvHidControllerClass;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Memo1: TMemo;
    JvHidDeviceController1: TJvHidDeviceController;
    procedure JvHidDeviceController1Arrival(HidDev: TJvHidDevice);
    procedure JvHidDeviceController1DeviceChange(Sender: TObject);
    procedure JvHidDeviceController1Removal(HidDev: TJvHidDevice);
    procedure JvHidDeviceController1DeviceData(HidDev: TJvHidDevice;
      ReportID: Byte; const Data: Pointer; Size: Word);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
   
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  a:TJvHidDevice;
     USB_VID,USB_PID:word;
   function HexToDec(const AHexString: String): Integer;


implementation

{$R *.dfm}


function HexToDec(const AHexString: String): Integer;
begin
Result := StrToInt('$' + AHexString);
end;



procedure TForm1.JvHidDeviceController1Arrival(HidDev: TJvHidDevice);
begin
    if HidDev.ProductName='OMRON Blood pressure monitor' then
    begin
        memo1.Lines.Add(Format('设备连接成功.【%s ; %s】', [HidDev.ProductName, HidDev.SerialNumber]));
        memo1.Lines.Add(Format('VID:%.4x/PID:%.4x', [HidDev.Attributes.VendorID,HidDev.Attributes.ProductID]));
        USB_VID:=HidDev.Attributes.VendorID;
        USB_PID:=HidDev.Attributes.ProductID;
    end;
end;

procedure TForm1.JvHidDeviceController1DeviceChange(Sender: TObject);
begin
  if JvHidDeviceController1.CheckOutByID(a, USB_VID, USB_PID) then
    begin
        a.NumInputBuffers := 128;
        a.NumOverlappedBuffers := 128;
    end;
end;

procedure TForm1.JvHidDeviceController1Removal(HidDev: TJvHidDevice);
begin
    if (HidDev.Attributes.VendorID = USB_VID) and (HidDev.Attributes.ProductID = USB_PID) then
    begin
        if (Assigned(a)) and (not a.IsPluggedIn) then
        begin
            JvHidDeviceController1.CheckIn(a);
        end;
        a := nil;
        //DeviceEnabled;
       memo1.Lines.Add('设备已移除');
    end;
end;

procedure TForm1.JvHidDeviceController1DeviceData(HidDev: TJvHidDevice;
  ReportID: Byte; const Data: Pointer; Size: Word);
begin
  if (HidDev.Attributes.VendorID = USB_VID) and (HidDev.Attributes.ProductID = USB_PID) then
    begin
        memo1.Lines.Add(Format('收到数据.【%s ; %s】', [HidDev.ProductName, HidDev.SerialNumber]));
        memo1.Lines.Add(pchar(data));
        edit1.Text:=floattostr(HexToDec(copy(pchar(data),6,4))/128);
        edit2.Text:=floattostr(HexToDec(copy(pchar(data),10,4))/128);
        edit3.text:=floattostr(HexToDec(copy(pchar(data),14,2)))
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.Clear;
end;

end.


相关阅读 >>

Delphi 之前解析串口数据

Delphi纯api窗体程序

Delphi数据库实现从最后一条记录向上查询至首记录

Delphi access存储过程是带参数的查询语句

Delphi时间相减函数

Delphi 如何在tmemo,tedit或trichedit中获得插入符的位置

Delphi - 如何执行windows、osx、linux的外部程序?

Delphi rest请求控件增加请求头时不编码

Delphi通过wmi获取系统信息

Delphi 取出一个字符在字符串出现的次数

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...