Jump to content
rharmon@sandia.gov

Communicate with hardware using USB HID?

Recommended Posts

Trying to communicate with a TRIPP-Lite UPS via USB port. I thought this was going to be easy, Tripp-Lite sent me the protocol, creating the words to send and what to expect for answers. I was ready to go, but now I'm seeing they use HID Protocol. Which I had never heard of, but that's not so unusual.

There is no com port, they use an ip address in the tripp-lite software. There is no network connections to the hardware so I'm guessing the ip address is being used by the software to address the USB Port.

I'm just lost, is there something in labview that addresses HID communications? Do I use VISA? Do I create a raw port and assign it a ASRL number?

Can someone point me in the right direction?

Thanks,

Bob Harmon

Share this post


Link to post
Share on other sites

So yeah I've struggled this same issue with TRIPP-Lite UPSs.  Mine luckily had a DB-9 so after investigating a bunch of time into getting a proof of concept going on the USB side, I decided to just drop it and go with the simple COM port.

NI's official method of talking to HID devices involves creating an INF driver for it, and then using that in Windows.  The problem is Windows 10 is quite restrictive when it comes to unsigned drivers, and you need to do some extra work just to install the driver, so that the hardware can be shown in MAX, so that you can start to communicate with it using raw VISA.  This isn't that big of a deal for one, but multiply this manual process by the 20+ machines I'd want to do this on and it is an issue.  Here is the process NI suggests.

At the time I did find some DLLs posted on the NI forums that wrapped communicating to HID devices so that this wasn't needed.  It was incomplete, and my knowledge of DLL calls, and C is limited so I just never found success in this method.  I don't remember the code or examples I used but here is a thread that came up when I was searching.  If you do get anything working feel free to post it.

EDIT: Oh I just saw a command line tool that might help.  I'm not in the office to test with.

Share this post


Link to post
Share on other sites

Hooovahh,

I didn't think this was going to be such a big deal... My unit also has a DB-9 so I think I'm going to go that direction.

Thanks for your help...

Bob

 

Share this post


Link to post
Share on other sites

Hooovahh,,

One quick question. When you went with the comm port (DB-9 RS232). Did you connect via com(x) and use the normal visa Write/Read commands?

Thanks,

Bob

Share this post


Link to post
Share on other sites

Yup. Just make sure you have the null of the cable correct.  Sometimes the manufacturer puts the null-ness in the device so a straight through cable should be used, some times they don't I can't remember what it is.  Some example code I posted here should get you started.

Share this post


Link to post
Share on other sites
On 5/12/2020 at 9:45 PM, rharmon@sandia.gov said:

Trying to communicate with a TRIPP-Lite UPS via USB port. I thought this was going to be easy, Tripp-Lite sent me the protocol, creating the words to send and what to expect for answers. I was ready to go, but now I'm seeing they use HID Protocol. Which I had never heard of, but that's not so unusual.

There is no com port, they use an ip address in the tripp-lite software. There is no network connections to the hardware so I'm guessing the ip address is being used by the software to address the USB Port.

I'm just lost, is there something in labview that addresses HID communications? Do I use VISA? Do I create a raw port and assign it a ASRL number?

Can someone point me in the right direction?

There is nothing out of the box. The main reason is that HID devices are normally claimed by the OS. Also HID is a low level binary protocol that says pretty much nothing at all about what data is transfered over the link, just what endpoints are involved. There are some HID sub classes such as keyboard and mice which have a specific data format to be used on the binary level but even that knows various vendor defined extensions that each vendor will implement in its own way. Other devices implementing the HID class are usually very specific to the actual device and therefore always need a custom implementation.

If you want to talk to HID devices from LabVIEW you have a few options, each with its specific drawbacks:

1) Use a shared library that implements the driver and call its functions with the Call Library Node. Advantage: No need to know the low level protocol details. Disadvantage: Shared library interface requires at least some basic C programming knowledge to be able to properly interface to it.

2) Use a HID specific shared library interface. Disadvantege: In addition to the need to know about interfacing to shared libraries you also need to implement the low level binary protocol for your device.

3) Use the VISA USB Raw protocol. Advantage: can be done all inside LabVIEW without the problems to interface to shared libraries with their non-managed C difficulties. Disadvantage: You need to implement the HID protocol and also only possible if you know the low level protocol on top of HID. You seem to have gotten that information from Tripp-Lite, so you "just" have to lookup the HID protocol specifications on usb.org and study several 100 pages of USB standard documentation to do this. The biggest drawback however is that all current desktop OSes require signed drivers in order that you can install them and that also applies to VISA INF style drivers. NI can't give you their private signing keys to let you sign such a driver and getting your own has a cost associated with it and not just a one time cost either. Disabling driver signing in the OS is still possible but requires one to jump through more and more hoops as time goes by. I expect it to soon be impossible without installing a special debug build of an OS.

4) Use of the Windows device interface API through the Call Library Node. The actual communication isn't that difficult once you have the device opened but interfacing to the setup API to enumerate, find and configure the device is a pita. The setup API is also complex enough that it pretty much requires a separate external shared library as many of the parameters are pretty complex and all but LabVIEW friendly. You still would need to implement the HID protocol itself and the also the low level device protocol in addition to the whole shared library interface for the Windows API. In terms of effort this option is by far the most complex to do.

5) using libusb or WinUSB you can communicate directly to the device too. It supports claiming devices eventhough the OS has already claimed them. libusb/WinUSB basically accesses the above mentioned Windows API and hides a lot of the complexity. You still need to interface to the shared library interface of libusb/WinUSB and you would need to implement the HID and low level device protocol on top of this.

Share this post


Link to post
Share on other sites

I'm fairly certain the purpose is to query the UPS status.  The API allows for reading the input voltage and frequency, the output voltage and frequency, the battery voltage, state of charge as a percentage, battery temperature, and if it is on battery power or not.  These UPSs have a USB port but when plugged into a Windows computer it is not recognized as a battery device like you'd typically see on a laptop.  Otherwise the normal Windows API can query the battery status.

Share this post


Link to post
Share on other sites

Thank you all for the awesome information... It is truly appreciated...

As hooovahh indicates it is to monitor the UPS health/status and know when the supply power drops out. If the power drops out, I need to safely shutdown several units before the UPS runs out of power.

As Rolf indicates it is possible to do on the USB HID port but a real pita... These units will be in distant locations and I don't want any extra complexity or reasons for it to fail.

hooovahh ended up using the DB9, RS232 port and that is the direction I intend to head.

Again, thank you all for the information... You guys are always a huge help.

Share this post


Link to post
Share on other sites

HID already tested my sanity... Sadly I failed...

Yes we looked at the relay card. I just want to get more UPS health information. These units are intended to run for years and it would be good if the user could visually see the UPS is working well.

Also as I understand it they either short or open two pins in the DB9 RS232 connector when the supply power shuts down. Again, just looking for more... As usual....

Share this post


Link to post
Share on other sites
On 5/20/2020 at 7:29 PM, rharmon@sandia.gov said:

HID already tested my sanity... Sadly I failed...

Yes we looked at the relay card. I just want to get more UPS health information. These units are intended to run for years and it would be good if the user could visually see the UPS is working well.

Also as I understand it they either short or open two pins in the DB9 RS232 connector when the supply power shuts down. Again, just looking for more... As usual....

How does the documentation look that your received from Tripp-Lite?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.