some 1w changes

This commit is contained in:
2018-02-04 20:13:48 +01:00
parent 13a9d598fd
commit 9e72263af3
2 changed files with 10 additions and 15 deletions
+7 -11
View File
@@ -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) """
+3 -4
View File
@@ -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: