2

I am working with a pressure-sensing mattress having a USB interface. The maker provides USB device drivers for Windows, and an API written in C++ which has functions to request data and set some parameters.

Currently, I cannot use this sensor for testing some Python data-visualization scripts directly, having had to ask my coworkers to write a text-logger for me, and then I read this information offline with Python.

Also, I cannot use Linux at all with the sensor, because there are not drivers for Linux, and I do not know where to start to "hack" the sensor, and that is why I am asking:

"If I were to try to read data from this sensor directly with Python and perhaps in Linux, what should I do first, or read first?"

EDIT: the device has an FTDI driver (FTD2XX.dll) if it helps.

Any help would be very welcome

heltonbiker
  • 26,657
  • 28
  • 137
  • 252

2 Answers2

3

Odds are fairly good it's a HID device, in which case you can probably start to write a userspace linux driver for it using libhid. First place to start with that would be enumerating the tree that gives you information about its capabilities. (lsusb -vvv or Example)

Failing that you can use libusb on linux (and other platforms too these days) to write a userspace driver still. You'll want to use something like usbsnoop or a real hardware equivalent to see what the official driver does when it's talking to the device and mimic it from there.

From the python side you can probably generate a decent wrapper to the existing C++ API using SWIG for relatively little effort, especially compared to developing an entirely custom driver.

Update:

If it's an FTDI device then it's might be a lot simpler to work with. Depending on what the vendor and product ID are showing it might automatically work with the FTDI driver in Linux, giving you as USB serial port. Failing that there are parameters to the module - vendor and product that I believe you can use to make it claim other devices besides the pid/vid combinations it knows about already. From there you can try opening the serial port device with different settings. With luck it might be sending state info regularly already.

If it's not you want to try and discover what the official software sends to make it start playing. You're back into the realm of sniffing again, but I think there might well be things that do it at the serial layer instead of the USB layer for windows (although I can't name any). You might also learn something by trying to make their library use a software emulated serial port instead of the FTDI device and seeing what it writes.

Community
  • 1
  • 1
Flexo
  • 87,323
  • 22
  • 191
  • 272
  • Very complete answer, I will have to take my time to inderstand it all, since I am not familiar with C. +1! – heltonbiker Aug 18 '11 at 18:29
  • I wrote a trivial userspace driver for a HID device a while back. Will try and dig it out. I'd still recommend wrapping existing code with swig over really low level stuff any day though! – Flexo Aug 18 '11 at 18:32
  • http://packages.debian.org/sid/python-hid skips the C side if you go down the HID route directly. Can't find my trivial example right now I think it's on a PC at work that's off. – Flexo Aug 18 '11 at 18:49
  • Great tip, @awoodland. I was reading the API documentation, and remembered the sensor uses FTD2XX.dll driver (has to do with FTDI, I guess). Does it change anything? Is it the same as HID? – heltonbiker Aug 18 '11 at 19:55
  • Might well be a serial device then. Same sort of thing applies for sniffing except you want to use usbserial kernel module to access it probably. – Flexo Aug 18 '11 at 20:18
  • Updated to talk about FTDI hunch more. – Flexo Aug 19 '11 at 09:16
1

The FTDI chips have a linux driver. Just go to the FTDI website and download it. The driver creates a virtual serial port. You can use PySerial to interface with it.

Too bad I didn't see the post sooner!

Jeff
  • 76
  • 6
  • Well, I appreciate your answer very much! Unfortunately we have put the project in a long stand-by, and besides that I am learning to program in C# already :o) – heltonbiker May 09 '13 at 03:08