HID-USB RS232 Converter
- HID-USB RS232 Converter
CH9329 is a serial port to USB HID device function chip. According to different working modes, HID devices can be identified as USB keyboard devices, USB mouse devices or custom HID devices.
peculiarity
Chip factory built-in firmware program, no need for secondary development.
Support Windows/Linux/ Android /macOS and other operating systems, using the system built-in keyboard, mouse, HID device drivers, no additional installation.
Provides 4 working modes (single keyboard/mouse/custom HID function, or a combination of several functions).
Provides three serial communication modes (protocol transfer mode, ASCII mode, and transparent transmission mode).
Supports the configuration of USB device information, serial port communication addresses, and keyboard carriage returns.
Working mode
Working mode | Function description |
0 | USB keyboard +USB mouse + Custom HID |
1 | USB keyboard |
2 | USB keyboard +USB mouse |
3 | Custom HID |
Serial communication mode
Serial communication mode | Function description |
0 | Protocol transport mode |
1 | ASCII mode |
2 | Transparent mode |
USB keyboard function
The chip can realize the function of standard USB keyboard, which includes ordinary keys and multimedia keys.
This function is often used for: scanning code gun, cash register, keypad, remote control, etc.
USB mouse function
The chip can implement standard USB mouse functions, USB mouse includes relative mouse and absolute mouse.
This function is often used for: hardware version of the key genie, remote control, etc.
Customize HID functions
This custom is not the custom, the custom here actually refers to the HID subclass and protocol are 0 device type, not refers to the user can customize the category or HID report format, etc., compare it to a USB to serial device function that does not need to use COM port more image.
This function is often used: USB to serial port two-way data transparent transmission (no drive HID mode), with the keyboard and mouse function to provide the computer's data downtransmission channel.
Common Q&A
Q: How to choose the chip working mode?
A: Applicable scenarios for each working mode:
Mode 0: Scenarios where multiple functions are used at the same time (for example, when the keyboard and mouse functions are used, defined data is received from the computer), scenarios where a multimedia keyboard is required, and scenarios where chip parameters are obtained or configured through the USB channel.
Mode 1: Use a single USB keyboard function, and do not use a multimedia keyboard, for older computers that do not support composite devices.
Mode 2: Use both keyboard and mouse functions, and better compatibility with the mouse of Linux/Android/ Apple operating systems.
Mode 3: Use a single USB custom HID function, with computer software to achieve two-way data transmission and receiving of serial devices and computers, similar to USB virtual serial port (COM port) application, the difference is that you can not see the COM virtual port, but directly use the system HID API and device interaction.
Q: How do I select the serial port communication mode?
A: Applicable scenarios for each serial port communication mode:
Mode 0: Protocol transmission mode. This mode is applicable to scenarios where at least two functions are used at the same time, and scenarios where chip parameters need to be obtained or configured through the serial port channel.
Mode 1: ASCII mode, tailored for the USB keyboard function of the simple version of the key transmission mode, the mode will be the usual visible ASCII characters directly into the HID report of the key and the HID report of the key release, the converted characters mainly include: numbers 0~9, letters A~Z, Spaces and carriage returns.
Special keys, such as F1~F12, arrow keys, Shift and Ctrl keys, cannot be converted.
Mode 2: Transparent transmission mode, refers to the serial port data intact through USB packaging to the computer, this mode is suitable for custom HID mode, similar to USB to virtual serial port application effect.
Q: How to fill the protocol transfer mode keyboard package?
A: Command code to be used:
CMD_SEND_KB_GENERAL_DAT A | 0X02 | Send USB keyboard general data Send normal keyboard packets to the chip to simulate a normal key press or release action by this command |
CMD_SEND_KB_MEDIA_DATA | 0X03 | Send USB keyboard multimedia data Send multimedia keyboard packets to the chip to simulate multimedia key press or release action by this command |
Here, take USB keyboard common data as an example:
"2.2.2. CMD_SEND_KB_GENERAL_DATA"(Please refer to this chapter of the manual)
The core data of the serial port message is the 8 bytes in the middle. After the 8 data chips are extracted, they will be directly packaged and uploaded to the computer through USB. The content format is as follows:
Byte 1 | Byte 2 | Byte 3 | Byte 4 | Byte 5 | Byte 6 | Byte 7 | Byte 8 |
Control key | 0x00 | Key 1 | Key 2 | Key 3 | Key 4 | Key 5 | Key 6 |
For the key values of byte 3 to byte 8, see CH9329 Key Code Table in the document appendix.
For example, digits 1 to 0 correspond to HID Code: 0x1E to 0x27. If key 1 needs to be simulated, the 8-byte content is as follows:
Key 1 Press: {0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x00}
Key release: {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Confirm the middle 8-byte packet, and then transfer according to the protocol requirements, add the packet header, command code, address code and automatic calculation of the sum and so on can achieve keyboard control.
Example 1: Simulate that the "A" key is pressed and then released
Serial port: 57 AB 00 02 08 00 00 04 00 00 00 00 00 00 00 00 00 10
Chip upload: 57 AB 00 82 01 00 85
Serial port: 57 AB 00 02 08 00 00 00 00 00 00 00 00 00 00 0C
Chip upload: 57 AB 00 82 01 00 85
Example 2: Simulate first pressing "Left Shift" + "A" key, and then release:
Serial port: 57 AB 00 02 08 02 00 04 00 00 00 00 00 00 00 12
Chip upload: 57 AB 00 82 01 00 85
Serial port: 57 AB 00 02 08 00 00 00 00 00 00 00 00 00 00 0C
Chip upload: 57 AB 00 82 01 00 85
In addition to the above methods, you can also easily determine the required keyboard package in other ways during development. Use the USB analyzer software (such as USB2.0 Monitor or BusHound tool) to capture the USB package when the corresponding key is pressed on the USB keyboard on the computer, and then copy it for use.
Q: How to fill the protocol transfer mode mouse package?
A: Command code to be used:
Here, take USB versus mouse as an example:
The protocol documentation is more comprehensive and can be directly referred to. In addition, you can also use USB analyzer software (USB2.0 Monitor or BusHound and other tools) to capture the USB package when the USB mouse is operated on the computer, and then copy it down for use.
Q: Use the keyboard function encountered some machine key code upload incorrect?
A: If you encounter the problem of code loss, repetition or simply no response to multiple keyboard codes, you can troubleshoot from the following aspects:
1. Check whether the USB KeyBoard device is online during the upload. In the USB Keyboard list of the device Manager, check whether the keyboard for the CH9329 is available, right-click Properties, choose Details, and choose Hardware ID. The default VID is 0x1A86.
2. Check whether the serial port data and USB data meet the design expectations. If the protocol transmission mode is used, check whether the reply content of each serial port data packet is correct.
3. If no error is reported for serial port data or USB data, try to slow down the upload interval.
(1) In ASCII mode, control the sending interval between serial port characters. The recommended range is 5 to 50ms
(2) In protocol transmission or transparent transmission mode, control the packet interval of each keyboard packet, the recommended range is 10 to 100ms
4. If the host does not receive any data, the possible cause is: Some hosts can only use the keyboard with fixed VID and PID. In this case, use the configuration tool to change the USB ID of the CH9329 to the same as that of the original device.
5, if there is a continuous same key value in the uploaded keyboard data, only the first data is displayed, and the subsequent repeated data is not displayed.
In this case, the ASCII mode (one serial port corresponds to two keyboard packages: one key package and one release package) is not applicable, and the protocol transmission mode is required, in which the packet sending is changed to: continuously upload key and value key packages, and the last release package is transmitted after uploading.
6, a convenient way to locate the problem: After the compatibility problem occurs, if the machine has a scanning gun and other devices that are normally available, you can use the USB bus analyzer or other USB packet capture software to capture the communication packets between the scanning gun and the computer, and then use the CH9329 to simulate the packet sending rule of the device.
1st Mar 2024
Recent Posts
-
How to use Wiegand USB converter
Introduction1> This module has two function conversion functions as follows: The functions are n …6th Mar 2024 -
HID-USB RS232 Converter
HID-USB RS232 ConverterCH9329 is a serial port to USB HID device function chip. According to differe …1st Mar 2024 -
DL6 microwave sensor user's Guide
DL6 microwave sensor user's Guide1. Wiring definition: Brown, green Power supply …20th Dec 2023