6

Android タブレットから POS プリンターにコマンドを送信しようとしています。基本的な接続を機能させることができましたが、プリンターにデータを送信しようとすると、bulkTransfer が -1 を返します。何が起こっているのか理解するのを手伝ってください。以下は、私がすべてのデータ転送を行う Android サイトから取得した、変更されたブロードキャスト レシーバーです。

private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
        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){
                      //call method to set up device communication

                        if(device.getVendorId() != 1659)
                            return;

                        UsbInterface intf = device.getInterface(0);
                        UsbEndpoint endpoint = intf.getEndpoint(0);
                        int direction = endpoint.getDirection();                            
                        UsbDeviceConnection connection = mUsbManager.openDevice(device);
                        connection.claimInterface(intf, forceClaim);

                        bytes = new byte[]{27, 64};

                        //**This returns -1 always**
                        int ret = connection.bulkTransfer(endpoint, bytes, bytes.length, TIMEOUT); 

                        if(ret < 0)
                        {
                            Log.d("WTF", "Error happened!");
                        }
                        else if(ret == 0)
                        {
                            Log.d("WTF", "No data transferred!");
                        }
                        else
                        {
                            Log.d("WTF", "success!");
                        }
                   }
                } 
                else {
                    Log.d(TAG, "permission denied for device " + device);
                }
            }
        }
    }
};
4

0 に答える 0