RAWHID demonstration program

DrM

Well-known member
Attached is a "sketch" and python program to demonstrate use of the RAWHID.

The sketch demonstrates data transfers in both directions and simple command processing. The python side includes an optional queue, using either thread or multiprocess, to handle rapid or asynchronous data from the teensy to the host computer. The read() is agnostic of whether the packets are being stored onto the queue .

The use cases here are related to data acquisition. I use the Teensy to implement a gated spectrometer and a high end analog and digital I/O card. So far, the RAWHID interface, compared to the serial interface, seems to resolve problems with fast and large data transfers.
 

Attachments

  • TeensyRawUSB210620.zip
    4.3 KB · Views: 83
In an – so far unsuccessful – attempt to get RAWHID communication between Teensy and Python working, I came across this post and your code example. As I have very little experience with Python, I am hoping to find existing code that at least successfully establishes a connection, and then try to adapt it to my needs (which are very basic). However, trying to run your python script, I get a
Code:
TypeError: enumerate() got an unexpected keyword argument 'vendor_id'
error. I don't even know enough about Python to be able to tell if this is a problem with the code or perhaps with my Python setup.

Can you perhaps offer any advice?

Thanks, Wolfgang
 
Hi luni, it already has. Of course – as was bound to happen – just 5 minutes after I wrote the above, I found the wiki. Thank you anyway!
 
@wpunkts That looks like it is coming from the call to hid.enumerate(). Rejecting a keyword is a little surprising. Perhaps you are using a different python library for the hid? Or, perhaps the api changed since my code snippet was written? Or perhaps, and not too inconceivably, something is not connected electrically and the library is not initializing something that provides that keyword.

Aside, I now use serial communications only, two ports, and each port is used in one direction only. it seems this is the most reliable arrangement for fast high volume data transfers.
 
@DrM: To be honest, I didn't keep looking into this any further. With the examples I found in the wiki, I've managed to start piecing something together that looks promising.

Is the RAW HID approach the right/best one? I don't know, but it has worked for me in the past (I don't need fast high volume transfers, and one-way only, Teensy to Computer) on a Mac, although with a little utility written in C on the receiving end. Now that I need to replicate something similar for a Windows-based system (with which I have very little familiarity, and neither time nor interest to invest too much into), I figured the easiest way would be to keep my Teensy-side code as is, and implement the computer side in python.

That, plus – and I might well be wrong about this – I feel RAW HID is more robust than serial under the circumstances I need this to work in (someone might unplug the Teensy and then replug it, and the system needs to just pick up from where it was and keep working).
 
Serial, two ports (or one port in one direction i suppose) seems to be very robust.
 
Back
Top