USBHost_t36 and Raw HID Device (HP Proximity Reader X3D03A)

Status
Not open for further replies.

jerwood

Member
I'm trying to connect a Teensy 3.6 to a device that provides a Raw HID interface. I've used KurtE's work here: https://forum.pjrc.com/threads/47914-T3-6-USB-Host-Raw-Hid?highlight=USBHost as a starting point. So far, it seems like I'm unable to connect to the device properly.

Here is my code:

Code:
// Simple RawHID Sketch

#include "USBHost_t36.h"

USBHost myusb;
USBHub hub1(myusb);
USBHIDParser hid1(myusb);
USBHIDParser hid2(myusb);
USBHIDParser hid3(myusb);
RawHIDController rawhid1(myusb);

USBDriver *drivers[] = {&hub1, &hid1, &hid2, &hid3,};
#define CNT_DEVICES (sizeof(drivers)/sizeof(drivers[0]))
const char * driver_names[CNT_DEVICES] = {"Hub1", "HID1", "HID2","HID3"};
bool driver_active[CNT_DEVICES] = {false, false};

// Lets also look at HID Input devices
USBHIDInput *hiddrivers[] = { &rawhid1};
#define CNT_HIDDEVICES (sizeof(hiddrivers)/sizeof(hiddrivers[0]))
const char * hid_driver_names[CNT_DEVICES] = {"RawHid1"};
bool hid_driver_active[CNT_DEVICES] = {false};


void setup()
{
  while (!Serial) ; // wait for Arduino Serial Monitor
  Serial.println("\n\nUSB Host Testing");
  Serial.println(sizeof(USBHub), DEC);
  myusb.begin();
  rawhid1.attachReceive(OnReceiveHidData);
}


void loop()
{
  myusb.Task();
  CheckUSBDeviceStatus();
}

bool OnReceiveHidData(uint32_t usage, const uint8_t *data, uint32_t len) {
  Serial.print("RawHID data: ");
  Serial.println(usage, HEX);
  while (len) {
    uint8_t cb = (len > 16) ? 16 : len;
    const uint8_t *p = data;
    uint8_t i;
    for (i = 0; i < cb; i++) {
      Serial.printf("%02x ", *p++);
    }
    Serial.print(": ");
    for (i = 0; i < cb; i++) {
      Serial.write(((*data >= ' ') && (*data <= '~')) ? *data : '.');
      data++;
    }
    len -= cb;
    Serial.println();
  }

  return true;
}

void CheckUSBDeviceStatus() {
  for (uint8_t i = 0; i < CNT_DEVICES; i++) {
    if (*drivers[i] != driver_active[i]) {
      if (driver_active[i]) {
        Serial.printf("*** Device %s - disconnected ***\n", driver_names[i]);
        driver_active[i] = false;
      } else {
        Serial.printf("*** Device %s %x:%x - connected ***\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct());
        driver_active[i] = true;

        const uint8_t *psz = drivers[i]->manufacturer();
        if (psz && *psz) Serial.printf("  manufacturer: %s\n", psz);
        psz = drivers[i]->product();
        if (psz && *psz) Serial.printf("  product: %s\n", psz);
        psz = drivers[i]->serialNumber();
        if (psz && *psz) Serial.printf("  Serial: %s\n", psz);
      }
    }
  }

  for (uint8_t i = 0; i < CNT_HIDDEVICES; i++) {
    if (*hiddrivers[i] != hid_driver_active[i]) {
      if (hid_driver_active[i]) {
        Serial.printf("*** HID Device %s - disconnected ***\n", hid_driver_names[i]);
        hid_driver_active[i] = false;
      } else {
        Serial.printf("*** HID Device %s %x:%x - connected ***\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct());
        hid_driver_active[i] = true;

        const uint8_t *psz = hiddrivers[i]->manufacturer();
        if (psz && *psz) Serial.printf("  manufacturer: %s\n", psz);
        psz = hiddrivers[i]->product();
        if (psz && *psz) Serial.printf("  product: %s\n", psz);
        psz = hiddrivers[i]->serialNumber();
        if (psz && *psz) Serial.printf("  Serial: %s\n", psz);
      }
    }
  }

}

I have turned on debug logging in USBHost_t36, and this is what I get on the serial console when I run the code:

Code:
 reset waited 5
USBHS_ASYNCLISTADDR = 0
USBHS_PERIODICLISTBASE = 1FFF4000
periodictable = 1FFF4000
port change: 14001403
    connect
  begin reset
port change: 14001005
  port enabled
  end recovery
new_Device: 1.5 Mbit/sec
new_Pipe

I have been able to connect to this device using a simple node.js CLI script, like so:

Code:
var HID = require('node-hid');
var devices = HID.devices();

console.log(devices)

var device = new HID.HID(1008,69);

device.on('data', function(data) {
  console.log(data);
})

This script successfully lists all of the HID devices on my machine, and receives data from the target device when it sends it.

The device in question shows up like this in Apple System Profiler:

Code:
HP Proximity Reader (X3D03A):

  Product ID:	0x0045
  Vendor ID:	0x03f0  (Hewlett Packard)
  Version:	16.00
  Speed:	Up to 12 Mb/sec
  Manufacturer:	Hewlett-Packard
  Location ID:	0x14100000 / 19
  Current Available (mA):	500
  Current Required (mA):	100
  Extra Operating Current (mA):	0

Any ideas on what I should be doing to connect to this device? Is there a better starting point or example that I should be working from? Thanks!
 
There are maybe a few different approaches I might take.

Was that the complete log of data of turning on the debug output? Was the device plugged in to the USB of the T3.6? And powered... If so, I would have expected to see messages about new device... When device is plugged in, plus information about someone trying to claim like the HID parsers. And if it found a HID device, then the RawHID object should try to do a claim collection and print out a message like:
RAWhid claim: <id vendor> <ID product>...

So you might try it again and try to capture and post the whole output...

a) Maybe a preferred approach is to understand the actual HID data, and setup your own HID parser object, like mouse or the like which understand the data and process it (which probably implies that you provide either interrupt call backs or query functions to grab the data.

b) With RAWHID there is code that only allows connection to:
// only claim RAWHID devices currently: 16c0:0486
if ((dev->idVendor != 0x16c0 || (dev->idProduct) != 0x486)) return CLAIM_NO;
Assuming you ever see the message about RawHid claim you might try editing that like to your vendor/product and see what it does
 
Was that the complete log of data of turning on the debug output? Was the device plugged in to the USB of the T3.6? And powered...

This was the complete log of powering up the Teensy with the device connected. It's connected directly to the Teensy. Maybe it needs more power than the Teensy can provide?

I will try again with a powered USB hub and see if I get the kind of results you describe.

Thanks for the pointers!
 
I looked more closely at how I was connecting the device to the Teensy and found a mistake.

It's working now, and I'm getting data. Thanks for the help, and your work on the USBHost stuff!
 
Status
Not open for further replies.
Back
Top