SerialPort: getInfo() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
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.
Syntax
getInfo()
Parameters
None.
Return value
An 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
.
Example
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
Specification |
---|
Web Serial API # dom-serialport-getinfo |
Browser compatibility
BCD tables only load in the browser