HidApi.read 在尝试获取 SN、PID 时返回 -2(DEVICE_ERROR)和“设备未初始化”

问题描述 投票:0回答:0

我正在尝试打开连接到我的 Mac 的 TRF7970A EVM 板(德州仪器)并从中读取。该设备在“ioreg -lfxp IOUSB”中显示为“USB 到 UART 桥接控制器”,并提供了 vid、pid 和序列号。 我的Mac中的设备路径如下(删掉机器名) koushikdas@xxxx ~ % ls /dev/tty* | grep USB /dev/tty.usbserial-0001 我更改了权限如下: sudo chmod -R 777 /dev/tty.usbserial-0001

下面是我的代码片段:

int vid = (int) Long.parseLong(Integer.toHexString(0x10c4), 16);
int pid = (int) Long.parseLong(Integer.toHexString(0xea60), 16);
try {
HidApi.init();
// HidDeviceStructure hidDeviceStructure = HidApi.open("/dev/tty.usbserial-0001");
HidDeviceStructure hidDeviceStructure = HidApi.open(vid, pid, "0001");
HidApi.setNonBlocking(hidDeviceStructure, true);
log("Reading device data " + HidApi.read(hidDeviceStructure, new byte[64]));
log("Device SN " + HidApi.getSerialNumber(hidDeviceStructure));
log("Device PID " + HidApi.getProductId(hidDeviceStructure));
log("Device Manufacturer " + HidApi.getManufacturer(hidDeviceStructure));
} catch (Exception e) {
log("Not able to open Hid device");
e.printStackTrace();
}

当我运行代码时,我在控制台中看到以下内容(已编辑包名称): 00:22:44.918 [ForkJoinPool-1-worker-1] INFO xxx - 读取设备数据 -2 00:22:44.918 [ForkJoinPool-1-worker-1] INFO xxx - 设备 SN 设备未初始化 00:22:44.918 [ForkJoinPool-1-worker-1] INFO xxx - 设备 PID 设备未初始化 00:22:44.918 [ForkJoinPool-1-worker-1] INFO xxx - 设备制造商设备未初始化

我还尝试设置 HidApi.useLibUsbVariant = true;但得到了相同的结果。 任何解决此问题的建议都会有所帮助。

java hid hidapi
© www.soinside.com 2019 - 2024. All rights reserved.