I got help from the Psychtoolbox developer. And I understand I don't have to open the device, but can use HID report to control and query a device. Here is the reply.
"PsychHID on both Linux and Windows uses libusb-1.0 for low-level usb control transfers." For report related stuff, "it uses HIDAPI which itself uses libusb-1.0 on Linux and direct Windows calls on Windows." The V-USB "does the same, except that it uses the outdated libusb-0.1 instead of libusb-1.0 on Linux."
I tried the feature report with hid-data example in V-USB. It works under Linux with PsychHID, but with some unspecified error. Under Windows (XP and 7), PsychHID fails to send data to or receive data from the hid-data device, but apparently PsychHID connects to the device. The error message is "Data error (cyclic redundancy check)". I noted that the V-USB API doesn't check CRC at 12MHz, but I think this is irrelevant to above CRC error since they are at device side and host side respectively.
The hidtools.exe from V-USB works fine for both data write and read.
According to the suggestion from the Psychtoolbox developer, I downloaded the HIDAPI test tool from
https://github.com/signal11/hidapi, and ran its testgui under Windows. When I connect to hid device from the testgui, it shows it is connected, but gives error message "hid_read() returned error" continuously. If I try to send or get report, it gives me the CRC error message. I also changed the firmware to different examples, including hid-data, bootloaderHID, and mine (descriptor from ARV-Doper), and the error message is the same.
I noticed that V-USB recommends libusb or libusb-win32. This is different from what PsychHID uses. But does this make difference? What could be the reason for the CRC error?
Thanks.
-Xiangrui
xiangrui wrote:I am playing with the wonderful V-USB. With an atmega8 and a breadboard, I successfully made HIDkeys, hid-data and AVR-Doper work. What I like to build is a simple USB device which controls 2 or more TTL output. I also have some experience with AVR, so this should be easy. My difficulty is to figure out a way for driver-free device across major computer systems. According to V-USB wiki, it seems that Custom HID class device is what I need. One of examples of the class is the AVR-Doper. With the included usbasp-mega8-12mhz.hex, my device can be recognized as HID device on Windows and Linux machine. But I can't open it within Matlab by PsychHID from Psychtoolbox. This is the same for HIDkeys and hid-data. I understand that HIDkeys is like a keyboard, so it is occupied by the system, but why does it fail to open for hid-data and AVR-Doper? I don't have any HID device to test PsychHID, but it is available to multi-OS, and is used by many users. The source code for PsychHID is at
http://code.google.com/p/psychtoolbox-3/source/browse/trunk/PsychSourceGL/Source/Common/PsychHID/PsychHIDOpenUSBDevice.cDoes anyone have experience with this, or could anyone point me some hint? Thanks.
-Xiangrui