-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
786699e
commit ebf7304
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Serial Ports</title> | ||
</head> | ||
<body> | ||
<h1>Available Serial Ports:</h1> | ||
<button id="listPorts">List Ports</button> | ||
<ul id="ports"></ul> | ||
|
||
<script> | ||
document.getElementById('listPorts').addEventListener('click', async () => { | ||
if ('serial' in navigator) { | ||
try { | ||
const ports = await navigator.serial.getPorts(); | ||
const ul = document.getElementById('ports'); | ||
ul.innerHTML = ''; // Clear the list before adding new items | ||
ports.forEach(port => { | ||
const li = document.createElement('li'); | ||
li.textContent = port.getInfo().usbProductId || 'Unknown'; | ||
ul.appendChild(li); | ||
}); | ||
} catch (err) { | ||
console.error('There was an error opening the serial port:', err); | ||
} | ||
} else { | ||
console.error('Web serial doesn\'t seem to be enabled in your browser. Try enabling it by visiting:'); | ||
console.error('chrome://flags/#enable-experimental-web-platform-features'); | ||
console.error('opera://flags/#enable-experimental-web-platform-features'); | ||
console.error('edge://flags/#enable-experimental-web-platform-features'); | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> |