HID device to COM-Port

Status
Not open for further replies.

Clemi

Member
Hello,

I'm working on a program for Teensy 3.2 that shall interface with different UIs. Some of them communicate via HID interface, and some communicate via COM-Port.
For different reasons I would like to have my Teensy appear as HID RAW device, so communicating with "HID UIs" shouldn't be a problem. However, then I'm lacking the COM Port.

My preferred solution would be to have a small program, that can detect the HID device and redirect its communication to a some emulated COM-Port, that can be addressed like a usual COM-Port.
I guess, that should be possible, as Teensyduino implements an emulated Port into the Arduino IDE.

So far I haven't found any program for this task.

Maybe someone of you had a similar problem and can help me?

Thank you for reading,

Clemi
 
Hello,

I'm working on a program for Teensy 3.2 that shall interface with different UIs. Some of them communicate via HID interface, and some communicate via COM-Port.
For different reasons I would like to have my Teensy appear as HID RAW device, so communicating with "HID UIs" shouldn't be a problem. However, then I'm lacking the COM Port.

My preferred solution would be to have a small program, that can detect the HID device and redirect its communication to a some emulated COM-Port, that can be addressed like a usual COM-Port.
I guess, that should be possible, as Teensyduino implements an emulated Port into the Arduino IDE.

So far I haven't found any program for this task.

Maybe someone of you had a similar problem and can help me?

Thank you for reading,

Clemi

use seremu, it emulates serial line over HID and is part of hid-raw interface
(choose HID-RAW )
 
Thank you WMXZ for the fast reply.

As I understand correctly sermu is enabled by default when choosing RAW HID, at least that's how I interpret the description of RAW HID in usb_desc.h.

I assume, this allows to access the emulated serial line via Arduino IDE if Teensyduino is installed.

But how do I turn this emulated port into some "physically" available COM Port that is listed in my Windows Device Manager. The applications I would like to interface with, only look into the "real" COM-Port list. They are not able to connect to an emulated serial port.

Or may I be misunderstanding something of your explanation?
 
Thank you WMXZ for the fast reply.

As I understand correctly sermu is enabled by default when choosing RAW HID, at least that's how I interpret the description of RAW HID in usb_desc.h.

I assume, this allows to access the emulated serial line via Arduino IDE if Teensyduino is installed.

But how do I turn this emulated port into some "physically" available COM Port that is listed in my Windows Device Manager. The applications I would like to interface with, only look into the "real" COM-Port list. They are not able to connect to an emulated serial port.

Or may I be misunderstanding something of your explanation?

I assume you tried it first.
in fact I use the following script
Code:
void setup() {
  // put your setup code here, to run once:
while(!Serial);
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.println("loop");
delay(1000);
}
with HID_RAW selected.
and opening (after a while) the monitor in teensyduino, the word loop appeared.

If your question is, if there is a USB serial comport in the device manager (Windows) then NO , as we are using HID
You may have to write your own program
see foe example this old thread
https://forum.pjrc.com/threads/27123-RawHID-and-seremo-outside-Arduino
for a solution
 
Yes that was my question. I had a look at the thread you mentioned before. I also looked into the hidapi repository.
I found some windows executable called gui_test.exe. There I could select the HID "Port" and print the serial data to some box.
For me it didn't look like what I needed, but maybe I didn't get the full functionality of the program.

As you rewrote parts of the program, maybe you can tell me if there is such a possibility to create a comport for the device manager with this program.
 
I guess, that should be possible, as Teensyduino implements an emulated Port into the Arduino IDE.

Indeed Teensyduino does this, but not by actually emulating a COM port. I should know, and I wrote that code. The code actually modifies the Arduino Serial Monitor to use localhost networking, instead of the JSSC library. It does this by creating a Java class called "FakeSerial" which implements the Serial API. You can find that code here:

https://github.com/PaulStoffregen/A...pp/src/processing/app/TeensyMonitor.java#L282

In the same file, when the port is opened, a board-specific preference called "fake_serial" is checked. If found, the FakeSerial object is used. Otherwise, the normal Serial (which uses the JSSC library) is used. Here's that code:

https://github.com/PaulStoffregen/A...pp/src/processing/app/TeensyMonitor.java#L116

I realize this probably isn't what you want. You're probably wanting an actual COM port in Window which can be opened by any program like CoolTerm which only deals with COM ports.

My only point here is that Teensyduino isn't actually doing anything like that. It may appear that way from a casual view. I try very hard to make normal Arduino stuff "just work". But if you dig into the Java code Teensyduino uses, it's actually a pretty substantial patch to the Arduino Serial Monitor itself, to talk a completely different non-serial way.
 
To actually emulate a "real" COM port on Windows, perhaps take a look at this project:

http://com0com.sourceforge.net/

In the early days of Teensy, this was one of many ways I considered. Ultimately, I went with the HID-TCP gateway and a hack in the Arduino Serial Monitor because all that stuff can be done entirely from Windows user space, without installing any INF or driver level code. While the HID APIs are vastly different on Windows, Linux and Mac, they all work without driver installs, and the rest is very cross-platform. An approach that kept things as similar and compatible as possible on all 3 platforms was also a huge factor in my decision to do this way with the TCP hacks in the serial monitor.
 
Thank you Paul for all the information.

I was able to implement your last suggestion. With the difference that I used HW VSP, as com0com didn't work for me for unknown reason.

In principle, now it works. It's just a little bit clumsy to achieve my goal, as I need to start teensy_gateway first and then configure HW VSP.

Another idea would be to combine RAW HID interface and Serial Port. Is that possible?
I would imagine Serial would give me a Com-Port and I could connect HID compatible programs to the HID interface.
 
I'm pretty sure you can make the device a composite device yes.

HW VSP and launching teensy_gateway can all be done from a .bat file. So I wouldn't really consider it clumsy. Depends on if HW VSP can run headless
 
Well, I tried to implement both.

I changed the usb_desc.h following this example to:

Code:
#elif defined(USB_RAWHID_USB_SERIAL)
  #define VENDOR_ID		0x16C0
  #define PRODUCT_ID		0x0483
  #define DEVICE_CLASS		2	// 2 = Communication Class FROM USB_SERIAL
  #define RAWHID_USAGE_PAGE	0xFFAB  // recommended: 0xFF00 to 0xFFFF
  #define RAWHID_USAGE		0x0200  // recommended: 0x0100 to 0xFFFF
  #define MANUFACTURER_NAME	{'T','e','e','n','s','y','d','u','i','n','o'}
  #define MANUFACTURER_NAME_LEN	11
  #define PRODUCT_NAME		{'T','e','e','n','s','y','d','u','i','n','o',' ','R','a','w','H','I','T'}
  #define PRODUCT_NAME_LEN	18
  #define EP0_SIZE		64
  #define NUM_ENDPOINTS         5
  #define NUM_USB_BUFFERS	24
  #define NUM_INTERFACE		2
  #define RAWHID_INTERFACE      0	// RawHID
  #define RAWHID_TX_ENDPOINT    1
  #define RAWHID_TX_SIZE        64
  #define RAWHID_TX_INTERVAL    1
  #define RAWHID_RX_ENDPOINT    2
  #define RAWHID_RX_SIZE        64
  #define RAWHID_RX_INTERVAL    1
  #define CDC_STATUS_INTERFACE	1	//FROM USB_SERIAL
  #define CDC_DATA_INTERFACE	2	//FROM USB_SERIAL
  #define CDC_ACM_ENDPOINT	3		//FROM USB_SERIAL
  #define CDC_RX_ENDPOINT       4	//FROM USB_SERIAL
  #define CDC_TX_ENDPOINT       5	//FROM USB_SERIAL
  #define CDC_ACM_SIZE          16	//FROM USB_SERIAL
  #define CDC_RX_SIZE           64	//FROM USB_SERIAL
  #define CDC_TX_SIZE           64	//FROM USB_SERIAL
  #define ENDPOINT1_CONFIG	ENDPOINT_TRANSIMIT_ONLY
  #define ENDPOINT2_CONFIG	ENDPOINT_RECEIVE_ONLY
  #define ENDPOINT3_CONFIG	ENDPOINT_TRANSIMIT_ONLY
  #define ENDPOINT4_CONFIG	ENDPOINT_RECEIVE_ONLY
  #define ENDPOINT5_CONFIG	ENDPOINT_TRANSIMIT_ONLY

Other files were changed as well.

To use CDC Serial and SEREMU at the same time, does not seem possible as they both seem to access Serial.
Am I right on this Paul?

Result is the following:
If I set
Code:
#define PRODUCT_ID		0x0483
the device will be recognized as COM Port and I can read serial messages.
However it is not recognized as HID device by the rawhid_exe.exe obtained here.
This is probably do to the fact that 486 is set as Product ID. (Unfortunately I was not able to compile the sourcecode with another Product ID due to my lack of programming skills :( )

If I set the the Product ID to 486 the device will be recognized as HID device, but not as Serial Port. I wonder why.
Is there some Serial Port Driver linked to the Product ID 483?
 
Is there some Serial Port Driver linked to the Product ID 483?

Have a look at Paul's comments at the top of that header file.
If I remember correctly he states that windows will maintain previous information based on Product ID so you need to make it unique if you're changing things
 
Status
Not open for further replies.
Back
Top