Well you don't need to make the listener a Thread/Runnable, and you really 
don't need to include busy loops (you have 2 different ones!) that will 
do nothing by shoot your CPU usage up to 100%! :)

But I see the problem, you're not calling UsbServices.getRootUsbHub(), 
which (in the Linux imp) is what initializes the subsystem.  So it's not 
actually listening to the bus for anything.  I guess that's actually a 
bug, but I've never seen anyone just use a listener and not check what's 
currently connected to the bus.

So your problem is either a bug on my part, try calling 
service.getRootUsbHub() right after you get the services (you don't have 
to do anything with the hub), or, your device is already connected, in 
which case you would never get a listener event anyway.

Interestingly enough, due to my "bug", if you added your listener before 
the subsystem was initialized and then called getRootUsbHub, the 
enumeration process would send you an event!  But if the bug is fixed (so 
initialization happens on creation of the UsbServices object) then you 
wouldn't be able to add the listener before the bus is enumerated...funny 
problem... :)

So I think you should add the listener as you're doing now (except don't 
make it a Runnable), but you also need to check for the currently 
connected devices as well.  Or, you have to "know" that your device isn't 
connected until after you start your program.


On Tue, 17 Feb 2004, Joey Shen wrote:

>Hi Dan, and all
>
>I wrote a little piece of code to detect the attach of my Palm device by
>using UsbServicesListener. But it looks that the listener isn't working.
>When I press the sync button of my Palm USB cradle, the monitor thread
>dose not print out the information.
>
>Did I correctly implement the UsbServicesListner interface or I
>misunderstood the use case?
>
>My code is attached.
>
>Thanks a lot!
>-JoeyS
>
>

-- 
Dan Streetman
[EMAIL PROTECTED]
---------------------
186,272 miles per second:
It isn't just a good idea, it's the law!


-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
javax-usb-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/javax-usb-devel

Reply via email to