-
Notifications
You must be signed in to change notification settings - Fork 2
/
readUart.py
68 lines (47 loc) · 1.47 KB
/
readUart.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
68
# from util import path
from crownstone_uart.topics.DevTopics import DevTopics
from crownstone_uart import CrownstoneUart, UartEventBus
import sys, time, logging
# from util.util import programCrownstone, findUsbBleDongleHciIndex, findUartAddress
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
uart = CrownstoneUart()
def initLibs():
# import traceback
# try:
# address = findUartAddress()
# if address == False:
# print("Could not find Crownstone")
# else:
uart.initialize_usb_sync()
# except:
# print("----- ----- Error in settings UART Address", sys.exc_info()[0])
# traceback.print_exc()
# print("tester not working, reboot test")
def enableUart():
# enable UART
print("----- Enabling UART...")
uart._usbDev.setUartMode(3)
def _getMacAddress():
result = [True, None]
def handleMessage(container, data):
container[0] = False
container[1] = data
subscriptionId = UartEventBus.subscribe(DevTopics.ownMacAddress, lambda data: handleMessage(result, data))
uart._usbDev.requestMacAddress()
counter = 0
while result[0] and counter < 50:
counter += 1
time.sleep(0.05)
UartEventBus.unsubscribe(subscriptionId)
return result[1]
initLibs()
time.sleep(1)
enableUart()
time.sleep(1)
mac = _getMacAddress()
print("MACY", mac)
try:
while True:
time.sleep(0.2)
except KeyboardInterrupt:
uart.stop()