hid_wrtite返回-1,通过调用hid_error返回函数不正确。

Apple Joke 2018-09-14 10:21:05
程序输出:
Starting F:\code\jiriheng\CommandTestApp\autoCommandTestApp\release\autoCommandTestApp.exe...
DLL_PROCESS_ATTACH Begin
DLL_PROCESS_ATTACH:autocommandtestapp.exe,ghijt32.dll
RegQueryValueEx(SYSTEM\CurrentControlSet\Services\) fail:2
LdSysCtrlDllName(C:\Inetpub\ftproot\Tipray\LdTerm\LdHook32.dll)
autocommandtestapp.exe Begin LoadLibrary(C:\Inetpub\ftproot\Tipray\LdTerm\LdHook32.dll)
DLL_PROCESS_ATTACH:f:\code\jiriheng\commandtestapp\autocommandtestapp\release\autocommandtestapp.exe:ldhook32.dll <1>
autoCommandTestApp.exe try hook...
[LdSysHook]==>HookFile::Init() <autoCommandTestApp.exe> InitCount<1>[LdSysHook]GH_SetHook(ZwQuerySystemInformation) success Process=<1976><autoCommandTestApp.exe>autoCommandTestApp.exe is Not Safe App
LoadLibrary(C:\Inetpub\ftproot\Tipray\LdTerm\LdHook32.dll) Success
Dewvice Handle:57610928

Manufacturer String: Touch Devic

Product String: Touch Device

Serial Number String: 00000000001A


Write Res = -1,error:函数不正确。
Read Ret = 0

部分代码:
#include "autocommandtest.h"
#include "ui_autocommandtest.h"
#include "../HidLib/hidapi.h"
#include "touchdevice.h"
#include "QDebug"
#include <windows.h>
#include <QString>

#define MAX_STR 255
#pragma comment(lib,"setupapi.lib")
#pragma comment(lib,"hid.lib")

AutoCommandTest::AutoCommandTest(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::AutoCommandTest)
{
ui->setupUi(this);


int res;
unsigned char buf[64];
wchar_t wstr[MAX_STR];
wchar_t *str_s = NULL;
hid_device *handle;
int i;


// Open the device using the VID, PID,
// and optionally the Serial number.
handle = hid_open(TOUCH_ViD, TOUCH_PiD_1, NULL);
qDebug("Dewvice Handle:%d\n",handle);

// Read the Manufacturer String
res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
qDebug("Manufacturer String: %ls\n", wstr);

// Read the Product String
res = hid_get_product_string(handle, wstr, MAX_STR);
qDebug("Product String: %ls\n", wstr);

// Read the Serial Number String
res = hid_get_serial_number_string(handle, wstr, MAX_STR);
qDebug("Serial Number String: %ls", wstr);
qDebug("\n");

// Send a Feature Report to the device


buf[0] = (INITIATIVE_REPORT); // First byte is report number
buf[1] = (VERSION);
buf[2] = (VER_BOARD_TYPE_GET);

// Set the hid_read() function to be non-blocking.
hid_set_nonblocking(handle, 1);

res = hid_write(handle, buf, 64);

qDebug("Write Res = %d,error:%ls",res,hid_error(handle));
// Read requested state
res = hid_read_timeout(handle, buf, 64,100);
if (res < 0)
{
qDebug("Unable to read()\n");
}
else
{
qDebug("Read Ret = %d\n",res);
}

// Print out the returned buffer.
for (i = 0; i < res; i++)
qDebug("buf[%d]: %d\n", i, buf[i]);

hid_close(handle);
}

AutoCommandTest::~AutoCommandTest()
{
delete ui;
}


这里面使用的hid.lib库是通过VS2010编译出来的,为什么write何read都不成功?急急急急
...全文
590 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:本文系统研究了构网型变流器的正负序阻抗解耦特性及其在弱电网环境下的稳定性表现,重点依托Matlab/Simulink仿真平台,构建了详细的阻抗数学模型,设计了解耦控制策略,并采用小信号扫频法进行频域辨识与稳定性验证。研究深入探讨了构网型变流器与传统跟网型逆变器在正负序阻抗特性上的本质差异,结合虚拟同步发电机(VSG)等先进控制技术,分析其在抑制宽频带振荡、削弱锁相环动态耦合等方面的优越性。文中不仅提供了完整的仿真模型与MATLAB代码实现,还整合了光伏、风电、储能、微电网等多类新能源系统的阻抗建模与稳定性分析资源,形成了一套面向新型电力系统稳定性的综合性技术资料体系,具有较强的科研复现与工程参考价值。; 适合人群:面向具备电力电子、电力系统自动化、新能源并网等专业背景的研究生、高校教师及工程技术人员,特别适用于从事阻抗建模、小干扰稳定性分析、宽频振荡机理研究以及撰写高水平学术论文的科研工作者。; 使用场景及目标:①掌握构网型变流器正负序阻抗建模与扫频辨识的仿真方法;②深入理解VSG等构网型控制在弱电网中提升稳定性的内在机理;③复现顶刊论文中的阻抗分析流程与稳定性判据应用;④利用提供的成熟模型与代码加速科研进程,支撑课题研究与学术成果产出。; 阅读建议:建议结合文中提供的Simulink模型与MATLAB代码,按照“理论建模—仿真搭建—扫频激励—频响提取—Nyquist判据分析”的完整流程进行实践操作,重点关注扫频信号的注入方式、频率范围设置及阻抗曲线的物理意义解读,并参考博士论文复现案例深化对复杂动态耦合问题的理解。

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧