On 7 apr 2009, at 16:32, Schalin, Patrik wrote:

Hi Dennis,
Thanks for your prompt reply!
Yes, I've managed to get that far. I have an extension of org.osgi.service.Device that gets registered with the appropriate properties (I think) i.e. DEVICE_SERIAL etc.. It also gets unregistered when the
device is disconnected...hoooray. =)

That's really nice :-)
Its just that when I take the next step with Device Manager, a driver and driver attachement I always have the feeling of "ok, did I get this right or what...". My first version I opened a USB channel and allocated resources for IO as part for the device registration but that didn't seem right. Now I have a re- written version where the USB driver will go through the matching and attachment process and I guess that will turn out better...
Although, it would be nice to have something to verify against....

Some time ago I presented a talk that (also) elaborates on the device matching and attaching

( http://www.nljug.org/pages/events/content/jfall_2007/sessions/00034/slides/ ) Skip some slides until you get to the device access part. I truly hope the slides do
offer some explanation of the process.


To elaborate on your specific case (assuming a lot, since I don't possess all the details)

I would expect in your situation that you have written some kind of base driver (as it is
mentioned in the DA spec) that is able to detect the appearance (and
subsequent removal) of USB devices of your choosing.

From what I read, that job is done. I would then (personally) recommend you to write a (native) java implementation of an interface that makes sense in your domain. This implementation would then take care of all the intricate IO on the low-level USB resource.

Suppose that this jni implementation is able to connect to such a USB device through it's serial:

pseudo code:

   USBDeviceInterface dev = new USBDeviceImpl(serial);

   dev.doIntricateIO();


the only thing the base driver then needs to do to startup device matching and attaching would be to register an Object (!) using the appropriate service properties:

{
objectclass=<don't care>
// you can implement the Device interface, then if no suitable driver is
//found, it's noDriverFound() method is called: there's your verification !!!

DEVICE_CATEGORY=new String[]{ "some category, e.g. "my-usb" "}
//really important, this triggers the device manager to start searching for a suitable driver.

DEVICE_SERIAL=<the device serial>
}



you'd then be able to implement a very simple driver:

(pseudo-code again)



 int match(ServiceReference ref) throws ... {

        Filter filter = FrameworkUtil.createFilter("DEVICE_CATEGORY=my-usb");
        
        if ( filter.match(ref) ) {
return 200; //a high number, since the match is good, but not too high to allow for better matches
        }

      return MATCH_NONE;
}


String attach(ServiceReference ref) throws ... {

          serial = ref.getProperty("DEVICE_SERIAL");  

         USBDeviceInterface dev = new USBDeviceImpl(serial);

       //optional
       props = new Properties();
       props.put(DEVICE_SERIAL, serial);

        //not optional (!)
context.registerService(new String[] {USBDeviceInterface.class.getName()}, props);


       // todo:  add code to unregister the driver
       // when the device disappears !!!



      return null;
}


And voila, the (native) USBDeviceInterface service implementation is
presented to all other services in your framework.




I guess that the verification comes from having the devices and drivers working in the dynamic environment i.e. coming and going
attaching and releasing...I'm slowly getting there...  ;)


What one can do is write a special utility bundle that once in a while
looks up all registered devices and inspect if they are actually used by a driver bundle, logging this to the LogService. I believe you can do that yourself, but I'd be more than happy to lend a hand...


Is there something that I can use, for verification, from the Felix website?

Finally, which device manager implementation are you currently using ?

I think more detailed information should be discussed offline. Feel free to mail me.



dennis

Regards
Patrik
> Hi Patrik,
>
> I don't know of a HelloWorld example that exists out there, but I've
> recently donated an implementation of the device access spec to Apache
> Felix. I can cook up an example for you, if you want.
>
> What you probably need is some kind base driver that is able to detect > (in a low-level way) that a device has appeared on the USB bus. Based
> on the limited information that has then become available about the
> device
> a Device (in the sense of the device access spec) must then be
> registered within the framework. It is then up to the device manager
> to locate possible drivers that match the detected device.
>
> Regards, Dennis
<ATT00001.c>

_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to