summaryrefslogtreecommitdiffstats
path: root/admin/lib
diff options
context:
space:
mode:
authorvuko <vuko@hackerspace.pl>2020-09-26 00:30:31 +0200
committervuko <vuko@hackerspace.pl>2021-05-23 15:51:23 +0200
commit7b44c0af3a63ca5982ef247c9d83254d773016a5 (patch)
tree4fb9ae7919fc3631fdef989d19b0f758666bd659 /admin/lib
parent44d194995100e02785ce1dee0e483ad9149b9a33 (diff)
downloaddoorman-serial.tar.gz
doorman-serial.tar.bz2
doorman-serial.tar.xz
doorman-serial.zip
restore serialserial
Diffstat (limited to 'admin/lib')
-rw-r--r--admin/lib/proto.py28
1 files changed, 8 insertions, 20 deletions
diff --git a/admin/lib/proto.py b/admin/lib/proto.py
index 8ceb8d8..c00c9b7 100644
--- a/admin/lib/proto.py
+++ b/admin/lib/proto.py
@@ -2,8 +2,6 @@ from time import sleep
from sys import stderr
import serial
-import socket
-import ssl
from command import Command
import options
@@ -16,30 +14,20 @@ class Proto(object):
kwa.update(options.serial)
kwa.update(kwargs)
url = url or options.url
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.settimeout(20)
- print ('wrapping..')
- ctx = ssl.create_default_context()
- self.sock = ssl.wrap_socket(sock)
- print ('connecting')
- self.sock.connect((url, 443))
- self.sock.settimeout(60)
- print ('done')
-
- self.fd = self.sock.makefile()
- #self.fd = serial.serial_for_url(url, **kwa)
+ self.fd = serial.serial_for_url(url, **kwa)
sleep(options.init_sleep)
- ##self.fd.flushInput()
- #self.fd.flushOutput()
- print >> stderr, 'Serial port ready'
+ self.fd.flushInput()
+ self.fd.flushOutput()
+ print('Serial port ready')
def send(self, command):
cmd = str(command) + '\n'
- print cmd
+ print(cmd)
for i in cmd:
- self.sock.send(i)
+ sleep(0.02)
+ self.fd.write(i)
def recv(self):
line = self.fd.readline()
- print (line)
+ print(line)
if line[0] != '$':
return self.recv()
cmd = Command.from_str(line)