Skip to main content
  • Products
  • Evaluate our Software
  • Downloads
  • Free Utilities
  • Purchase
  • Support
  • About Us
  • Blog
  • Forum
  • Search
    • Contact Us
    • Forum
    • Knowledge Base
    • Web Shop
    • Newsletter
    • RSS
  •   Jobs
  •   Videos
  •   Blog
  •   Sustainability
  • emUSB-Device
  • WebUSB
  • Technology
  • Add-Ons

WebUSB access

Access your emUSB-Device target via JavaScript from a web browser.

Contact us
Downloads
Documentation
SEGGER emUSB-Device
  1. 1.What is WebUSB
  2. 2.Example
  3. 3.Try it now!
  4. 4.Additional information

What is WebUSB

WebUSB is an API standard to provide access to USB devices from web pages. WebUSB is developed by Google.
WebUSB can be used by a web page to communicate with a USB device which is connected to the user's PC.

This works seamlessly with emUSB-Device.

Example

The example on the right demonstrates a web page with 4 buttons which allow the LEDs on an evaluation board to be toggled on and off. The example uses WebUSB and the emUSB-Device-Bulk component.

Download Demo for the emPower board.

To try WebUSB with emUSB-Device download the above package, program the emPower board with the included .srec file, connect the USB cable and click connect. After that you will be able to control the board's LEDs with the buttons on the right.

For the sake of clarity the sample is separated into two JavaScript files and one web page which includes both and contains the HTML code for the buttons. The first JavaScript file "seggerbulk.js" describes the emUSB-Device-Bulk target and is used by WebUSB to find the device among the other USB devices connected to the PC. The second file "led.js" is responsible for sending the buttons status to our target.

The most important part of the first JavaScript file is the detection of the target running emUSB-Device-Bulk. This is done by creating a filter for the vendor and product IDs:

function _Connect() {
  var PromiseObj;

  _USBDev = new SeggerBulk({'vendorId': 0x8765, 'productId': 0x1240});
  PromiseObj = _USBDev.Connect();
  PromiseObj.then(_cbOnConnect, _cbOnError);
}

The JavaScript for the buttons contains a simple function which sends the LED status to the device on each click of a button:

function _cbOnLEDUpdate() {
  if (!_USBDev) {
    return;
  }
  var view = new Uint8Array(4);

  view[0] = _aLED[0].checked ? 1 : 0;
  view[1] = _aLED[1].checked ? 1 : 0;
  view[2] = _aLED[2].checked ? 1 : 0;
  view[3] = _aLED[3].checked ? 1 : 0;
  _USBDev.Send(view, null, _cbOnError);
  _USBDev.Receive(_cbOnDataReceived, _cbOnError);
}

Try it now!





Additional information

  • WebUSB API description https://wicg.github.io/webusb
  • List of browsers with WebUSB support https://caniuse.com/#search=webusb

Headquarters

SEGGER Microcontroller GmbH

Ecolab-Allee 5
40789 Monheim am Rhein, Germany
info@segger.com
Tel.: +49-2173-99312-0
Fax: +49-2173-99312-28

Locations

USA: SEGGER Microcontroller Systems LLC

Boston area
101 Suffolk Lane
Gardner, MA 01440, USA
us-east@segger.com
Tel.: +1-978-874-0299
Fax: +1-978-874-0599

Silicon Valley
Milpitas, CA 95035, USA
us-west@segger.com
Tel.: +1-408-767-4068

China: SEGGER Microcontroller China Co., Ltd.

Room 218, Block A, Dahongqiaoguoji
No. 133 Xiulian Road
Minhang District, Shanghai 201199, China
china@segger.com
Tel.: +86-133-619-907-60

ISO 9001 certified

ISO 9001

30+ years of experience

First-class embedded software tools since 1992
  • Imprint
  • Disclaimer
  • Privacy Policy
© 2025 SEGGER - All rights reserved.