USB Hid questions(HIDAPIDeviceMBS)

Hi all.

I need help. I am trying to query a usb hid device for information and as a second question, I need to be able to set new information.
I have looked at Hid USB Plugin from MBS. I am getting there with that plugin.

I have found the device, and have it in a HIDAPIDeviceMBS object. I can query serial number, vendor and such, that all fits. Of course this is not all I need.

I need to be able to fetch the date of the device, according to the device manual, I should send 0x1008 to the device to get back 8 bytes which tells you the date, like seconds, minutes, hours, day of week, day of month, month, year lsb, year msb.

And I also need to be able to send a new date in the same format, to 0x0006.

Anyone out there that can explain the above and help me out ?

I’ve not used the HIDAPIDevice, but I have used just the regular MacHIDMBS and WinHIDMBS classes. Assuming the other library works the same way you may still need some driver stuff loaded for it to talk to it. I don’t know what platform you are talking to but on the Mac we had to create a mostly empty kernel extension for the device. It contained no code at all, just the plist file describing the device and telling the HID manager to present it to anything asking about HID devices. I can send you the example we made if you want to experiment with that on a Mac. I”m not sure if thats necessary though if you’ve already got a reference to the device as you said in that other thread. In our case the device wasn’t recognized at all until the installation of the kernel extension shell thing.

Once you have that reference you should be able to use the read and write methods of the HIDAPIDeviceMBS class to send that data and read back the response. Those 0x… look like just 2 byte messages in hex? Have you tried just using the write methods yet? I’ve not done a lot of USB device development but I have some more coming up which is why I’m paying attention :wink:

Well, you probably need to know the block size for messages.
see InputReportLength property.

Than create memoryblock of that size and fill with data for request.
Maybe you just need to set a byte or so.
Send that and see if you get something back.

@James Sentman I am starting to believe that perhaps the device does not work on a Mac. Can you give me the information on the steps you had to do ?
How would you also do the driver install for a customer ?

@Christian Schmitz I added the following code near the top of the example called USB Hid devices for mac

      ListBox1.AddRow ""
      if ((hex(m.ProductID) = "929") and (hex(m.VendorID) = "2047")) then
        dim mb as new MemoryBlock(13)
        dim res as new MemoryBlock(13)
        dim s as string
        if m <> nil then
          dim v as Dictionary = m.HIDProperties
          'title = mydev.GetFeatureReport
          mb.UInt8Value(0) = &h3f
          mb.UInt8Value(1) = &h00
          mb.UInt8Value(1) = &h03
          s = hex(m.ReadMessage(val(mb), MacHIDMBS.kIOHIDReportTypeInput, 2))
          res = m.ReadMessageMemory(val(mb), 2, 8)
          dim error as Integer = m.Lasterror
          dim x as integer = 0
        end if
      end if

I know that the feature page is hex 3f, according to the manual, I need to send the request 0x0003 and I should get some information back, but I am getting 0 back and res is Nil

Will try this on windows just to be sure a little later

you set values into a memoryblock and than do a val() on it? Sounds crazy.

I don’t see where you write something to the connection, too.

you are using MacHIDMBS or HIDAPIDeviceMBS?
First is Mac only, second cross platform.

This is all new to me, any assistance is greatly appreciated. Memory blocks is something I have never used in Xojo.
Do I write first ? Read ? I don’t know

How should I do this ? I only need this to work on the Mac.

We continue by email :slight_smile:

@James Sentman I am using OSX. The device is a heart monitor. I am getting a sneaky feeling that OSX is only accepting the device as a storage device, the device has a little storage on it that gets mounted on OSX.

I am almost at the conclusion that I frankly can’t access these portion of the device that I need to, in order to check battery status. Any help would be appreciated.

I was wondering, If I use the Windows tools of MBS to test this, I know the device works as it should do on windows. Is this what I do ?

  1. Get the device from the device list.
  2. Send an memoryblock to it with “0x3f (page), 0x0A (size of block), 0x03 (asking for battery byte)”, so I send this to the device using write, then I read from just 0x3f ?

Can anyone help me here ? I either need to solve this case or give up, I can’t use more time on it.
Does anyone have any code that reads from a feature page ?

Keep in mind, I might not be asking the right question here or wording it correctly. I have a HiD device that I need to get the battery status of. The feature page is 0x3f and according the manual of the device 0x0003 gives you the battery status as 2 bytes, that is all I have.

As I saw in the docs you emailed me, you need to send a data package with right bytes on begin and end including a checksum.