使用隐藏协议写入数据的USB设备。为什么我有错误吗?

30视图(30天)
嗨!
我试着飞行员的usb设备(ksn合成器mini-circuits测试板)通过usb HID协议(hid.dll)。基本功能的工作,除了当我试着写数据。实际上,当我写数据使用这条线:
(res, h) = calllib (“hidapi32”,“hid_write”,pbuf hid.handle uint64(长度(wmsg)));
答案总是“ 1 ”。你能指出我的错误在哪里?
谢谢。
完整的代码:
如果~ libisloaded (“hidapi32”)
[notfound,警告]= loadlibrary (“hidapi32_thunk_pcwin64.dll”,“hidapi.h”,“mfilename”,“mHeaderc”);
结束
calllib (“hidapi32”,“hid_init”);
libfunctions (“hidapi32”);
vendorID = 0;
productID = 0;
pointeur = calllib (“hidapi32”,“hid_enumerate”uint16 (vendorID) uint16 (productID));
结果= calllib (“hidapi32”,“hid_free_enumeration”pointeur)
pNull = libpointer (“uint16Ptr”);
藏不住的。vendorID = 8398;
藏不住的。productID = 32;
pointeur = calllib (“hidapi32”,“hid_enumerate”uint16 (hid.vendorID) uint16 (hid.productID));
str = calllib (“hidapi32”,“hid_free_enumeration”,pointeur);
(藏。处理,价值]= calllib (“hidapi32”,“hid_open”uint16 (hid.vendorID) uint16 (hid.productID) pNull);
hid.device = calllib (“hidapi32”,“hid_open_path”,str.path);
藏不住的。nReadBuffer = 256;
藏不住的。nWriteBuffer = 256;
缓冲= 0 (1、hid.nReadBuffer);
pbuf = libpointer (“uint16Ptr”uint16(缓冲));
(res, h) = calllib (“hidapi32”,“hid_get_product_string”,pbuf hid.handle uint64(长度(缓冲)));
藏不住的。product_string = sprintf (' % s 'char (pbuffer.Value));
缓冲= 0 (1、hid.nReadBuffer);
pbuf = libpointer (“uint16Ptr”uint16(缓冲));
(res, h) = calllib (“hidapi32”,“hid_get_serial_number_string”,pbuf hid.handle uint64(长度(缓冲)));
藏不住的。serial_number = pbuffer.Value (1);
缓冲= 0 (1、hid.nReadBuffer);
pbuf = libpointer (“uint16Ptr”uint16(缓冲));
(res, h) = calllib (“hidapi32”,“hid_get_manufacturer_string”,pbuf hid.handle uint64(长度(缓冲)));
藏不住的。manufacturer_string = sprintf (' % s 'char (pbuffer.Value));
暂停(1)
缓冲= 0 (1、hid.nWriteBuffer);
wmsg = [0 0 0 0 0 0 0 0 1 48 00 09 00 00 00 00 00 00);
wmsg(结束+ (hid.nWriteBuffer-length (wmsg))) = 0;
%创建一个unit8指针
pbuf = libpointer (“uint8Ptr”uint8 (wmsg));
%写消息
(res, h) = calllib (“hidapi32”,“hid_write”,pbuf hid.handle uint64(长度(wmsg)));
%检查响应
如果res ~ =长度(wmsg)
流(hidapi写错误:% d写道,% d \ n '(长度(wmsg) 1) res);
结束
calllib (“hidapi32”,“hid_close”,hid.handle);

答案(4)

Guillaume
Guillaume 2015年9月14日
它看起来像你可能使用 这个库 (信息应该包括在你的博文)。
的医生 hid_write 说它返回1错误,所以你的电话没有写任何你想写。根据医生,你可以获得更多关于错误的信息 hid_error 。我建议你试一下,你的问题不是由matlab引起的。
errcause = calllib (“hidapi32”,“hid_error”hid.handle)
2的评论
Guillaume
Guillaume 2015年9月14日
那么,如果你有visual studio,我建议你抓住的源代码库,使用visual studio的调试设备发现的问题是什么。
否则,找到一个库或联系开发人员邮件列表。

登录置评。


默罕默德naseem
默罕默德naseem 2020年1月8日
试试这个
我也面临这样问题,我解决这个问题
wmsg(结束+ (hid.nWriteBuffer-length (wmsg)) + 1) = 0;

RABEHI
RABEHI 2020年5月13日
编辑:RABEHI 2020年5月20日
你好,
我有一个模拟的项目,我的问题是,当我给 vendorID productID,什么也没有发生!
其结果是:
路径:
vendor_id: 0
product_id: 0
serial_number: []
release_number: 0
manufacturer_string: []
product_string: []
usage_page: 0
用法:0
interface_number: 0
下一个:[]
我必须提到我读librery如下:
目录“C: \ Windows \ SysWOW64”)
loadlibrary (“hidapi”)
我可以得到一些帮助吗?

Melwin托马斯
Melwin托马斯 2023年1月16日
相反的 hid_write “使用” hid_send_feature_report

标签

社区寻宝

找到宝藏在MATLAB中央,发现社区如何帮助你!

开始狩猎!