diff --git a/pycoax/coax/protocol.py b/pycoax/coax/protocol.py index 4b40444..3fb32de 100644 --- a/pycoax/coax/protocol.py +++ b/pycoax/coax/protocol.py @@ -213,9 +213,11 @@ def read_address_counter_lo(interface, **kwargs): return _execute_read_command(interface, command_word, **kwargs)[0] -def read_data(interface): +def read_data(interface, **kwargs): """Execute a READ_DATA command.""" - raise NotImplementedError + command_word = _pack_command_word(Command.READ_DATA) + + return _execute_read_command(interface, command_word, **kwargs) def read_multiple(interface): """Execute a READ_MULTIPLE command.""" diff --git a/pycoax/examples/09_read_data.py b/pycoax/examples/09_read_data.py new file mode 100755 index 0000000..e77f8d5 --- /dev/null +++ b/pycoax/examples/09_read_data.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +import sys +import time +from serial import Serial + +sys.path.append('..') + +from coax import Interface1, read_address_counter_hi, read_address_counter_lo, read_data, load_address_counter_hi, load_address_counter_lo, write_data + +print('Opening serial port...') + +with Serial('/dev/ttyUSB0', 115200) as serial: + print('Sleeping to allow interface time to wake up...') + + time.sleep(3) + + interface = Interface1(serial) + + print('Resetting interface...') + + version = interface.reset() + + print(f'Firmware version is {version}') + + load_address_counter_hi(interface, 0) + load_address_counter_lo(interface, 80) + write_data(interface, bytes.fromhex('a7 84 8b 8b 8e 33 00 96 8e 91 8b 83 19')) + + load_address_counter_hi(interface, 0) + load_address_counter_lo(interface, 81) + + print('READ_DATA...') + + print(read_data(interface)) + + hi = read_address_counter_hi(interface) + lo = read_address_counter_lo(interface) + + print(f'hi = {hi}, lo = {lo}')