Connection error with adapted Automator and LibUSB
Posted: Tue May 20, 2008 9:51 am
Hi!
I'm working with an AT90USBKEY from ATMEL (demo board with an AT90USB1287 on it) and at the moment I'm working on a host application, that allows to connect to my HID device.
On my AT90USB1287 I have a firmware running, that implements an HID Keyboard for a keymatrix connected to the AVR. Therefore I used the USB library MyUSB written by Dean Camera for the AT90USB family.
The next step in my project is to make it possible to change the keycodes, that are sent by pressing a button. Due to this, the user can define himeself, what function the F-buttons on the keymatrix have.
On the search how to realize this, I found the Automator application, that does similar things.
Ok, i have adapted the Automator host application to my needs, but when I try to send a keycode that was typed into my application, I get the errormessage:
Error writing to device: Communication error with device
In the Linux console from where I have startet my application, I geht following error:
Warning: could not set configuration: could not set config 1: Device or resource busy
Error sending message: error sending control message: Broken pipe
My question is now: Where is the problem?
I cant't find the problem in my code, perhaps someone here in the forum has any idea.
I have changed the communication thing from the FEATURE report to an OUT report:
My device has the following descriptors:
An endpoint for the datatransmission is also defined:
After this error I also tried to connect from a Windows XP, running in a VMware, but there my application can't even find the device.
Im using Kubuntu 7.10 on my computer...
THANKS FOR ANY HINT!
I'm working with an AT90USBKEY from ATMEL (demo board with an AT90USB1287 on it) and at the moment I'm working on a host application, that allows to connect to my HID device.
On my AT90USB1287 I have a firmware running, that implements an HID Keyboard for a keymatrix connected to the AVR. Therefore I used the USB library MyUSB written by Dean Camera for the AT90USB family.
The next step in my project is to make it possible to change the keycodes, that are sent by pressing a button. Due to this, the user can define himeself, what function the F-buttons on the keymatrix have.
On the search how to realize this, I found the Automator application, that does similar things.
Ok, i have adapted the Automator host application to my needs, but when I try to send a keycode that was typed into my application, I get the errormessage:
Error writing to device: Communication error with device
In the Linux console from where I have startet my application, I geht following error:
Warning: could not set configuration: could not set config 1: Device or resource busy
Error sending message: error sending control message: Broken pipe
My question is now: Where is the problem?
I cant't find the problem in my code, perhaps someone here in the forum has any idea.
I have changed the communication thing from the FEATURE report to an OUT report:
Code: Select all
static int uploadData(const char* data[5])
{
usbDevice_t *dev = NULL;
int err = 0, len;
char buffer[9];
if((err = usbOpenDevice(&dev, IDENT_VENDOR_NUM, IDENT_VENDOR_STRING, IDENT_PRODUCT_NUM, IDENT_PRODUCT_STRING, 1)) != 0){
fl_alert("Error opening USBKEY device: %s", usbErrorMessage(err));
goto errorOccurred;
}
len = sizeof(buffer);
buffer[0] = 0; /* report ID: setData */
memcpy(buffer + 1, data, 5);
if((err = usbSetReport(dev, USB_HID_REPORT_TYPE_OUTPUT, buffer, 6)) != 0){
fl_alert("Error writing to device: %s", usbErrorMessage(err));
goto errorOccurred;
}
errorOccurred:
if(dev != NULL)
usbCloseDevice(dev);
return err;
}
My device has the following descriptors:
Code: Select all
USB_Descriptor_HID_Keyboard_Report_t KeyboardReport PROGMEM =
{
ReportData:
{
0x05, 0x01, /* Usage Page (Generic Desktop) */
0x09, 0x06, /* Usage (Keyboard) */
0xa1, 0x01, /* Collection (Application) */
0x05, 0x07, /* Usage Page (Keyboard) */
0x19, 0xe0, /* Usage Minimum (Keyboard LeftControl) */
0x29, 0xe7, /* Usage Maximum (Keyboard Right GUI) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x01, /* Logical Maximum (1) */
0x75, 0x01, /* Report Size (1) */
0x95, 0x08, /* Report Count (8) */
0x81, 0x02, /* Input (Data, Variable, Absolute) */
0x95, 0x01, /* Report Count (1) */
0x75, 0x08, /* Report Size (8) */
0x81, 0x03, /* Input (Const, Variable, Absolute) */
0x95, 0x01, /* Report Count (1) */
0x75, 0x08, /* Report Size (8) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x65, /* Logical Maximum (101) */
0x05, 0x07, /* Usage Page (Keyboard) */
0x19, 0x00, /* Usage Minimum (Reserved (no event indicated)) */
0x29, 0x65, /* Usage Maximum (Keyboard Application) */
0x81, 0x00, /* Input (Data, Array, Absolute) */
0xc0, /* End Collection */
0x05,0xFF, /* Usage Page (Vendor defined) */
0xa1,0x01, /* Collection (Application) */
0x09,0x01, /* Usage (Vendor defined) */
0x75,0x08, /* Report Size (8) */
0x95,0x01, /* Report Count (1) */
0x91,0x02, /* Output (Data, Variable, Absolute) */
0xc0 /* End Collection */
}
};
An endpoint for the datatransmission is also defined:
Code: Select all
DataEndpoint:
{
Header: {Size: sizeof(USB_Descriptor_Endpoint_t), Type: DTYPE_Endpoint},
EndpointAddress: (ENDPOINT_DESCRIPTOR_DIR_OUT | DATA_EPNUM),
Attributes: EP_TYPE_INTERRUPT,
EndpointSize: KEYBOARD_EPSIZE,
PollingIntervalMS: 0x02
}
After this error I also tried to connect from a Windows XP, running in a VMware, but there my application can't even find the device.
Im using Kubuntu 7.10 on my computer...
THANKS FOR ANY HINT!