1
\$\begingroup\$

I have a UPS HID device and I'm trying to use LibUSB to get data from it. The response expected is in the format below:

(Input_Volt ^ Fault_Volt ^ Output_Volt ^ Input_Curr ^ Freq ^ Batt_Volt (MMM.M ^ NNN.N ^ PPP.P ^ QQQ ^ RR.R ^ SS.S or S.SS ^ Temp ^ Status<cr> ^ TT.T ^8bit <cr>)

Example: (229.0 000.0 220.0 000 49.9 2.25 33.0 00000000 <cr>)

At the current moment, I'm not able to get a populated response from the device since it's returning a response like this: (000.0 000.0 000.0 000 00.0 0.00 00.0 00000000)

Curiosity: If I use the software UPSmart I can see that the UPS is working well. If I stop the UPSmart and try to get the response from the device again using my code, the response returned is the last one that was shown in the UPSmart and it does not change anymore.

Here is the code I'm using:

Context mContext = new Context();
int result = LibUsb.init(mContext);
if (result != LibUsb.SUCCESS)
    throw new RuntimeException(String.format("USB error: Unable to initialize LibUSB. Error %d: %s", result, LibUsb.strError(result)));

DeviceHandle mDeviceHandle = LibUsb.openDeviceWithVidPid(mContext, vendorId, productId);
if (mDeviceHandle == null) {
    throw new Exception("USB error: Device not found or is being used by another process");
}

System.out.println(LibUsb.getStringDescriptor(mDeviceHandle, 0x3));

LibUsb.exit(mContext);

Should I send any other command to tell the UPS it should populate the data?

\$\endgroup\$
  • \$\begingroup\$ You can use USB sniffer software to determine how the UPS software communicates with the device. There are plenty of free/free-trial versions that you come up if you google "USB Sniffer Software". I've personally used Free USB Analyzer before and it worked well. \$\endgroup\$ – Oscillonoscope May 14 at 18:03
  • \$\begingroup\$ Yeah, I downloaded this software before posting this question. Although I could extract relevant information, it was not enough to accomplish what I want. Have you ever used this to monitor UPS devices? \$\endgroup\$ – Athus Vieira May 14 at 18:57
  • \$\begingroup\$ Not specifically a UPS device but an HID is an HID is an HID. You either missed a command or the command wasn't visible with the options you chose. Make sure that you're not filtering out any commands and you're seeing data transfers in both directions. \$\endgroup\$ – Oscillonoscope May 14 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.