-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmodt_status.py
More file actions
32 lines (26 loc) · 772 Bytes
/
modt_status.py
File metadata and controls
32 lines (26 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
# Requires pyusb and permissions to read/write the mod-t via USB.
# Just polls the Mod-T for status JSON
import sys
import os
import usb.core
import usb.util
import time
# Read pending data from MOD-t (bulk reads of 64 bytes)
def read_modt(ep):
text=''.join(map(chr, dev.read(ep, 64)))
fulltext = text
while len(text)==64:
text=''.join(map(chr, dev.read(ep, 64)))
fulltext = fulltext + text
return fulltext
# Find MOD-t usb device
dev = usb.core.find(idVendor=0x2b75, idProduct=0x0002)
# was it found?
if dev is None:
raise ValueError('Device not found')
#Finally, loop and query mod-t status every 5 seconds
while True:
dev.write(4, '{"metadata":{"version":1,"type":"status"}}')
print(read_modt(0x83))
time.sleep(5)