From 9e72263af3a9fbf63bb6da2e51c798f27051312f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 4 Feb 2018 20:13:48 +0100 Subject: [PATCH] some 1w changes --- gex/units/OneWire.py | 18 +++++++----------- main.py | 7 +++---- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/gex/units/OneWire.py b/gex/units/OneWire.py index 6b44b69..3c57e3d 100644 --- a/gex/units/OneWire.py +++ b/gex/units/OneWire.py @@ -40,28 +40,24 @@ class OneWire(gex.Unit): return devices - def query(self, request, rcount, addr=None, as_array=False): + def query(self, request, rcount, addr=0, verify=True, as_array=False): """ Query a device """ pb = gex.PayloadBuilder() - if addr is not None: - pb.u64(addr) - + pb.u64(addr) pb.u16(rcount) - + pb.bool(verify) pb.blob(request) - resp = self._query(11 if addr is None else 13, pb.close()) + resp = self._query(11, pb.close()) return resp.data if not as_array else list(resp.data) - def write(self, payload, addr=None, confirm=True): + def write(self, payload, addr=0, confirm=True): """ Write to a device """ pb = gex.PayloadBuilder() - if addr is not None: - pb.u64(addr) - + pb.u64(addr) pb.blob(payload) - self._send(10 if addr is None else 12, pb.close(), confirm=confirm) + self._send(10, pb.close(), confirm=confirm) def wait_ready(self): """ Wait for DS18x20 to complete measurement (or other chip using the same polling mechanism) """ diff --git a/main.py b/main.py index 8dcf8f5..ef49dad 100644 --- a/main.py +++ b/main.py @@ -13,9 +13,8 @@ with gex.Client(transport) as client: client.ini_write(s) # search the bus - if False: + if True: ow = gex.OneWire(client, 'ow') - print("Presence: ", ow.test_presence()) print("Devices:", ow.search()) # search the bus for alarm @@ -25,11 +24,11 @@ with gex.Client(transport) as client: print("Devices w alarm:", ow.search(alarm=True)) # simple 1w check - if True: + if False: ow = gex.OneWire(client, 'ow') print("Presence: ", ow.test_presence()) print("ROM: 0x%016x" % ow.read_address()) - print("Scratch:", ow.query([0xBE], 9, as_array=True)) + print("Scratch:", ow.query([0xBE], rcount=9, addr=0x7100080104c77610, as_array=True)) # testing ds1820 temp meas without polling if False: