Android Things-I2C2已在使用中(代码16)

时间:2019-07-15 22:33:45

标签: gpio i2c android-things

我正在尝试将ADS1015 ADC与我的Pico Pro Maker连接。不幸的是,我遇到以下错误:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.cililing.harvbox.thingsapp, PID: 1855
    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:448)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
     Caused by: com.google.android.things.pio.PioException: android.os.ServiceSpecificException: I2C2 is already in use (code 16)
        at com.google.android.things.pio.I2cDeviceImpl.<init>(I2cDeviceImpl.java:43)
        at com.google.android.things.pio.PeripheralManager.openI2cDevice(PeripheralManager.java:246)
        at com.google.android.things.contrib.driver.adc.ads1xxx.Ads1xxx.<init>(Ads1xxx.java:200)
        at com.google.android.things.contrib.driver.adc.ads1xxx.Ads1xxx.<init>(Ads1xxx.java:187)
        at com.cililing.harvbox.thingsapp.thingscontroller.controllers.ADS1015ControllerImpl.<init>(ADS1015Controller.kt:12)
        at com.cililing.harvbox.thingsapp.ui.MainActivity$i2CController$2.invoke(MainActivity.kt:40)
        at com.cililing.harvbox.thingsapp.ui.MainActivity$i2CController$2.invoke(MainActivity.kt:33)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at com.cililing.harvbox.thingsapp.ui.MainActivity.getI2CController(Unknown Source:25)
        at com.cililing.harvbox.thingsapp.ui.MainActivity.access$getI2CController$p(MainActivity.kt:33)
        at com.cililing.harvbox.thingsapp.ui.MainActivity$i2cLogger$1.run(MainActivity.kt:47)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
     Caused by: android.os.ServiceSpecificException: I2C2 is already in use (code 16)
        at android.os.Parcel.readException(Parcel.java:2027)
        at android.os.Parcel.readException(Parcel.java:1959)
        at com.google.android.things.pio.IPeripheralManagerClient$Stub$Proxy.OpenI2cDevice(IPeripheralManagerClient.java:1243)
        at com.google.android.things.pio.I2cDeviceImpl.<init>(I2cDeviceImpl.java:41)
        at com.google.android.things.pio.PeripheralManager.openI2cDevice(PeripheralManager.java:246) 
        at com.google.android.things.contrib.driver.adc.ads1xxx.Ads1xxx.<init>(Ads1xxx.java:200) 
        at com.google.android.things.contrib.driver.adc.ads1xxx.Ads1xxx.<init>(Ads1xxx.java:187) 
        at com.cililing.harvbox.thingsapp.thingscontroller.controllers.ADS1015ControllerImpl.<init>(ADS1015Controller.kt:12) 
        at com.cililing.harvbox.thingsapp.ui.MainActivity$i2CController$2.invoke(MainActivity.kt:40) 
        at com.cililing.harvbox.thingsapp.ui.MainActivity$i2CController$2.invoke(MainActivity.kt:33) 
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) 
        at com.cililing.harvbox.thingsapp.ui.MainActivity.getI2CController(Unknown Source:25) 
        at com.cililing.harvbox.thingsapp.ui.MainActivity.access$getI2CController$p(MainActivity.kt:33) 
        at com.cililing.harvbox.thingsapp.ui.MainActivity$i2cLogger$1.run(MainActivity.kt:47) 
        at android.os.Handler.handleCallback(Handler.java:790) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 

我正在使用以下驱动程序: https://github.com/androidthings/contrib-drivers/tree/master/adc

我已经完成的事情:

  • 卸载所有应用
  • 重新安装整个AndroidThings
  • 我都累了I2C1和I2C2
  • 尝试读取新应用程序上的值(仅是库中的示例)。

我不知道该怎么办。我非常确定设备已正确连接到主板(scl-scl,sda-sda,addr-gnd,a0-other_analog_output),并且错误实际上有点奇怪,因为我敢肯定其他应用程序都不会使用这些引脚。 / p>

负责与外围设备连接的代码:

class ADS1015ControllerImpl(val i2cName: String,
                            val range: Int) : ADS1015Controller {

    private val instance: Ads1xxx = Ads1xxx(i2cName, Ads1xxx.Configuration.ADS1015)
    init {
        instance.inputRange = range
    }

    override fun read(channel: Int, logger: (Int) -> Unit) {
        logger.invoke(
                instance.readSingleEndedInput(channel)
        )
    }

    override fun release() {
        instance.close()
    }
}

2 个答案:

答案 0 :(得分:1)

错误消息I2C2 is already in use (code 16)表示您正在尝试打开同一I2C总线的多个连接,而没有关闭前一个实例。打开I2C连接的代码位于Ads1xxx构造函数中。您必须在代码中管理该类的单个实例,或者确定在初始化另一个close()之前调用Ads1xxx

基于堆栈跟踪,它看起来也像该设备在首次访问其值时由延迟加载初始化的,因此很可能在您期望的位置未调用此构造方法,从而导致事情发生订单。

答案 1 :(得分:0)

事实上,问题是插头焊接不良。 :)