On Thu, 5 Jan 2006, Alireza Bakhtiari wrote: >hi everyone > I have a usb gsm modem (siemens MC35) and i wanna send an sms through this > modem, but whatever command I send to the modem, the response is the same:1' > this is what i have done:
You get "1" as the response? Do you mean it successfully transfers only 1 byte? > > final UsbPipe usbPipein = usbEndpointin.getUsbPipe(); > final UsbPipe usbPipeout = usbEndpointout.getUsbPipe(); > //I had to define them as final to be able to work with them in the thread > after that i open the pipes, then: > > > Thread runner1 = new Thread () { > public void run () { > UsbIrp irp = usbPipeout.createUsbIrp(); > irp.setData("ATI".getBytes()); This probably isn't what you want to do, as "ATI".getBytes() will convert it to 16-bit unicode, not ascii (8-bit) bytes. You'll need to either explicitly create the byte array with the right values or use one of the String (or related classes) ASCII conversion methods, if that's what you want. Probably easiest to do something like byte[] data = { 'A', 'T', 'I' }; although I'm not actually sure Java allows byte[] construction like that. > > try{ > usbPipeout.syncSubmit(irp); > Thread.sleep(1000); syncSubmit guarantees that the transfer is done when the method returns. No point in sleeping at all. > > if (1 > irp.getActualLength()){ > System.out.print("failed"); > throw new Exception("packet sending failed"); > } > }catch(Exception e){}; You don't want to even print something out at least if there is an exception? > }}; > > Thread runner2 = new Thread () { > public void run () { > byte[] resData = new byte[64]; > try{ > Thread.sleep(1000); why? > UsbIrp inIrp = usbPipein.createUsbIrp(); > inIrp.setData(resData); > int bytesRead = 0; > do{ > usbPipein.syncSubmit(inIrp); > bytesRead = inIrp.getActualLength(); > totalBytes += bytesRead; > } while (!inIrp.isComplete()); that's pointless, any submit method guarantees the irp will be complete on return. > System.out.println("response: "+new > String(resData,0,totalBytes)); > }catch(Exception e){} > }}; > runner2.start (); > runner1.start (); > > if i set the sleep time of thread 2 to be 2000 or more, it will catch an > exception > Im dont know much of usb programming, please help me correct the code. Have you read Chaps 5 and 9 of the USB spec? Those will help a lot. Also, javax.usb JavaDOC is your friend... http://javax-usb.org/jdoc/ -- Dan Streetman [EMAIL PROTECTED] --------------------- 186,272 miles per second: It isn't just a good idea, it's the law! ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ javax-usb-devel mailing list javax-usb-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/javax-usb-devel