<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">On Aug 28, 2015, at 2:21 PM, Rob Groner <<a href="mailto:rgroner@RTD.com" class="">rgroner@RTD.com</a>> wrote:<br class=""><div><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><div class="WordSection1" style="page: WordSection1; font-family: Helvetica; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">We’re wrapping up our first version of the UPS we’re making, and so I’m going over the USB code and came across one loose end.  The serial number of the unit (iSerialNumber according to the USB HID doc) is a constant, but it’s of course a different constant for each UPS.</div></div></div></blockquote><div><br class=""></div><div>iSerialNumber does not need to be unique per device - it is not very many bits wide.</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div class="WordSection1" style="page: WordSection1; font-family: Helvetica; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">  Right now we store that value in the Flash on the device, but the only way I’ve seen to pass the serial number over USB is to encode it as a constant in the code and then reference it as a USB HID String Index.  We aren’t going to rebuild/program for each UPS, so there must be a way to take the value in flash memory and send that as the serial number.  In other words, how do you send a “variable” length string across USB?  Actually, the length can be known ahead of time, but the data itself will be the variable.</div></div></div></blockquote><br class=""></div><div>NUT and other tools match against the string returned from the "get string descriptor" request (not iSerialNumber itself - the string indexed by it) and the procedure for modifying that is going to be specific to each USB device controller.</div><div><br class=""></div><div>Typically the string descriptor table is an array of pointers, and this is often why USB devices cluster the string indexes together starting at 1 (rather than having a sparse array). If you can make the pointer corresponding to the serial number point to RAM, you should be all set (Harvard architecture chips like PICs make this harder, but there is a C __attribute__ or something that you should be able to use). Otherwise, does your USB framework allow callbacks for arbitrary requests?</div><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px;"><div class="">-- </div><div class="">Charles Lepple</div><div class="">clepple@gmail</div><div class=""><br class=""></div></span><br class="Apple-interchange-newline">

</div>
<br class=""></body></html>