Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The hid_write() returns -1 #395

Open
TimurAs opened this issue Apr 25, 2018 · 1 comment
Open

The hid_write() returns -1 #395

TimurAs opened this issue Apr 25, 2018 · 1 comment

Comments

@TimurAs
Copy link

TimurAs commented Apr 25, 2018

Hello, could you help me please.
I've installed the hidapi into my Qt project by the instruction from here
http://www.eliasing.com/qt/hid-qt
uses the hidapi-0.7.0 version , OS Windows 10
And it compiled well, then I reading the vid and pid, but the method hid_write()
exactly gives -1. _ tried to use latest version of hidapi_ (moved the folders with my version and put instead new, then cleaned my project, rebuild, rewrite the path to file hidapi.h)
And the same history - only reading the pid and vid

`MicroCont::MicroCont(QObject *parent) : QObject(parent)
{

devs = hid_enumerate(0x0, 0x0);
cur_dev = devs;
while (cur_dev) {
    qDebug() << "vendor_id: " << cur_dev->vendor_id;
    qDebug() << "product_id: " << cur_dev->product_id;
    qDebug() << "path: " << QString(cur_dev->path);
    qDebug() << "serial_number: " << cur_dev->serial_number;
    qDebug() << "manufacturer_string: " << cur_dev->manufacturer_string;
    qDebug() << "product_string: " << cur_dev->product_string << "\n";

    cur_dev = cur_dev->next;
}
hid_free_enumeration(devs);

//---------------------------------------------------------------------------------

res = hid_init();
qDebug() << res << 1;

handle = hid_open(0x046d, 0xc31c, NULL); 

if (handle == NULL) qDebug() <<"Handle is Null";
else
    qDebug() << "Hid opened: "<< handle;

}

MicroCont::~MicroCont()
{
res = hid_exit();
qDebug () << "hid exit: " << res << 3;
}

void MicroCont::writeHID() //THIS IS SLOT function, SO I USE IT BY THE BOTTON PUSH
{
// Read the Manufacturer String
res = hid_get_manufacturer_string(handle, wstr, MAX_STR); //THIS IS WORK
qDebug("\nManufacturer String: %ls", wstr);

    // Toggle LED (cmd 0x80). The first byte is the report number (0x0).
    buf[0] = 0x0;
    buf[1] = 0x80;

    res = hid_write(handle, buf, 65); //but this is NOT work
    qDebug () << res << 2;

}
`
I tried to write some command to my device, but it's owful. Please help, my brain is going to booom...

@ikillmeba
Copy link

guys, should notice the report id(maybe 0) and length(may be 65) of written on windows

erikolofsson pushed a commit to Malterlib/hidapi that referenced this issue May 14, 2022
Make buffer pointer NULL, once it is freed.

In hid_close() buffer pointer is freed and next to that the libusb_free_transfer function is called which checks for if the LIBUSB_TRANSFER_FREE_BUFFER flag is set and the buffer pointer is not NULL. when this condition evaluates true, it
tries to free memory for a buffer which is already free and a crash occurs.

Even though the described behavior should not happen as per libusb documentation, it has been observed with some version(s) of libusb.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants