Teensy Sharp watcher not seeing Teensy 3.6 boards

Status
Not open for further replies.

John E B

Member
I want to communicate from a simple windows console app with Teensy 3.6 with usb type flight sim controls. Using the Arduino (v1.8.13) serial monitor & port set to emulated serial hid#vid16c0&pid0488 everything works as expected.
I have tried to write a windows console application to communicate with the Teensy. After a quick search on how to do this things got very complicated very quickly with lots of code examples many pages long on handling HID/USB. Mostly well beyond my ability to understand the code.

I have downloaded TeensySharp from https://github.com/luni64/TeensySharp. This is well documented so I have a chance to understand it. I have used MS Visual studio 2019 and the Teensywatcher console example which compiles and runs with no errors My Teensey boards do not appear in the output and I am at a loss as to why.

I have found a program HIDSharp by James F. Bellinger https://www.zer7.com/software/hidsharp This runs and outputs a list of all USB devices and sees Teensy boards. Unfortunaely it is to advanced for me to understand the code.
As always any guidance suggestions greatly appreciated.

HIDSharp output.jpg

Have included my Arduino code for completeness. Ultimately I hope to do a little more than this.


/
Code:
*
 Name:		TestSerialonArduino.ino
 Created:	26/01/2021 1:10:28 PM
 Author:	John
*/

// the setup function runs once when you press reset or power the board
void setup() {
	Serial.begin(9600);
	pinMode(13, OUTPUT);
 
}

// the loop function runs over and over again until power down or reset
void loop() {

	String readstring;
	String Q;
//------------------------check serial port ----------------
	while (Serial.available()) {
		delay(5);
		if (Serial.available() > 0) {
			char c = Serial.read(); // gets single byte from buffer
			if (isControl(c)) {
				break;
			}
			readstring += c; // makes string readString

		}
	}
	Q = readstring;

	if (Q == "on")
	{
		Serial.println("Flaps downn");
		digitalWrite(13, HIGH);
	}

	if (Q == "off")
	{
		Serial.println("Flaps up");
		digitalWrite(13, LOW);
	}


}
 
If you do it this way, it's just a com port - no complicated HID Stuff.
You can check this by using a simple terminal program.

My suggestions for this:
So first try it simple: open the comport with the right number (Arduino shows it) - this should work (make sure to have the Arduino serial monitor closed)
You can try more advanced things after that..

Edit: Ooops... forget that... flight sim-... have not read that.
Sorry, I have no experience with that. Forget my Text above.

Perhaps take a look at the FlightSim examples.
 
I want to communicate from a simple windows console app with Teensy 3.6 with usb type flight sim controls. Using the Arduino (v1.8.13) serial monitor & port set to emulated serial hid#vid16c0&pid0488 everything works as expected.
I have tried to write a windows console application to communicate with the Teensy. After a quick search on how to do this things got very complicated very quickly with lots of code examples many pages long on handling HID/USB. Mostly well beyond my ability to understand the code.

I have downloaded TeensySharp from https://github.com/luni64/TeensySharp. This is well documented so I have a chance to understand it. I have used MS Visual studio 2019 and the Teensywatcher console example which compiles and runs with no errors My Teensey boards do not appear in the output and I am at a loss as to why.

I have found a program HIDSharp by James F. Bellinger https://www.zer7.com/software/hidsharp This runs and outputs a list of all USB devices and sees Teensy boards. Unfortunaely it is to advanced for me to understand the code.
As always any guidance suggestions greatly appreciated.

The published version of TeensySharp is quite old and doesn't detect all USB Types. There is a much newer version in the development branch which should work with FlightSim, but it still has some rough edges (need to finalize this sometime...). Anyway, it is quite simple to communicate via RawHID in C#. The user WIKI contains some examples: https://github.com/TeensyUser/doc/wiki/Raw-HID.


Converting the examples to SerEMU should be straight forward. Changing the VID to Flightsim and the usage/usage page from RawHID to SerEMU should do the trick. Let me know if you need help with it.
 
Luni Thanks for your reply. I will take a look at the newer version and have a read through the wiki. It might take me a while to get to understand all this but I will let you know how I get on.
 
Using USB with Flightsim

Luni
I have gone through the tutorial and examples in the user wiki and the examples are clear. However I have not been able to sucessfully change the VID to Flightsim and the usage/usage page to SerEMU as you suggest.
The VID from the HID report seems to be the same for both raw HID and when I set the USB type to Flightsim controls. Also I can not identify the usage/usage page correctly. Currently the only way I can get my application to work is always open Arduino and use the serial monitor. So not really a long term solution.
If you can give me any further help I would really appreciate it as I am basically stuck.

I have attached the HID report and my code just for completeness.
 

Attachments

  • HID report.txt
    2.6 KB · Views: 45
  • FlightControl panel.c
    20.1 KB · Views: 32
Here a simple example showing how to receive SerEMU data from a FligthSim device (uses Mike O'Brien's HidLibrary https://www.nuget.org/packages/hidlibrary/3.3.40)

Code:
using HidLibrary;
using System;
using System.Linq;

namespace receiver
{
    class Program
    {
        static void Main(string[] args)
        {
            int VID         = 0x16C0;                   // PJRC 
            int PID         = 0x488;                    // FlightSim
            short usage     = 0x0004;                   // SerEMU has usagePage: 0xFFC9 and usage 0x004
            short usagePage = unchecked((short)0xFFC9); // unfortunately the lib requires a short instead of an ushort -> need to convert...
            
            var teensy = HidDevices.Enumerate(VID,PID)  // get hold of the first SerEMU FlightSim device we find on the bus
                   .Where(d => d.Capabilities.UsagePage == usagePage && d.Capabilities.Usage == usage) 
                   .FirstOrDefault();                        

            while (teensy != null)
            {
                var report = teensy.ReadReport();       // request a report from the teensy
                Console.WriteLine(report.Data[0]);      // and write its first byte to the console
            }
        }
    }
}

Here the Teensy sketch (USB mode: FlightSim) which just prints an increasing number to the SerEmu interface

Code:
uint8_t cnt = 0;

void setup(){
}

void loop()
{
  Serial.write(cnt++);
  delay(250);
}

Output:
Screenshot 2021-04-23 093648.jpg

Hope that helps
 
Last edited:
Luni thanks very much for this.
Can you tell me which USB files you find things like usagePage: 0xFFC9 and usage 0x004? I have looked at the Teensy core usb_flightsim files and in prticular usb.c which contains descriptor data but these things are quite tough to understand.

I am trying to understand Mike O'Brien's HidLibrary but are struggling to find how to use it. Do yopu know if there is any documenttion for this other than what I have found on the link you provided?

I will experiment with the code you have provided. Next I will try sending data from the PC to the Flightsim code on the Teensy.

Thanks again for your help with this.
 
Luni thanks very much for this.
Can you tell me which USB files you find things like usagePage: 0xFFC9 and usage 0x004? I have looked at the Teensy core usb_flightsim files and in prticular usb.c which contains descriptor data but these things are quite tough to understand.

The SerEmu interface not related to fligthsim. More or less all Teensy USB modes which don't have a "real" Serial interface provide a SerEmu interface. You find the corresponding report descriptor in usb_desc.c (https://github.com/PaulStoffregen/c...10530a4e621395c4d51f7/teensy4/usb_desc.c#L453)

I am trying to understand Mike O'Brien's HidLibrary but are struggling to find how to use it. Do yopu know if there is any documenttion for this other than what I have found on the link you provided?

Like so often there is not much documentation other than the code :) On the other hand, there is not much to know about it. You can enumerate the HID devices and filter by VID/PID. You can get/send reports to/from a device by readReport / sendReport as shown in the example above and in the TeensyUser WIKI (for RawHID). . Reading the serial number (device.ReadSerialNumber()) comes in handy if you need to handle more than one USB device on the bus.

Here some examples how I use the HidLibary in TeensySharp:
https://github.com/luni64/TeensySha...7ce9513/src/TeensySharp/TeensyWatcher.cs#L190
 
Status
Not open for further replies.
Back
Top