-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLAUDAServer.py
More file actions
39 lines (26 loc) · 1002 Bytes
/
LAUDAServer.py
File metadata and controls
39 lines (26 loc) · 1002 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
33
34
35
36
37
38
39
import zmq
import serial
from time import sleep
class LAUDAServer():
def __init__(self, portname='/dev/ttyS0', port=5050):
self.instr = serial.Serial(portname, 9600, timeout=2)
context = zmq.Context()
self.socket = context.socket(zmq.REP)
self.socket.bind("tcp://*:%d"%port)
print("SerialServer listening at *:%d relaying to %s" % (port,portname))
def loop(self):
while True:
msg = self.socket.recv().decode("utf-8").strip()
print("Processing %s" % msg)
reply = ""
self.instr.write(str(msg+"\r\n").encode())
reply = self.instr.readline()
self.socket.send(reply)
sleep(0.5)
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-p","--port")
parser.add_option("-d","--device")
(options,args)=parser.parse_args()
myServer = LAUDAServer(port=int(options.port),portname=options.device)
myServer.loop()