Thank you for your quick answers.

Looking at your explanations, it seems that I had correctly written my code... but it 
does not work yet.
Here are some more details.

Actually, it seems that I receive some data through the isochronous pipe but when I 
send it
to the component that aims to display the image, that does not look like an image at 
all (rather like some noise !).
I checked by asking for the number of bytes that were transferred using the result of 
"syncsubmit(byte[] data)".
"0" is always returned, so no data is actually sent from the WebCam to the host...

Why is 0 byte always returned ? Why do I receive something anyway (even if it is not 
correct) ?
And a second pipe (interrupt transfer mode) is open. I do not understand its use.

In case it could be useful, I run the 0.9.3 version of javax.usb on my computer.

Below, the code I use :

---------------------------------------------------------

public class CameraDriver implements Runnable
{
        private UsbInterface uInterface;
        private UsbPipe[] pipes;

        private CameraInterface ci;

        public CameraDriver(UsbDevice camera,CameraInterface camInterface)
        //CameraInterface is a personal interface not belonging to the JDK...
        {
                ci = camInterface;

                UsbConfig config = camera.getActiveUsbConfig();
                uInterface = getUsbInterface(config);

                addListener(camera);

                try
                {
                        uInterface.claim();
                }
                catch(UsbException ue)
                {
                        System.out.println(ue);
                }

                pipes = getUsbPipes(uInterface);

                System.out.println("Debug : number of pipes in interface : 
"+pipes.length);

                for(int i=0;i<pipes.length;i++)
                {
                        try
                        {
                                pipes[i].open();

                        //the following two lines indicate which transfer mode is used 
by the pipes
                        //it enables me to see that 2 pipes are open, the first one 
using isochronous mode
                        //the second one using interrupt mode

                                System.out.println("Debug : isochronous mode ? : 
"+(pipes[i].getType()==UsbInfoConst.ENDPOINT_TYPE_ISOC));
                                System.out.println("Debug : interrupt mode ? : 
"+(pipes[i].getType()==UsbInfoConst.ENDPOINT_TYPE_INT));
                        }
                        catch(UsbException ue)
                        {
                                System.out.println(ue);
                        }
                }
                Thread runningDriver = new Thread(this);
                runningDriver.start();
        }

        public void run()
        {
                try
                {
                        byte[] isoData = new byte[1023];

                //from what I read, 1023 is the maximum number of bytes that can be 
passed to the "syncSubmit()" method used below
                //So, I need a second array, "image", that will actually contain the 
whole image data.

                        byte[] image = new byte[3*352*288];

                //352*288*3 bytes
                //corresponding to 352*288 images with 3 colors
                //maybe it is not the right way to define the size of the byte array
                //but I guess the size is not the important parameter for the moment, 
is it ?

                        while(true)
                        {
                                int isoResult = -1;
                                for(int i=0;i<300;i++)

                        //100 arrays are needed to transfer 352*288 bytes
                        //or 3*100 to transfer 3*352*288 bytes corresponding to the 3 
color channels

                                {
                                        isoResult = pipes[0].syncSubmit(isoData);

                                        //the following loop only copies the data in 
the "image" array
                                        for(int j=0;j<1023;j++)
                                        {
                                                if(1023*i+j<3*352*288) //stops the 
"for" loop if the size of the image is reached
                                                {
                                                        image[1023*i+j] = isoData[j];
                                                }
                                                else
                                                {
                                                        break;
                                                }
                                        }
                                }
                                System.out.println("Debug : number of bytes 
transferred through isochronous pipe: "+String.valueOf(isoResult));

                        //this always returns "0"...

                                ci.setImage(image);//method defined in CameraInterface 
that sends the image to a JFrame for displaying purposes
                        }
                }
                catch(UsbException ue)
                {
                        System.out.println(ue+"\nMaybe a device was detached that 
interrupted the submission");
                }
        }

        private UsbInterface getUsbInterface(UsbConfig config)
        {
                //enumerates the interfaces that are within this UsbConfig
        }

        private UsbPipe[] getUsbPipes(UsbInterface uInterface)
        {
                //returns the pipes connected to uInterface
        }

        private void addListener(UsbDevice device)
        {
                //releases properly the inferface uInterface in case the UsbDevice is 
detached
        }
}



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
javax-usb-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/javax-usb-devel

Reply via email to