Why is usb hid getting slow speed?
-
Hello !
I am using hid_device, to read data from incoming usb port (this data I get is transmitted by mcu)
Here is my receive interrupt function, it works fine, but only at 10ms 1 time,QObject::connect(this,SIGNAL(hiddataarrived(unsigned char *, unsigned char)),this,SLOT(Outdata(unsigned char *, unsigned char))); void MainWindow::Outdata(unsigned char *data, unsigned char length) // slot { QString chuoi; for(int i=0;i<length;i++) { chuoi.append(data[i]); } ui->textEdit_2->append(chuoi); // show on textedit }
when i increase the speed between transmissions, about 5ms 1 time, some data is lost
Is it because the show function on textedit makes it late? or what is the reason?Thank you !
-
@DQUY05 said in Why is usb hid getting slow speed?:
hiddataarrived
Where does this signal comes from? It's not a Qt signal and we don't know what it does/where it comes from.
-
Hello !
I am using hid_device, to read data from incoming usb port (this data I get is transmitted by mcu)
Here is my receive interrupt function, it works fine, but only at 10ms 1 time,QObject::connect(this,SIGNAL(hiddataarrived(unsigned char *, unsigned char)),this,SLOT(Outdata(unsigned char *, unsigned char))); void MainWindow::Outdata(unsigned char *data, unsigned char length) // slot { QString chuoi; for(int i=0;i<length;i++) { chuoi.append(data[i]); } ui->textEdit_2->append(chuoi); // show on textedit }
when i increase the speed between transmissions, about 5ms 1 time, some data is lost
Is it because the show function on textedit makes it late? or what is the reason?Thank you !
@DQUY05 said in Why is usb hid getting slow speed?:
void MainWindow::Outdata(unsigned char *data, unsigned char length) // slot
{
QString chuoi;
for(int i=0;i<length;i++)
{
chuoi.append(data[i]);
}
ui->textEdit_2->append(chuoi); // show on textedit
}Hi,
Beside the information requested by @Christian-Ehrlicher, this loop is unnecessary. QString can be built taking a char * and a length. Check the fromXXX methods.
-
@DQUY05 said in Why is usb hid getting slow speed?:
hiddataarrived
Where does this signal comes from? It's not a Qt signal and we don't know what it does/where it comes from.
@Christian-Ehrlicher
Here is the signal constructor, the interrupt occurs every time there is data from the usb port (64 bytes), and if I remove the command QCoreApplication::processEvents();
the program freezesvoid MainWindow::run() { int res,i; unsigned char buf1[64]; while(isopen==1) { res=hid_read(target, buf1, 64); // read data from usb_hid if(res==-1) // if an error occurs { isopen=0; ui->listWidget->clear(); ui->pushButton_2->setText("Not connect"); } else if(res==0) // No data {} else //if(res>0) { unsigned char datas[64]; for(i=0;i<64;i++) { datas[i]=buf1[i]; } emit hiddataarrived(datas,64); } QCoreApplication :: processEvents (); //avoid freezing } }
The receive interrupt speed I need it to achieve at 100us per 64 byte transmission, but currently only 10ms per 64 byte transmission, as the baud rate increases, the data will be interrupted
Thanks!
-
@DQUY05 said in Why is usb hid getting slow speed?:
void MainWindow::Outdata(unsigned char *data, unsigned char length) // slot
{
QString chuoi;
for(int i=0;i<length;i++)
{
chuoi.append(data[i]);
}
ui->textEdit_2->append(chuoi); // show on textedit
}Hi,
Beside the information requested by @Christian-Ehrlicher, this loop is unnecessary. QString can be built taking a char * and a length. Check the fromXXX methods.
@SGaist said in Why is usb hid getting slow speed?:
QString can be built taking a char * and a length
Dear Sir !
Sorry, I'm newbie, and my English is not very good, you mean QString::fromUtf8(data,length);
I tried, but I don't know if this is correct, but I don't get a QStringvoid MainWindow::Outdata(const char *data, unsigned char length) // slot { QString chuoi; // for(int i=0;i<length;i++) // { // chuoi.append(data[i]); // } chuoi=QString::fromUtf8(data,length); ui->textEdit_2->append(chuoi); // show on textedit }
I don't know how to use this structure, is it because my loop is late and lose data?
Many thanks!
-
@DQUY05 said in Why is usb hid getting slow speed?:
hid_read
When this is a blocking function than you must not do this in the main thread. Move this out into another thread.
And only reading 64 bytes at once can not be "fast". -
@DQUY05 said in Why is usb hid getting slow speed?:
hid_read
When this is a blocking function than you must not do this in the main thread. Move this out into another thread.
And only reading 64 bytes at once can not be "fast".@Christian-Ehrlicher
Thank you,
I am using libusb (usb_hid), and also know the max speed is about 64Kbyte/s, here mine is 64Byte/5ms = 12.5Kbyte/s, anyway my project will accept working at this speed.When this is a blocking function than you must not do this in the main thread. Move this out into another thread.
Sorry, I don't know how?
Many thanks!
-
Since you are pretty new to all of this, you might want to consider using a library wrapping libusb for Qt.
On a side note, many MCUs have serial port to communicate with which is usually way simpler to use. Is it not the case of yours ?
-
Since you are pretty new to all of this, you might want to consider using a library wrapping libusb for Qt.
On a side note, many MCUs have serial port to communicate with which is usually way simpler to use. Is it not the case of yours ?
@SGaist
Thank you !Since you are pretty new to all of this, you might want to consider using a library wrapping libusb for Qt.
You are right, I am using this set of libraries.
On a side note, many MCUs have serial port to communicate with which is usually way simpler to use. Is it not the case of yours ?
Serial port I have successfully done, however it is asynchronous communication, and the speed is usually lower than usb_hid, in this project of mine, which requires using usb_hid, I have increased the speed to 25Kbyte/s, and got the desired result, please write to solve the problem, in the future if anyone can increase the speed, hope to have development
Regards !