CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

USB HID serial number

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
vtrx



Joined: 11 Oct 2017
Posts: 141

View user's profile Send private message

USB HID serial number
PostPosted: Mon Apr 22, 2019 6:14 am     Reply with quote

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?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 22, 2019 10:33 am     Reply with quote

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.
vtrx



Joined: 11 Oct 2017
Posts: 141

View user's profile Send private message

PostPosted: Mon Apr 22, 2019 12:30 pm     Reply with quote

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?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 22, 2019 12:49 pm     Reply with quote

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.
vtrx



Joined: 11 Oct 2017
Posts: 141

View user's profile Send private message

PostPosted: Mon Apr 22, 2019 5:20 pm     Reply with quote

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.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Apr 22, 2019 11:01 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group