0

I am trying to open and read from a TRF7970A EVM board (by Texas Instruments) connected to my Mac. The device shows up in ioreg -lfxp IOUSB as a "USB to UART Bridge Controller" and gives the vid, pid and serial number.

The device path in my Mac is as follows (machine name redacted)

koushikdas@xxxx ~ % ls /dev/tty* | grep usb
/dev/tty.usbserial-0001

I changed the permission as follows: sudo chmod -R 777 /dev/tty.usbserial-0001

Below is my code snippet:

int vid = 0x10c4;
int pid = 0xea60;
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();
}

When I run the code, I see the following in console (package name redacted):

00:22:44.918 [ForkJoinPool-1-worker-1] INFO xxx - Reading device data -2
00:22:44.918 [ForkJoinPool-1-worker-1] INFO xxx - Device SN Device not initialised
00:22:44.918 [ForkJoinPool-1-worker-1] INFO xxx - Device PID Device not initialised
00:22:44.918 [ForkJoinPool-1-worker-1] INFO xxx - Device Manufacturer Device not initialised

I also tried setting HidApi.useLibUsbVariant = true; but got the same result.

Any suggestion to resolve this would be helpful.

Koushik
  • 1
  • 1
  • Aside from the real problem: why do you convert the hex value to a string and parse it again in the first two rows of the snippet? You could do `int vid = 0x10c4; int pid = 0xea60;` – cyberbrain Apr 21 '23 at 09:46
  • @cyberbrain that's right. my mistake. Edited – Koushik Apr 21 '23 at 16:39
  • I'm not familiar with hidapi, but it seems that it is a nativ library with several Java wrappers available. Maybe you should add some details about the library you use, and also check your logfile for any native lib error messages, e.g. if it can't link to the native lib, the jni lib path, etc. – cyberbrain Apr 22 '23 at 15:22
  • I am using Hid4Java 0.7.0. The dependency in build.gradle is: implementation group: 'org.hid4java', name: 'hid4java', version: '0.7.0' – Koushik Apr 24 '23 at 07:19
  • did you try the simpler examples from hid4java? – cyberbrain Apr 24 '23 at 11:55
  • @cyberbrain yes, I tried with HidServices getHidDevice(...) and HidDeviceInfoStructure show() method also. HidApi.open(...) works best. I get a fatal error with HidServices getHidDevice(...) and null values with HidDeviceInfoStructure show() – Koushik Apr 25 '23 at 06:07

0 Answers0