Limited availability
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Note: This feature is available in Dedicated Web Workers.
The getInfo()
method of the SerialPort
interface returns an object containing identifying information for the device available via the port.
None.
Return valueAn object containing the following properties:
usbVendorId
If the port is part of a USB device, this property is an unsigned short integer that identifies the device's vendor. If not, it is undefined
.
usbProductId
If the port is part of a USB device, this property is an unsigned short integer that identifies the USB device. If not, it is undefined
.
bluetoothServiceClassId
Experimental
If the port is a Bluetooth RFCOMM service, this property is an unsigned long integer or string representing the device's Bluetooth service class ID. If not, it is undefined
.
This snippet calls the Serial.requestPort()
method when a <button>
is pressed. We pass a filter to requestPort()
to filter for Arduino Uno USB devices. Once a port is requested, we call getInfo()
to return the device's usbProductId
and usbVendorId
.
<button id="connect">Connect</button>
const connectBtn = document.getElementById("connect");
// Filter for devices with the Arduino Uno USB Vendor/Product IDs
const filters = [
{ usbVendorId: 0x2341, usbProductId: 0x0043 },
{ usbVendorId: 0x2341, usbProductId: 0x0001 }
];
connectBtn.addEventListener("click", () => {
try {
// Prompt the user to select an Arduino Uno device
const port = await navigator.serial.requestPort({ filters });
// Return the device's identifying info
const { usbProductId, usbVendorId } = port.getInfo();
} catch (e) {
// The user didn't select a device
}
});
Specifications Browser compatibility
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4