Arduino的问题< - > Cordova(Android)串口通讯

时间:2017-03-31 07:58:31

标签: android cordova arduino serial-port usbserial

我有一个用于Android的cordova 6应用程序,我想与Arduino通信,它与USB连接。为此,我使用cordovaarduino - 插件,它使用usb-serial-for-android

不幸的是我的设置有问题。请求权限有效,但是当我尝试实际打开串行连接时,我在adb logcat中看到了Java异常: java.io.IOException:错误排队请求 这意味着在我调用serial.open之后,既不会成功,也不会调用错误回调。

我的Android设备: - Android 5.1.1 - Allwinner A33芯片组

我的串口设备: - Arduino Uno或Arduino Nano - 与USB连接到Android

我的Javascript代码:

myApp.serial = {
  initialize: function(){
    // Arduino Nano China 1a86:7523
    // Arduino Uno original 2a03:0043
    var serial_device = {vid: '2a03',
      pid: '0043',
      //driver: 'CdcAcmSerialDriver'
      //driver: 'Ch34xSerialDriver'
      //driver: 'Cp21xxSerialDriver'
      //driver: 'FtdiSerialDriver'
      //driver: 'ProlificSerialDriver'      
    };
    serial.requestPermission( serial_device, this.initialize_success, this.initialize_error);
  },
  initialize_success: function(){
    toLog("Serial initialized", 4);
    var opts = { baudRate: 9600 };
    serial.open(opts, this.open_success, this.open_error);
  },
  initialize_error: function(){
    toLog("Error initializing serial!", 1);
  },
  open_success: function(){
    toLog("Serial connectino opened", 4);
    serial.registerReadCallback(this.on_serial_read, this.on_serial_read_error);
  },  
  open_error: function(){
    toLog("Error opening serial connection!", 1);
  }
}  

adb logcat

D/Serial  ( 3010): Action: requestPermission
D/UsbBroadcastReceiver( 3010): Permission to connect to the device was accepted!

I/chromium( 3010): [INFO:CONSOLE(3)] "Serial initialized", source: file:///android_asset/www/assets/javascripts/myapp.min.js (3)
D/Serial  ( 3010): Action: openSerial
D/CdcAcmSerialDriver( 3010): claiming interfaces, count=2
D/CdcAcmSerialDriver( 3010): Control iface=UsbInterface[mId=0,mAlternateSetting=0,mName=null,mClass=2,mSubclass=2,mProtocol=1,mEndpoints=[
D/CdcAcmSerialDriver( 3010): UsbEndpoint[mAddress=130,mAttributes=3,mMaxPacketSize=8,mInterval=255]]
D/CdcAcmSerialDriver( 3010): Control endpoint direction: 128
D/CdcAcmSerialDriver( 3010): Claiming data interface.
D/CdcAcmSerialDriver( 3010): data iface=UsbInterface[mId=1,mAlternateSetting=0,mName=null,mClass=10,mSubclass=0,mProtocol=0,mEndpoints=[
D/CdcAcmSerialDriver( 3010): UsbEndpoint[mAddress=4,mAttributes=2,mMaxPacketSize=64,mInterval=1]
D/CdcAcmSerialDriver( 3010): UsbEndpoint[mAddress=131,mAttributes=2,mMaxPacketSize=64,mInterval=1]]
D/CdcAcmSerialDriver( 3010): Read endpoint direction: 128
D/CdcAcmSerialDriver( 3010): Write endpoint direction: 0
D/CdcAcmSerialDriver( 3010): Async reads enabled
D/UsbRequestJNI( 3010): close
D/UsbRequestJNI( 3010): init
D/UsbRequestJNI( 3010): close
D/Serial  ( 3010): Serial port opened!
I/Serial  ( 3010): Stopping io manager.
I/SerialInputOutputManager( 3010): Stop requested
I/Serial  ( 3010): Starting io manager.
W/SerialInputOutputManager( 3010): Run ending due to exception: Error queueing request.
W/SerialInputOutputManager( 3010): java.io.IOException: Error queueing request.
W/SerialInputOutputManager( 3010):      at com.hoho.android.usbserial.driver.CdcAcmSerialDriver$CdcAcmSerialPort.read(CdcAcmSerialDriver.java:168)
W/SerialInputOutputManager( 3010):      at com.hoho.android.usbserial.util.SerialInputOutputManager.step(SerialInputOutputManager.java:159)
W/SerialInputOutputManager( 3010):      at com.hoho.android.usbserial.util.SerialInputOutputManager.run(SerialInputOutputManager.java:141)
W/SerialInputOutputManager( 3010):      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
W/SerialInputOutputManager( 3010):      at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/SerialInputOutputManager( 3010):      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/SerialInputOutputManager( 3010):      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/SerialInputOutputManager( 3010):      at java.lang.Thread.run(Thread.java:818)
D/Serial  ( 3010): Runner stopped.
I/SerialInputOutputManager( 3010): Stopped.
I/SerialInputOutputManager( 3010): Running ..
D/UsbRequestJNI( 3010): init

没有一个司机似乎工作。但是logcat消息略有不同。

这是否意味着,我的Android设备不受支持,或者我可以尝试一下?

1 个答案:

答案 0 :(得分:0)

Arduino解决方案:

            event   status 
id   year
1    2013     1       1
     2014     0       1
     2015     0       1
     2016     0       1
     2017     0       1

2    2014     0       0
     2015     0       0
     2016     1       1
     2017     0       1

3    2016     1       1
     2017     0       1

4    2013     0       0
     2014     1       1
     2015     0       1

5    2014     0       0
     2015     0       0
     2016     0       0
     2017     1       1

Java

port.dtr = true // for arduino, ...
port.rts = true

how to set