More details on:
http://breaking-the-system.blogspot.com/2014/08/emulating-usb-devices-in-python-with-no.html
http://breaking-the-system.blogspot.com/2014/08/emulating-usb-devices-in-python-with-no.html
USB: Raw HID If you want to create a custom application, Raw HID is simple way to send 64 byte packets between your code on the Teensy and your application on the PC or Mac. HID works automatically with built-in drivers in Linux, Mac OS X and Windows, so users will not need to load any drivers. For converting to usb serial emulation honeywell metrologic mx009 2ma8c cable. Scanner from keyboard wedge or rs232 interface to usb keyboard or usb com.
This code uses the USB/IP project: http://usbip.sourceforge.net/ to emulate usb devices.
In this example I showed how to emulate HID mouse device.
This code can be easily changed to support any usb device.
This code is very experimental, use with care.
In the HID example there is a bug with USB/IP driver that causes blue screen on de-attach:
http://sourceforge.net/p/usbip/discussion/418507/thread/7ff86875/?page=0
It doesnt happen with other devices I tested.
In this example I showed how to emulate HID mouse device.
This code can be easily changed to support any usb device.
This code is very experimental, use with care.
In the HID example there is a bug with USB/IP driver that causes blue screen on de-attach:
http://sourceforge.net/p/usbip/discussion/418507/thread/7ff86875/?page=0
It doesnt happen with other devices I tested.
Table of Contents
Mbed OS 2 and Mbed OS 5
This is the handbook for Mbed OS 2. If you’re working with Mbed OS 5, please see the Mbed OS 5 documentation. For the latest information about Serial, please see The Windows Serial Driver.
The USBSerial interface is used to emulate a serial port over USB. You can use this serial port as an extra serial port or as a debug solution. It's also a great solution to easily communicate between your mbed and a computer.
The USB connector should be attached to
- p31 (D+), p32 (D-) and GND for the LPC1768 and the LPC11U24
- The on-board USB connector of the FRDM-KL25Z
Driver required on Windows!
On Windows, you need a configuration file. You can download this archive containing a .inf file. Extract it.
When you plug your USBSerial serial device, Windows will try to find an existing driver for it without success. After this step, go into the device manager to find the unknown device:
When you plug your USBSerial serial device, Windows will try to find an existing driver for it without success. After this step, go into the device manager to find the unknown device:
- Right click on the device
- Update driver software
- Click on 'Browse my computer for driver software'
- Indicate the path of serial.inf extracted previously and click next.
- Accept the warning and you should have a virtual port (called Mbed Virtual Serial Port in device manager) over USB!
As product_id and vendor_id are hardcoded in the .inf file, if you don't want to use default values, you will have to change them in your program AND in the .inf file.
Hello World¶
API¶
Public Member Functions | |
USBSerial (uint16_t vendor_id=0x1f00, uint16_t product_id=0x2012, uint16_t product_release=0x0001) | |
Constructor. | |
virtual int | _putc (int c) |
Send a character. | |
virtual int | _getc () |
Read a character: blocking. | |
uint8_t | available () |
Check the number of bytes available. | |
bool | writeBlock (uint8_t *buf, uint16_t size) |
Write a block of data. | |
template<typename T > | |
void | attach (T *tptr, void(T::*mptr)(void)) |
Attach a member function to call when a packet is received. | |
void | attach (void(*fn)(void)) |
Attach a callback called when a packet is received. |
More example¶
In this example, the program waits a line on the virtual serial port. When it receives a line, it sends it to the usual mbed serial port (the one used to flash a new program) and to the virtual one.