View previous topic :: View next topic |
Author |
Message |
vtrx
Joined: 11 Oct 2017 Posts: 142
|
USB HID serial number |
Posted: Mon Apr 22, 2019 6:14 am |
|
|
I need to implement a serial number on my device.
Where do I need to change the descriptor to use the number string and what size does it need to be? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 22, 2019 10:33 am |
|
|
Look in this file: usb_desc_hid.h
It's in the CCS drivers folder. See these lines:
Quote: |
#if defined(USE_USB_SERIAL_NUMBER)
0x03, //index of string descriptor of serial number ==17
#else
0x00,
#endif
.
.
.
//string 3 - serial number (this is optional, but we specified it's use in the device descriptor)
USB_STRING("12345678")
|
CCS has put in a sample serial number of 12345678.
Also, see this line in ex_usb_hid.c:
Quote: | #define USE_USB_SERIAL_NUMBER
| It tells the .h file above to put in the serial number.
These lines are also in ex_usb_hid.c:
Quote: | #if defined(USE_USB_SERIAL_NUMBER)
#serialize(id=USB_STRING_DESC, unicode=3, prompt="Serial Number")
#endif |
They don't show it, but the #serialize is optional. If you are just making
one device, you could comment out the #serialize line and hard-code the
serial number as shown above as 12345678 or whatever number you choose. |
|
![](templates/subSilver/images/spacer.gif) |
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Mon Apr 22, 2019 12:30 pm |
|
|
PCM programmer wrote: | Look in this file: usb_desc_hid.h
It's in the CCS drivers folder. See these lines:
Quote: |
#if defined(USE_USB_SERIAL_NUMBER)
0x03, //index of string descriptor of serial number ==17
#else
0x00,
#endif
.
.
.
//string 3 - serial number (this is optional, but we specified it's use in the device descriptor)
USB_STRING("12345678")
|
CCS has put in a sample serial number of 12345678.
Also, see this line in ex_usb_hid.c:
Quote: | #define USE_USB_SERIAL_NUMBER
| It tells the .h file above to put in the serial number.
These lines are also in ex_usb_hid.c:
Quote: | #if defined(USE_USB_SERIAL_NUMBER)
#serialize(id=USB_STRING_DESC, unicode=3, prompt="Serial Number")
#endif |
They don't show it, but the #serialize is optional. If you are just making
one device, you could comment out the #serialize line and hard-code the
serial number as shown above as 12345678 or whatever number you choose. |
I just need to append this line #define USE_USB_SERIAL_NUMBER in main? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 22, 2019 12:49 pm |
|
|
You should look at ex_usb_hid.c. It shows that #define statement must
be placed above the #include lines for the usb drivers. It shows you
exactly where to place the #define. |
|
![](templates/subSilver/images/spacer.gif) |
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Mon Apr 22, 2019 5:20 pm |
|
|
PCM programmer wrote: | You should look at ex_usb_hid.c. It shows that #define statement must
be placed above the #include lines for the usb drivers. It shows you
exactly where to place the #define. |
I was able to record the serial, but it did not solve my problem.
I have a combo interface, joystick keyboard, with same PID and VID.
When I connect two equals, Windows can not use the two Joysticks, locking the test utility.
I thought about using a serial for each interface, but it did not work.
Only works if I change the PID for different numbers.
I will number one PID for each interface. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19378
|
|
Posted: Mon Apr 22, 2019 11:01 pm |
|
|
You can have two identical devices, with the same serial number and
still talk to them in Windows. It is dependant on the driver's ability
to support multiple devices. It's a known issue with Windows that dual
identical joysticks are difficult to handle with the standard driver.
However the HID instance ID will be different for each device (depends
on 'where' Windows finds the device). You will need to write your code
to access this.
Joystick.Properties.InterfacePath
will contain this data.
The entry will depend on what port the device is attached to.
If the device has a unique serial numbers, this is used, instead, so
you can identify the device without having to worry what port it is on. |
|
![](templates/subSilver/images/spacer.gif) |
|