我尝试将我的archos Titanium HD连接到我的RAMBo(http://reprap.org/wiki/Rambo)。目前我可以连接到设备,我找到USB_DIR_IN,但当我从连接读取时,我得到null。我做错了什么?
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);
}
}
}
}
};