libusb:这些读错误的来源是什么?

时间:2015-06-03 21:18:34

标签: c++ arduino libusb libusb-1.0

我发送的英文字母从Arduino到我的笔记本电脑有一秒钟的延迟:

void loop() 
{
    delay(1000);
    Serial.write('N'); 

}

我正在尝试使用libusb从C ++程序中捕获并打印字母表。以下是代码的相关部分:

while(1)
{
        r = libusb_bulk_transfer(dev_handle, 131, data, 1, &actual, 0); 
        if(r == 0 && actual == 1) //we read 1 byte successfully
                cout<<"Read Successful! Data recieved is "<<data[0]<<endl;
        else
                cout<<"Read Error! Return value: "<<r
                    <<"Actual  bytes recieved = "<<actual<<endl;

}

这是我得到的输出:

Read Successful! Data recieved is A
Read Error! Return value: 0Actual  bytes recieved = 0
Read Successful! Data recieved is B
Read Successful! Data recieved is C
Read Successful! Data recieved is D
Read Error! Return value: 0Actual  bytes recieved = 0
Read Successful! Data recieved is E
Read Error! Return value: 0Actual  bytes recieved = 0
Read Successful! Data recieved is F
Read Error! Return value: 0Actual  bytes recieved = 0
Read Successful! Data recieved is G
Read Error! Return value: 0Actual  bytes recieved = 0
Read Successful! Data recieved is H
Read Error! Return value: 0Actual  bytes recieved = 0
Read Successful! Data recieved is I
Read Error! Return value: 0Actual  bytes recieved = 0
Read Successful! Data recieved is J
Read Error! Return value: 0Actual  bytes recieved = 0
Read Successful! Data recieved is K
Read Error! Return value: 0Actual  bytes recieved = 0
Read Successful! Data recieved is L
Read Error! Return value: 0Actual  bytes recieved = 0
Read Successful! Data recieved is M
Read Error! Return value: 0Actual  bytes recieved = 0
Read Successful! Data recieved is N
Read Error! Return value: 0Actual  bytes recieved = 0
Read Successful! Data recieved is O
Read Successful! Data recieved is P
Read Error! Return value: 0Actual  bytes recieved = 0
Read Successful! Data recieved is Q
Read Error! Return value: 0Actual  bytes recieved = 0

我观察到每一秒Arduino发送一个字母表,我的程序一定会抓住它。但几乎所有时间,屏幕上都会打印读取错误以及捕获的对象。造成这种情况的原因是什么,如何阻止它?

我找到了Serial.write()here的源代码,但我无法理解它。

0 个答案:

没有答案