OpenQNX :: The QNX Community Portal

Oct 07, 2008 - 11:29 AM
Google
  Web openqnx.com   
     Create an account Home · Submit News · QNX Forums · QNX Download · Search   
_
Main Menu
Who's Online
There are 54 unlogged users and 0 registered users online.

You can log-in or register for a user account here.

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
jacus
Post subject: How to read serial number from USB device ?  PostPosted: Sep 05, 2007 - 02:26 PM
Senior Member


Joined: Apr 22, 2003
Posts: 238

Hi,

Here is a part of the 'usb' output:

USB 0 (EHCI) v1.10, v1.01 DDK, v1.01 HCD
Control, Interrupt, Bulk, High speed

Device Address : 1
Upstream Host Controller : 0
Upstream Device Address : 0
Upstream Port : 4
Upstream Port Speed : High
Vendor : 0x0951 (Kingston)
Product : 0x1600 (DataTraveler II )
Device Release : r1.00
USB Spec Release : v2.00
Serial Number : 5B6502002021

Which function from USB library can read the Serial Number field?
Is it usbd_string() ?
If yes how to determine it second parametr, called 'index' ?

Reagrds,
Jacek
 
 View user's profile Send private message  
Reply with quote Back to top
jacus
Post subject: Re: How to read serial number from USB device ?  PostPosted: Sep 06, 2007 - 10:35 AM
Senior Member


Joined: Apr 22, 2003
Posts: 238

Hi,

Here is my code:

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/usbdi.h>

#define VENDOR 0x0951
#define DEVICE 0x1600

usbd_device_ident_t interest = {
VENDOR,
DEVICE,
USBD_CONNECT_WILDCARD,
USBD_CONNECT_WILDCARD,
USBD_CONNECT_WILDCARD,
};

usbd_funcs_t funcs = {
_USBDI_NFUNCS,
NULL,
NULL,
NULL
};

usbd_connect_parm_t cparms = {
NULL,
USB_VERSION,
USBD_VERSION,
0,
0, // argc
NULL, // *argv
0,
&interest,
&funcs
};

struct usbd_connection *connection;
struct usbd_device *device;
usbd_device_instance_t instance;

usbd_device_descriptor_t *ddesc=NULL;
struct usbd_desc_node *node=NULL;
usbd_string_descriptor_t *sdesc=NULL;

int main (void) {
int error,status;
int devno,hostid;
char* ID;

error = usbd_connect (&cparms, &connection);
if (error != EOK) {
printf ("\n usbd_connect() error number: %d \n",error);
return -1;
}

instance.config = 1;
instance.iface = 0;
instance.alternate = 0;

for (hostid =0; hostid < 8; ++hostid) {
for (devno = 0; devno < 16; ++devno) {
memset(&instance, USBD_CONNECT_WILDCARD,
sizeof(usbd_device_instance_t));
instance.path = hostid, instance.devno = devno;
status = usbd_attach(connection, &instance,0,&device);
// the device has been found
if (status == EOK) {
ddesc = usbd_device_descriptor(device,&node );
if (ddesc == NULL ) {
printf("\n usbd_device_descriptor () error !!\n");
return -1;
}
// is it a specific device ?
if (ddesc->idVendor == VENDOR) {
sdesc = usbd_languages_descriptor(device,&node );
ID = usbd_string(device,3,sdesc->bString[0]);
printf ("\n I found it -> hostid: %d, devno: %d, seriall number:
%s \n",hostid,devno,ID);
if (usbd_detach (device) != EOK)
printf ("\n usbd_detach (): error ! \n");
}
else {
if (usbd_detach (device) != EOK)
printf ("\n usbd_detach (): error ! \n");
}
}
}
}
if (usbd_disconnect(connection )!= EOK)
printf ("\n usbd_disconnect (): error ! \n");

return 0;
}

and it works fine under QNX Neutrino.

But I have some problems under QNX4.
I compile application as follows:
# cc -lusbdi -liomgr -T1 -o usb_test usb_test.c

but it returns everytime:
# ./usb_test

usbd_connect() error number: 275

Why I can't connect to the USB stack ?
Am I doing something wrong ?

Regards,
Jacek


Użytkownik "Jacek Rudnicki" <jacek.rudnicki@quantum.com.pl> napisał w
wiadomości news:fbme0d$kp9$1@inn.qnx.com...
Quote:
Hi,

Here is a part of the 'usb' output:

USB 0 (EHCI) v1.10, v1.01 DDK, v1.01 HCD
Control, Interrupt, Bulk, High speed

Device Address : 1
Upstream Host Controller : 0
Upstream Device Address : 0
Upstream Port : 4
Upstream Port Speed : High
Vendor : 0x0951 (Kingston)
Product : 0x1600 (DataTraveler II )
Device Release : r1.00
USB Spec Release : v2.00
Serial Number : 5B6502002021

Which function from USB library can read the Serial Number field?
Is it usbd_string() ?
If yes how to determine it second parametr, called 'index' ?

Reagrds,
Jacek

 
 View user's profile Send private message  
Reply with quote Back to top
jacus
Post subject: Re: How to read serial number from USB device ?  PostPosted: Sep 10, 2007 - 01:01 PM
Senior Member


Joined: Apr 22, 2003
Posts: 238

Now running previous release of the USB stack (devu-uhci) is little better.
The usbd_connect () function works fine, but I can attach to the USB stack
only when all fields of the 'instance' structure are set including device
and
vendor id.

Another thing is that all functions which use device pointer as a parameter
(i.e usbd_device_descriptor(), usbd_languages_descriptor(), usbd_string() )
return NULL.

Did I miss something ?
How can I solve this problem ?

Source code attached.

Regards,
Jacek


Użytkownik "Jacek Rudnicki" <jacek.rudnicki@quantum.com.pl> napisał w
wiadomości news:fbokru$mtm$1@inn.qnx.com...
Quote:
Hi,

Here is my code:

#include <stdio.h
#include <stdlib.h
#include <errno.h
#include <sys/usbdi.h

#define VENDOR 0x0951
#define DEVICE 0x1600

usbd_device_ident_t interest = {
VENDOR,
DEVICE,
USBD_CONNECT_WILDCARD,
USBD_CONNECT_WILDCARD,
USBD_CONNECT_WILDCARD,
};

usbd_funcs_t funcs = {
_USBDI_NFUNCS,
NULL,
NULL,
NULL
};

usbd_connect_parm_t cparms = {
NULL,
USB_VERSION,
USBD_VERSION,
0,
0, // argc
NULL, // *argv
0,
&interest,
&funcs
};

struct usbd_connection *connection;
struct usbd_device *device;
usbd_device_instance_t instance;

usbd_device_descriptor_t *ddesc=NULL;
struct usbd_desc_node *node=NULL;
usbd_string_descriptor_t *sdesc=NULL;

int main (void) {
int error,status;
int devno,hostid;
char* ID;

error = usbd_connect (&cparms, &connection);
if (error != EOK) {
printf ("\n usbd_connect() error number: %d \n",error);
return -1;
}

instance.config = 1;
instance.iface = 0;
instance.alternate = 0;

for (hostid =0; hostid < 8; ++hostid) {
for (devno = 0; devno < 16; ++devno) {
memset(&instance, USBD_CONNECT_WILDCARD,
sizeof(usbd_device_instance_t));
instance.path = hostid, instance.devno = devno;
status = usbd_attach(connection, &instance,0,&device);
// the device has been found
if (status == EOK) {
ddesc = usbd_device_descriptor(device,&node );
if (ddesc == NULL ) {
printf("\n usbd_device_descriptor () error !!\n");
return -1;
}
// is it a specific device ?
if (ddesc->idVendor == VENDOR) {
sdesc = usbd_languages_descriptor(device,&node );
ID = usbd_string(device,3,sdesc->bString[0]);
printf ("\n I found it -> hostid: %d, devno: %d, seriall
number:
%s \n",hostid,devno,ID);
if (usbd_detach (device) != EOK)
printf ("\n usbd_detach (): error ! \n");
}
else {
if (usbd_detach (device) != EOK)
printf ("\n usbd_detach (): error ! \n");
}
}
}
}
if (usbd_disconnect(connection )!= EOK)
printf ("\n usbd_disconnect (): error ! \n");

return 0;
}

and it works fine under QNX Neutrino.

But I have some problems under QNX4.
I compile application as follows:
# cc -lusbdi -liomgr -T1 -o usb_test usb_test.c

but it returns everytime:
# ./usb_test

usbd_connect() error number: 275

Why I can't connect to the USB stack ?
Am I doing something wrong ?

Regards,
Jacek


Użytkownik "Jacek Rudnicki" <jacek.rudnicki@quantum.com.pl> napisał w
wiadomości news:fbme0d$kp9$1@inn.qnx.com...
Hi,

Here is a part of the 'usb' output:

USB 0 (EHCI) v1.10, v1.01 DDK, v1.01 HCD
Control, Interrupt, Bulk, High speed

Device Address : 1
Upstream Host Controller : 0
Upstream Device Address : 0
Upstream Port : 4
Upstream Port Speed : High
Vendor : 0x0951 (Kingston)
Product : 0x1600 (DataTraveler II )
Device Release : r1.00
USB Spec Release : v2.00
Serial Number : 5B6502002021

Which function from USB library can read the Serial Number field?
Is it usbd_string() ?
If yes how to determine it second parametr, called 'index' ?

Reagrds,
Jacek






begin 666 USB_Kingston.c
M(VEN8VQU9&4@/'-T9&EO+F@^#0HC:6YC;'5D92 \<W1D;&EB+F@^#0HC:6YC
M;'5D92 \97)R;F\N:#X-"B-I;F-L=61E(#QS>7,O=7-B9&DN:#X-"@T*(V1E
M9FEN92!614Y$3U()(" P># Y-3$-"B-D969I;F4@1$5624-%"2 @,'@Q-C P
M#0HC9&5F:6YE($-,05-3"2 @,'@P,# X#0HC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@/3T@3E5,3" I('L-"@D)"0D@<')I;G1F*")<;B!U<V)D
M7V1E=FEC95]D97-C<FEP=&]R("@I(&5R<F]R("$A7&XB*3L-"@D)"0D@<F5T
M=7)N("TQ.PT*(" @(" @(" @(" @("!]#0H-"@D@(" @(" @($E$(#T@=7-B
M9%]S=')I;F<H9&5V:6-E+#,L,'@P-# Y*3L)"0D)( T*( D)("!I9B H240@
M(3T@3E5,3"D)#0H)(" @(" @(" @("!P<FEN=&8@*")<;B!)(&9O=6YD(&1E
M=FEC92!H;W-T:60Z("5D+"!D979N;SH@)60L('-E<FEA;"!N=6UB97(Z("5S
M(%QN(BQH;W-T:60L9&5V;F\L240I.PT*"0D@(&5L<V4-"B @(" )"2 @(" @
M<')I;G1F("@B7&X@=7-B9%]S=')I;F<H*2!E<G)O<B A(2!<;B(I.PD-"@D@
M( D@(&EF("AU<V)D7V1E=&%C:" H9&5V:6-E*2 A/2!%3TLI#0H)"2 @(" @
M<')I;G1F("@B7&X@=7-B9%]D971A8V@@*"DZ(&5R<F]R("$@7&XB*3L)"0D@
M(" @(" @(" -"B @(" @(" @(" @?2 @(" @(" @(" @"2 @#0H@(" @(" @
M?0T*"7T-"@EI9B H=7-B9%]D:7-C;VYN96-T*&-O;FYE8W1I;VX@*2$]($5/
M2RD-"B @(" @("!P<FEN=&8@*")<;B!U<V)D7V1I<V-O;FYE8W0@*"DZ(&5R
L<F]R("$@7&XB*3L-"@D@(" @(" @(" @"2 @( T*("!R971U<FX@,#L-"GT`
`
end
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits
All logos and trademarks in this site are property of their respective owners. The comments are property of their posters.
Powered by OpenQNX: The QNX Community Portal Site
QNX and the QNX logo are registered trademarks of QNX Software Systems.