eepprog.py: Add list-devices command
This commit is contained in:
parent
cedb5bfe81
commit
d9a7cb401d
2 changed files with 55 additions and 22 deletions
|
|
@ -1,5 +1,5 @@
|
|||
from serial import Serial
|
||||
from typing import Optional
|
||||
from typing import Optional, Union
|
||||
|
||||
from . import Logger
|
||||
|
||||
|
|
@ -20,33 +20,49 @@ class EepromProgrammer:
|
|||
self._device_file = device
|
||||
self._baudrate = baudrate
|
||||
|
||||
# TODO
|
||||
def open(self):
|
||||
def open(self) -> None:
|
||||
"""
|
||||
Open and setup serial port.
|
||||
"""
|
||||
assert self.serial is None, 'Serial port is already opened!'
|
||||
|
||||
self.logger.debug("Setting up serial device '{}' with baudrate {}".format(self._device_file, self._baudrate))
|
||||
self.logger.debug("Opening serial device '{}' with {} bauds".format(self._device_file, self._baudrate))
|
||||
self.serial = Serial(self._device_file, self._baudrate)
|
||||
|
||||
def close(self):
|
||||
if self.serial is None:
|
||||
self.logger.debug("Serial port is already closed")
|
||||
return
|
||||
def close(self) -> None:
|
||||
"""
|
||||
Closes the serial port.
|
||||
"""
|
||||
if self.serial is not None:
|
||||
self.logger.debug("Closing serial port")
|
||||
self.serial.close()
|
||||
|
||||
self.logger.debug("Closing serial port")
|
||||
self.serial.close()
|
||||
def write(self, data: Union[bytes, bytearray]) -> int:
|
||||
"""
|
||||
Writes bytes to the serial port and writes debug log.
|
||||
"""
|
||||
self.logger.debug('Writing: {}'.format(str(data)))
|
||||
return self.serial.write(data)
|
||||
|
||||
# TODO
|
||||
def test(self):
|
||||
def test_command(self) -> None:
|
||||
# Open serial port
|
||||
if self.serial is None:
|
||||
self.open()
|
||||
|
||||
# TODO where to do this? in open() or when needed?
|
||||
self.serial.timeout = 1
|
||||
|
||||
# Write a test command
|
||||
self.logger.info("Sending 'INIT' ...")
|
||||
self.serial.write(b"INIT\n")
|
||||
self.logger.info("Sending INIT command ...")
|
||||
self.write(b'INIT BINARY\n')
|
||||
|
||||
# Just read some stuff
|
||||
self.logger.info("Read line: ", self.serial.readline(80))
|
||||
self.logger.info("Received line: ", self.serial.readline(80))
|
||||
|
||||
# Send a READ command
|
||||
self.logger.info("Sending READ command ...")
|
||||
self.write(b'READ 0000:0010\n')
|
||||
|
||||
while True:
|
||||
self.logger.info("Received line: ", self.serial.readline(80))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue