Skip to content

Commit e15bb44

Browse files
committed
add reference script for spark 4 detection
1 parent ce8c912 commit e15bb44

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"mounts": [
3737
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind", // mount the Docker socket
3838
"source=/etc/localtime,target=/etc/localtime,type=bind,readonly", // mount localtime
39-
"source=/dev,target=/dev,type=bind", // Required for recognizing new USB devices
39+
"source=/dev,target=/dev,type=bind" // Required for recognizing new USB devices
4040
// "source=${localWorkspaceFolder}/.devcontainer/.bash_aliases,target=/home/vscode/.bash_aliases,type=bind",
4141
// "source=brewblox-usb-proxy-extensions,target=/home/vscode/.vscode-server/extensions,type=volume"
4242
],

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The return value is a JSON object with all detected devices.
1616
The key is the device ID, and the value is the associated TCP port, or `null` if no proxy is active.
1717

1818
Example output:
19+
1920
```json
2021
{
2122
"30003d001947383434353030":null,

find_usb_devices.py renamed to find_spark_3.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
if (tty / 'device' / 'subsystem').resolve() != Path('/sys/bus/usb'):
88
continue
99

10-
dev = (tty / 'device').resolve()
11-
usb_vid = (dev / '..' / 'idVendor').read_text().strip()
12-
usb_pid = (dev / '..' / 'idProduct').read_text().strip()
13-
usb_device_id = (dev / '..' / 'serial').read_text().strip()
10+
dev_root = (tty / 'device').resolve() / '..'
11+
usb_vid = (dev_root / 'idVendor').read_text().strip()
12+
usb_pid = (dev_root / 'idProduct').read_text().strip()
13+
usb_device_id = (dev_root / 'serial').read_text().strip()
1414

1515
print(tty)
1616
print('\t', f'{usb_vid}:{usb_pid}')

find_spark_4.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from glob import glob
2+
from pathlib import Path
3+
from subprocess import run
4+
5+
for tty in glob('/sys/class/tty/ttyUSB*'):
6+
tty = Path(tty)
7+
8+
if (tty / 'device' / 'subsystem').resolve() != Path('/sys/bus/usb-serial'):
9+
continue
10+
11+
dev_root = (tty / 'device').resolve() / '..' / '..'
12+
usb_vid = (dev_root / 'idVendor').read_text().strip()
13+
usb_pid = (dev_root / 'idProduct').read_text().strip()
14+
usb_device_id = (dev_root / 'serial').read_text().strip()
15+
16+
print(tty)
17+
print('\t', f'{usb_vid}:{usb_pid}')
18+
print('\t', usb_device_id)
19+
print('\t', '/dev/' + tty.name)
20+
21+
# To listen to the serial port, use the below code
22+
# if usb_vid == '10c4' and usb_pid == 'ea60':
23+
# run(['sudo', '/usr/bin/socat', '-u', f'file:/dev/{tty.name},raw,echo=0,b115200', '-'])
24+
# break

0 commit comments

Comments
 (0)