Skip to main content
  • 产品
  • Evaluate our Software
  • 下载
  • Free Utilities
  • 购买
  • 芯片厂商
  • 支持
  • 关于我们
  • Search
  • 工作机会
  • 新闻简报
  • 联系我们
  • 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

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
  • Try it now!
  • Additional information

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
  • User manual
  • List of downloads
  • Update notification
  • Pricing
  • Support
  • Silicon vendor resources

全球总部

德国: SEGGER Microcontroller GmbH

地址: Ecolab-Allee 5
40789 Monheim am Rhein, Germany
电邮: info@segger.com
电话: +49-2173-99312-0
传真: +49-2173-99312-28

网点分布

中国:哲戈微系统科技(上海)有限公司

地址: 中国上海市闵行区秀涟路133号
大虹桥国际A 栋218室
邮编201199
电邮: china@segger.com
电话: +86-133-619-907-60


简易信息聚合

通过ISO 9001认证

ISO 9001

30多年的嵌入式行业经验

First-class embedded software tools since 1992
  • 版本说明
  • 免责声明
  • 隐私策略
  • 沪ICP备2022005181号
  • 沪公网安备 31011202014525号
© 2025 SEGGER - 版权所有.

您即将离开 segger.cn 而访问境外网站,是否继续?