简体   繁体   English

Android 的事情:使用命令 writeBuffer、write、byte[] 在 i2c 寄存器中写入许多字节

[英]Android things: using commands writeBuffer, write, byte[] to write many bytes in i2c registers

I'm developing an application to move dc motors, using android things.我正在开发一个应用程序来移动直流电机,使用 android 的东西。

At this stage I already know which commands I have to process, but I do not know how.在这个阶段,我已经知道我必须处理哪些命令,但我不知道如何处理。 ( Using the i2c smartdrive sensor with a Pio Cli commands to run motors ) 使用带有 Pio Cli 命令的 i2c smartdrive 传感器来运行电机

Below example i2c from guide google developers:下面是来自谷歌开发者指南的 i2c 示例:

public void writeBuffer (I2cDevice device, byte [] buffer) throws IOException {
     int count = device.write (buffer, buffer.length);
     Log.d (TAG, "Wrote" + count + "bytes over I2C.");
}

My question (based on the code above) is:我的问题(基于上面的代码)是:

1) How to write (in Kotlin) pio i2c I2C1 0x1B write-raw 0x46 128 0x05 0x00 0xD1 in buffer to pass as parameter in writeBuffer function? 1)如何在缓冲区中写入(在 Kotlin 中)pio i2c I2C1 0x1B write-raw 0x46 128 0x05 0x00 0xD1 作为参数传递给 writeBuffer 函数?

eg: var buffer = (new byte[] (byte) 0x46, 128, 0x05, 0x00, 0xD1, value.i2cValue.toByteArray()), did not work.例如:var buffer = (new byte[] (byte) 0x46, 128, 0x05, 0x00, 0xD1, value.i2cValue.toByteArray()),不起作用。

My final project is based on the project below: https://github.com/Nilhcem/i2cfun-androidthings/tree/arduino_slave/app/src/main/java/com/nilhcem/androidthings/i2cfun我的最终项目基于以下项目: https : //github.com/Nilhcem/i2cfun-androidthings/tree/arduino_slave/app/src/main/java/com/nilhcem/androidthings/i2cfun

quote: I know that I2C1 and 0x1B are not required because they are passed parameters, either before, or in I2cDevice.引用:我知道 I2C1 和 0x1B 不是必需的,因为它们是在之前或在 I2cDevice 中传递的参数。

我解决了: val buffer = byteArrayOf(0x46, 128.toByte(), 0x05, 0x00, 0xD1.toByte()) and device?.write(buffer, buffer.size)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM