From cf03c995dbc96bfc8a494fd8beb0a97145852f82 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 19 Feb 2025 17:21:23 +0100 Subject: [PATCH] Tests of busterminal configuration extended to function calls --- tests/test_terminals.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_terminals.py b/tests/test_terminals.py index 6c2ce38..89d00c8 100644 --- a/tests/test_terminals.py +++ b/tests/test_terminals.py @@ -39,6 +39,30 @@ def test_terminal_plausib(): assert o.parameters.get('output_word_width', 0) > 0 +def rw_all_bus_terminals(bus_cupler: pyhoff.BusCoupler): + for bt in bus_cupler.bus_terminals: + if isinstance(bt, AnalogOutputTerminal): + for channel in range(1, bt.parameters.get('output_word_width', 0) + 1): + bt.set_normalized(channel, 0) + bt.set_normalized(channel, 1) + bt.set_normalized(channel, 2) + + if isinstance(bt, AnalogInputTerminal): + for channel in range(1, bt.parameters.get('input_word_width', 0) + 1): + assert bt.read_channel_word(channel, 1337) == 1337 + assert bt.read_channel_word(channel, 1337) == 1337 + assert bt.read_channel_word(channel, 1337) == 1337 + + if isinstance(bt, DigitalOutputTerminal): + for channel in range(1, bt.parameters.get('output_bit_width', 0) + 1): + assert not bt.write_coil(channel, True) + assert not bt.write_coil(channel, False) + + if isinstance(bt, DigitalInputTerminal): + for channel in range(1, bt.parameters.get('input_bit_width', 0) + 1): + assert bt.read_input(channel) is None + + def test_terminal_setup(): """ Test if all implemented BusTerminal classes in devices can @@ -55,7 +79,16 @@ def test_terminal_setup(): print(n) terminal_classes.append(o) + # Beckhoff bus_cupler = devices.BK9050('localhost', 11255, terminal_classes, timeout=0.001) assert len(terminal_classes) == len(bus_cupler.bus_terminals) assert bus_cupler.get_error() == 'connection failed', bus_cupler.get_error() + rw_all_bus_terminals(bus_cupler) + + # Wago + bus_cupler = devices.WAGO_750_352('localhost', 11255, terminal_classes, timeout=0.001) + + assert len(terminal_classes) == len(bus_cupler.bus_terminals) + assert bus_cupler.get_error() == 'connection failed', bus_cupler.get_error() + rw_all_bus_terminals(bus_cupler)