Best way to communicate with Windows program

Status
Not open for further replies.

jpatrick62

Well-known member
I am using a MPU-9250 to talk to a WPF Windows program for primarily gyro axis updates in a 3D program. I can't rule out accelerometer and magnetometer axis updates presently
since the project could eventually include those as well. So, worst case, I have 10 bytes (AX/AY/AZ/GX/GY/GZ/MX/MY/MZ plus temp) going across to Windows
at a sample. I've used the USB HID driver before for this sort of thing as well as the serial port - any other thoughts on the best way to interact with Windows?
 
What exactly is the problem with 10 bytes?
USB-Packets, for example, are 64 Bytes anyway. And the MPU is slow enough.
 
Last edited:
thoughts on the best way to interact with Windows?

It depends on what you consider "best", and whether you wish to support older than Windows 10.

All versions of Windows since 2000 support HID "out of the box". But programming for HID on the Windows side can be tricky. Mingw makes it easier. If you use Microsoft's tools, you might need to download their huge WDK add-on.

Serial has tons of examples, so if "best" is minimum effort to reuse public code, maybe serial is more compelling? Windows 10 *finally* knows how to load its own driver, but Windows XP, 7, 8 need an INF installed, which can be a real downside. While it's possible to auto-locate the COM port using the Windows setup API, that's very complicated. Generally programs have the user select the COM port, which may or may not factor into your decision.

Really depends on your criteria, which I can't understand from your question. Hopefully this helps anyway?
 
While it's possible to auto-locate the COM port using the Windows setup API, that's very complicated. Generally programs have the user select the COM port, which may or may not factor into your decision.

Since you wrote that you are using WPF I assume you are using dotNet/c# and are not too keen on using complicated low level API calls :). Instead, you can simply use TeensySharp https://github.com/luni64/TeensySharp to identify connected Teensies. E.g. printing a list of all connected Teensies showing their serial numbers and com ports is as easy as:

Code:
var Watcher = new TeensyWatcher(); 
foreach (USB_Device Teensy in Watcher.ConnectedDevices)
{
    Console.WriteLine("Serialnumber {0}, on {1}", Teensy.Serialnumber, Teensy.Port);
}

You can also use TeensySharp to upload firmware from within your application if that is a use case for your application.

Driver:
Windows 10 *finally* knows how to load its own driver, but Windows XP, 7, 8 need an INF installed, which can be a real downside.
Win10 is a big improvement regarding the COM port driver indeed. Anyway, you can download the driver for Windows versions < 10 here https://www.pjrc.com/teensy/td_download.html (look for Windows Serial Installer) and add it to your installer or instruct your users to install this driver before they install your application. IMHO, installing drivers was and still is pretty much standard if you connect new hardware to a PC.

HID:
If you wan't to go the HID road you can use this library https://github.com/mikeobrien/HidLibrary.

Here a short snippet from TeensySharp
Code:
...
var devices = HidDevices.Enumerate(0x16C0, 0x0478);                         // Get all boards with running HalfKay
device = devices.FirstOrDefault(x => GetSerialNumber(x) == Serialnumber);   // check if the correct one is online
...
var report = PrepareReport(addr, dataBlock.ToArray(), BoardDef);            // copy data into a HID report...     
device.WriteReport(report))                                                 // ...and send it to the Teensy       
...
 
Last edited:
Sorry, should have made my question clearer. I have implemented the HID driver on other projects to talk to Windows and of course it does take somewhat more effort to do. I ended up having some issue getting .net to work with rawhid and compiled a
64 bit dll version which worked fine. My question should have been what is the fastest way to send data to Windows, as the MPU9250 chip connected to a Teensy 3.2 via SPI can dump a ton of information out fast. I suspect the answer is HID, but I didn't know if there was any other methods that others have used.
 
I believe that all Teensys use a Full/Low speed USB 2.0 implementation, which limits any communication to 12 Mbits/second theoretical maximum.

The Teensy 3.6 does have the pins for a second USB port that can run at High speed (480 Mbits/second theoretical maximum). I don't know what the state of the libraries are to support this port.

I presume you know for the fastest speed, you should be buffering the values sent, so that the overhead of each data packet is reduced. But you need to tailor the buffer size to the individual medium, and of course deal with smaller values when you need a real time response.
 
Yes.
As long as you use USB, the speed should hardly differ between the interfaces.
You should take care not to send single bytes, but as large packets as possible to use the interface to its full capacity.
But I still wonder if the MPU is really getting anywhere near the USb speed. I don't know this special MPU, but normally they are several orders of magnitude slower than USB? If I'm wrong, an info would be nice!
 
Good points all - thanks. Looks like the HID driver is probably the most optimal method and one that doesn't require a (serial) driver install for clients not up to Windows 10.
 
Status
Not open for further replies.
Back
Top