ArticleDirectory
- Method -:
- Method 2:
- Use Windows APIs
- MSComm control used in MFC
- Use USB to serial drive cypress_m8.ko (kernel> = 2.6)
- Use hiddev
Introduction: USB 2com is a virtual serial port driver of USB to serial port converter. Program (Windows2000/XP), USB-HID-> com converter (not tested) for the proxyess, and compatible devices. USB-HID-> com converter is compatible with USB hid devices, so you can access it directly with USB _ hid devices without using this driver.
Features:
- You can set the baud rate, parity, and stop bits.
- Event detection. Only serial_ev_rxchar | serial_ev_rxflag | serial_ev_txempty is supported.
- Data Flow Control. Todo
- Timeout settings. Todo
Installation Method -:
- Insert the hid-> com converter into the USB port.
- The hid-> com converter is recognized as a USB ergonomic input device.
- Choose Device Manager> ergonomic input device> USB ergonomic input device, and right-click the device.
- Select Update driver.
- Select to install from the list or a specified location, and click Next.
- Select do not search. I want to select the driver to be installed and click Next.
- Select the path where the driver is installed from the disk, and click OK.
- The system prompts that the Windows logo test is not passed and the option continues.
- After the installation is complete, the USB-HID-> COMM port (COM?) is displayed under the Port (COM and LPT) item ?).
Method 2: Use the installer. -;) Accessing the device
- Use Windows APIs
- Blocked read/write comtst. c
- Detection event comevent. c
- Appropriate timeout settings can be used to implement readfile return when data is available, and blocking when no data is available.
Commtimeouts. readintervaltimeout = 3; commtimeouts. Timeout = 0; commtimeouts. Timeout = 0; commtimeouts. Timeout = 0; commtimeouts. Timeout = 0; BRC = setcommtimeouts (hcomatrix, & commtimeouts );
- MSComm control used in MFC
- Vc6.0 project menu ---> Add to project ---> components and controls ---> registered ActiveX controls, select components: Microsoft Communications Control to insert to the current workspace. The result adds the cmscomm class (and corresponding files: MSComm. h and MScomm. cpp ).
- ... See http://www.gjwtech.com/scomm/scmfcprogramfujie.htm
- Access with USB hid Devices
- Open the device: bool bopenhiddevice (handle * hiddevhandle, ushort vid, ushort PID)
- Set the baud rate, parity, and stop bit:
Outbuffer [0] = 0;/* No report ID */* (unsigned int *) & outbuffer [1] = 19200; /* baud rate * // * configuration byte7 6543210reset0 parity typeparity enablestop bits0data bits */outbuffer [5] = 0x03;/* Data bit 8, no parity check, stop bit 1 */bresult = hidd_setfeature (hiddevhandle, outbuffer, capabilities. featurereportbytelength); If (bresult) {} elseprintf ("hidd_setfeature failed % d \ n", getlasterror ());
- Read/write data
Outbuffer [0] = 0;/* No report ID */outbuffer [1] = 7;/* Data Length */For (INT I = 0; I <7; I ++) outbuffer [2 + I] = 'A' + I; bresult = writefile (hiddevhandle, & outbuffer [0], capabilities. outputreportbytelength, & numbytesreturned, null); inbuffer [0] = 0;/* No report ID */bresult = readfile (hiddevhandle, & inbuffer [0], capabilities. inputreportbytelength, & numbytesreturned, null); If (bresult) {// dump data printf ("Len = % d \ n", inbuffer [1]); for (INT I = 0; I <inbuffer [1]; I ++) printf ("% C", inbuffer [I + 2]);}
How the driver works with todo. Use USB-HID-> com converter in Linux
- Use USB to serial drive cypress_m8.ko (kernel> = 2.6)
- Insert the device. If the driver cannot be installed automatically, run modprobe cypress_m8.
- It can be like accessing a common serial port device (/dev/TTYs ?) In this way, access this device (/dev/ttyusb ?).
Use libusb Testlibusb. c
Todo. Reference:
- different ways of handling IRPs
- proper completion -- resubmitting IRPs from within a completion routine
- using the hid class eases the job of writing USB device drivers
- http://www.lvr.com/hidpage.htm
- http://www.gjwtech.com/serialcomm.htm