-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmimic.py
65 lines (57 loc) · 1.73 KB
/
mimic.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
import asyncio
import serial_asyncio
import re
import time
from InfPacket import InfPacket
from DrvCommands import DrvCommands
import DomeControl
from setup_logger import logger
async def main(loop):
# Connect to the bar code reader.
tickReader, _ = await serial_asyncio.open_serial_connection(
url='/dev/domeaz', baudrate=9600)
# Connect to the nuc.
driverReader, driverWriter = await serial_asyncio.open_serial_connection(
url='/dev/nuc', baudrate=9600)
info = InfPacket()
drvc = DrvCommands()
print('Readers, Writer, Created')
recTick = recvTick(tickReader, info, drvc)
recComm = recvComm(driverReader, driverWriter, info, drvc)
await asyncio.wait([recTick, recComm])
async def recvTick(r, info, drvc):
checking = ""
charCount = 0
msg = ""
while True:
oneByte = await r.readexactly(1)
checking = oneByte.decode('ascii')
# print("recvTick: " + checking)
if (checking != "\r"):
msg = msg + checking
charCount = charCount + 1
else:
msg = ""
charCount = 0
if (charCount == 3):
# print("recvTick: " + msg)
logger.debug('recvTick: ' + msg)
string = "abcd"
try:
info.setInf("ADAZ", int(msg))
except ValueError:
logger.debug('recvTick: Bad Azimuth')
msg = ""
charCount = 0
async def recvComm(r, w, info, drvc):
while True:
msg = await r.readexactly(4)
print(msg)
msgascii = msg.decode('ascii')
if ("ST" in msgascii): # The STOP command has a "\n" after it
msg = await r.readexactly(1) # Skip this character.
print("recvComm: message received: " + msgascii)
await drvc.command_to_function(msgascii, w, info)
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
loop.close()