summaryrefslogtreecommitdiff
path: root/usv_driver.py
diff options
context:
space:
mode:
authorMarc Lasch <mlasch@mailbox.org>2017-05-01 21:32:07 +0200
committerMarc Lasch <mlasch@mailbox.org>2017-05-01 21:32:07 +0200
commitbbe8426cc28a24d083cb34bac319896c61087e51 (patch)
treeceb5fb74eb5daf161e4124b9e52280f7473d05f4 /usv_driver.py
parent112f478b2fc9f5365a5e2111cde1decfb0ceff0d (diff)
downloadusv_tools-bbe8426cc28a24d083cb34bac319896c61087e51.tar.gz
usv_tools-bbe8426cc28a24d083cb34bac319896c61087e51.zip
Deleted some old filesdevelop
Diffstat (limited to 'usv_driver.py')
-rwxr-xr-xusv_driver.py78
1 files changed, 0 insertions, 78 deletions
diff --git a/usv_driver.py b/usv_driver.py
deleted file mode 100755
index 4ff52ea..0000000
--- a/usv_driver.py
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/usr/bin/env python3
-
-import serial
-import json
-import re
-
-class Usv(object):
- def __init__(self, device, baudrate, json_file):
- self._serial_port = serial.Serial(device,
- baudrate=baudrate,
-<<<<<<< HEAD
- timeout=0.8)
-=======
- timeout=10)
->>>>>>> e3494d280fd6e2db591ea40c4365cdf18524fbdc
-
- # force a clean prompt
- #self._serial_port.write(b"\r")
- self._read_until_prompt("\r")
- #print("cleaned prompt")
- with open(json_file) as fhandle:
- self.json_params = json.load(fhandle)
-
-
- def _read_until_prompt(self, outbuf):
- # match on "\n=>"
- self._serial_port.write(outbuf.encode())
-
- inbuf = self._serial_port.read(100)
- sbuf = inbuf.decode("utf-8")
-
- #prompt = False
- #inbuf = []
- #while not prompt:
- # pending = self._serial_port.read(1)
- # if len(pending) == 0:
- # self._serial_port.write(b"\r")
- # else:
- # inbuf.append(pending)
- # print(pending)
- #if len(sbuf) > 2:
- # if sbuf[-3] == "\n" and \
- # sbuf[-2] == "=" and sbuf[-1] == ">":
- # return sbuf
- # else:
- # sbuf = self._read_until_prompt(outbuf)
-
- return sbuf
-
- def get_parameters(self):
- # [{'name': 'acvoltsin', 'index': 1},
- results = {}
-
- for parameter in self.json_params:
- outbuf = "d %s\r" % parameter['num']
- inbuf = self._read_until_prompt(outbuf)
-
- regex = parameter['regex']
- match = re.search(regex, inbuf, re.MULTILINE)
-
- if match:
- name = parameter['name']
- value = float(match.group(1))
-
- results.setdefault(name, value)
- #print("MATCH: %s: %f" % (name,value))
-
- return results
-
-
-
-if __name__ == "__main__":
- import pprint
-
- usv = Usv("/dev/ttyU0", 600, "usv_param.json")
- parameters = usv.get_parameters()
- pprint.pprint(parameters)
-