From 1c7e252ce9d9236934931482e615366d7999de25 Mon Sep 17 00:00:00 2001 From: rsoyding Date: Sat, 27 Apr 2024 18:28:49 +0200 Subject: [PATCH] Make interface optional. Correct the documentation --- README.md | 8 ++++---- README.rst | 8 ++++---- src/caroa04/caroa04.py | 3 ++- tests/test_caroa04.py | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 346a9fb..7ffebf8 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ You can instantiate a CaroA04 object and start it to communicate with the device from caroa04 import CaroA04 caro = CaroA04() -caro.start(0xE0, 'pcan', 250000, 'PCAN_USBBUS1') # start communication +caro.start(0xE0, 'pcan', 250000, 'PCAN_USBBUS1') # start communication with device node ID 0xE0 caro.do1.phys = True # set do1 state to True print(caro.do1.phys) # read do1 state @@ -40,7 +40,7 @@ caro.bitrate.phys = 500000 # set different baudrate (will require device power print(caro.node_id.phys) # read current address code caro.node_id.phys = 0xE1 # set address code (will require device power cycle) -caro.shutdown() # free the bus +caro.stop() # free the bus ``` In order to share the bus with other participants, you can assign the bus attribute of the CaroA04 object before starting it. @@ -58,8 +58,8 @@ caro = CaroA04() caro.bus = nw.bus # use the bus already started by canopen nw.notifier.add_listener(caro.listener) # add listener so that we can receive messages -caro.start(0xE0, 'pcan') # start communication -caro.shutdown() # free the bus +caro.start(0xE0) # start communication with node ID 0xE0 +caro.stop() # free the bus ``` ## Features diff --git a/README.rst b/README.rst index 5f09c35..21bfa32 100644 --- a/README.rst +++ b/README.rst @@ -46,7 +46,7 @@ You can instantiate a CaroA04 object and start it to communicate with the device from caroa04 import CaroA04 caro = CaroA04() - caro.start(0xE0, 'pcan', 250000, 'PCAN_USBBUS1') # start communication + caro.start(0xE0, 'pcan', 250000, 'PCAN_USBBUS1') # start communication with device node ID 0xE0 caro.do1.phys = True # set do1 state to True print(caro.do1.phys) # read do1 state @@ -58,7 +58,7 @@ You can instantiate a CaroA04 object and start it to communicate with the device print(caro.node_id.phys) # read current address code caro.node_id.phys = 0xE1 # set address code (will require device power cycle) - caro.shutdown() # free the bus + caro.stop() # free the bus .. @@ -78,8 +78,8 @@ You should simply then add CaroA04's listener to the existing bus' notifier. caro.bus = nw.bus # use the bus already started by canopen nw.notifier.add_listener(caro.listener) # add listener so that we can receive messages - caro.start(0xE0, 'pcan') # start communication - caro.shutdown() # free the bus + caro.start(0xE0) # start communication with node ID 0xE0 + caro.stop() # free the bus .. diff --git a/src/caroa04/caroa04.py b/src/caroa04/caroa04.py index 1bcb9cf..a6832a1 100644 --- a/src/caroa04/caroa04.py +++ b/src/caroa04/caroa04.py @@ -105,7 +105,7 @@ def __init__(self): self.node_id ) - def start(self, node_id, interface, bitrate=None, channel=None): + def start(self, node_id, interface=None, bitrate=None, channel=None): """ Start the communication. :param node_id: node ID (or address code) of the device @@ -163,3 +163,4 @@ def stop(self): caro.do1.phys = True print(caro.do1.phys) caro.do1.phys = False + caro.stop() diff --git a/tests/test_caroa04.py b/tests/test_caroa04.py index 483eee8..2f402dd 100644 --- a/tests/test_caroa04.py +++ b/tests/test_caroa04.py @@ -85,7 +85,7 @@ def stop(self): self.bus = None -class TestVirtualCanIoExp1: +class TestVirtualCaroA04: @pytest.fixture(scope="class") def caro(self): return CaroA04()