我尝试将我的 archos Titanium HD 连接到我的 RAMBo ( http://reprap.org/wiki/Rambo )。目前我可以连接到设备并找到 USB_DIR_IN 但是当我从连接中读取时我得到空值。我究竟做错了什么?
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) {
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
if(device != null){
myfield.setText(myfield.getText()+"start connection");
UsbInterface intf = device.getInterface(0);
UsbManager mUsbManager=(UsbManager) getSystemService(Context.USB_SERVICE);
UsbDeviceConnection connection = mUsbManager.openDevice(device);
if(connection.claimInterface(intf, forceClaim)){
for(int i=0;i<intf.getEndpointCount();i++){
UsbEndpoint endpoint = intf.getEndpoint(i);
if(endpoint.getDirection()== UsbConstants.USB_DIR_IN){
myfield.setText(myfield.getText()+"endpoint zum lesen:"+i);
int ret=connection.bulkTransfer(endpoint, mybytes, 20, TIMEOUT);
myfield.setText(myfield.getText()+"ret"+ret+" "+Arrays.toString(mybytes)+"first read");
}
else if(endpoint.getDirection()==UsbConstants.USB_DIR_OUT){
myfield.setText(myfield.getText()+"endpoint zum schreiben"+i);
}
else{
myfield.setText(myfield.getText()+"irgendein endpoint");
}
}
}
else{
myfield.setText(myfield.getText()+"verbindung nicht möglich");
}
//call method to set up device cmmunication
}
}
else {
myfield.setText("Permission denied");
//Log.d(TAG, "permission denied for device " + device);
}
}
}
}
};