-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbasic.py
67 lines (52 loc) · 1.83 KB
/
basic.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import argparse
import time
import platform
from radiacode import RadiaCode
from radiacode.transports.usb import DeviceNotFound as DeviceNotFoundUSB
from radiacode.transports.bluetooth import DeviceNotFound as DeviceNotFoundBT
def main():
parser = argparse.ArgumentParser()
if platform.system() != 'Darwin':
parser.add_argument(
'--bluetooth-mac', type=str, required=False, help='bluetooth MAC address of radiascan device (e.g. 00:11:22:33:44:55)'
)
parser.add_argument(
'--serial',
type=str,
required=False,
help='serial number of radiascan device (e.g. "RC-10x-xxxxxx"). Useful in case of multiple devices.',
)
args = parser.parse_args()
if hasattr(args, 'bluetooth_mac') and args.bluetooth_mac:
print(f'Connecting to Radiacode via Bluetooth (MAC address: {args.bluetooth_mac})')
try:
rc = RadiaCode(bluetooth_mac=args.bluetooth_mac)
except DeviceNotFoundBT as e:
print(e)
return
except ValueError as e:
print(e)
return
else:
print('Connecting to Radiacode via USB' + (f' (serial number: {args.serial})' if args.serial else ''))
try:
rc = RadiaCode(serial_number=args.serial)
except DeviceNotFoundUSB:
print('Device not found, check your USB connection')
return
serial = rc.serial_number()
print(f'### Serial number: {serial}')
print('--------')
fw_version = rc.fw_version()
print(f'### Firmware: {fw_version}')
print('--------')
spectrum = rc.spectrum()
print(f'### Spectrum: {spectrum}')
print('--------')
print('### DataBuf:')
while True:
for v in rc.data_buf():
print(v.dt.isoformat(), v)
time.sleep(2)
if __name__ == '__main__':
main()