kkohase / usb-serial-for-android

Automatically exported from code.google.com/p/usb-serial-for-android
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Connect Archors 97 Titanium HD to an Rambo Board (reprap) #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hy
I try to connect my Titanium HD to an Rambo Board (http://reprap.org/wiki/Rambo 
But the driver is null. What am i doing wrong? Here is my code:

public void dummyclick(View view){

        EditText myfield = (EditText) findViewById(R.id.editText1);

        UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);

        HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); 
        Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
        myfield.setText(deviceList.size()+"Geräte gefunden");
        PendingIntent mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
        IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
        while(deviceIterator.hasNext()){
            UsbDevice device = deviceIterator.next();
            myfield.setText(myfield.getText()+ device.getDeviceName()+" vendorid: "+device.getVendorId()+"  productid"+device.getProductId());

            //abfrage der berechtigung
            registerReceiver(mUsbReceiver, filter);
            manager.requestPermission(device, mPermissionIntent);

        }

    }

private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {

            public void onReceive(Context context, Intent intent) {
                EditText myfield = (EditText) findViewById(R.id.editText1);
                String action = intent.getAction();
                if (ACTION_USB_PERMISSION.equals(action)) {
                    synchronized (this) {

                        UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);

                        // Find the first available driver.
                        UsbSerialDriver driver = UsbSerialProber.acquire(manager);

                        if (driver != null) {

                          try {
                              driver.open();
                            driver.setBaudRate(115200);

                            byte buffer[] = new byte[16];
                            int numBytesRead = driver.read(buffer, 1000);
                            myfield.setText(myfield.getText()+ "Read " + numBytesRead + " bytes.");
                          } catch (IOException e) {
                              myfield.setText(myfield.getText()+"readerror");
                          } finally {
                            try {
                                driver.close();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                //e.printStackTrace();
                            }
                          } 
                        }
                        else{

                            myfield.setText(myfield.getText()+"cant open device");
                        }

                    }

thank you
Markus

Original issue reported on code.google.com by kaltenbr...@gmail.com on 5 Mar 2013 at 7:55

GoogleCodeExporter commented 9 years ago
Can you please bring this up on the mailing list 
(http://groups.google.com/group/usb-serial-for-android)? Someone might be able 
to help you there.

Original comment by mike.wak...@gmail.com on 8 Apr 2013 at 5:46