3434
3535import client_async
3636
37- import pymodbus .diag_message as req_diag
38- import pymodbus .mei_message as req_mei
39- import pymodbus .other_message as req_other
40- from pymodbus .exceptions import ModbusException
4137
42-
43- logging .basicConfig ()
4438_logger = logging .getLogger (__file__ )
4539_logger .setLevel ("DEBUG" )
4640
@@ -56,14 +50,14 @@ async def async_template_call(client):
5650 """Show complete modbus call, async version."""
5751 try :
5852 rr = await client .read_coils (1 , 1 , slave = SLAVE )
59- except ModbusException as exc :
53+ except client_async . ModbusException as exc :
6054 txt = f"ERROR: exception in pymodbus { exc } "
6155 _logger .error (txt )
6256 raise exc
6357 if rr .isError ():
6458 txt = "ERROR: pymodbus returned an error!"
6559 _logger .error (txt )
66- raise ModbusException (txt )
60+ raise client_async . ModbusException (txt )
6761
6862 # Validate data
6963 txt = f"### Template coils response: { rr .bits !s} "
@@ -160,24 +154,24 @@ async def async_handle_input_registers(client):
160154async def async_execute_information_requests (client ):
161155 """Execute extended information requests."""
162156 _logger .info ("### Running information requests." )
163- rr = await client .execute ( req_mei . ReadDeviceInformationRequest ( slave = SLAVE ) )
157+ rr = await client .read_device_information ( slave = SLAVE )
164158 assert not rr .isError () # test that call was OK
165159 assert rr .information [0 ] == b"Pymodbus"
166160
167- rr = await client .execute ( req_other . ReportSlaveIdRequest ( slave = SLAVE ) )
161+ rr = await client .report_slave_id ( slave = SLAVE )
168162 assert not rr .isError () # test that call was OK
169- # assert rr.status
163+ # assert not rr.status
170164
171- rr = await client .execute ( req_other . ReadExceptionStatusRequest ( slave = SLAVE ) )
165+ rr = await client .read_exception_status ( slave = SLAVE )
172166 assert not rr .isError () # test that call was OK
173167 # assert not rr.status
174168
175- rr = await client .execute ( req_other . GetCommEventCounterRequest ( slave = SLAVE ) )
169+ rr = await client .diag_get_comm_event_counter ( slave = SLAVE )
176170 assert not rr .isError () # test that call was OK
177171 # assert rr.status
178172 # assert not rr.count
179173
180- rr = await client .execute ( req_other . GetCommEventLogRequest ( slave = SLAVE ) )
174+ rr = await client .diag_get_comm_event_log ( slave = SLAVE )
181175 assert not rr .isError () # test that call was OK
182176 # assert rr.status
183177 # assert not (rr.event_count + rr.message_count + len(rr.events))
@@ -187,32 +181,27 @@ async def async_execute_diagnostic_requests(client):
187181 """Execute extended diagnostic requests."""
188182 _logger .info ("### Running diagnostic requests." )
189183 message = b"OK"
190- rr = await client .execute (
191- req_diag .ReturnQueryDataRequest (message = message , slave = SLAVE )
192- )
184+ rr = await client .diag_query_data (msg = message , slave = SLAVE )
193185 assert not rr .isError () # test that call was OK
194186 assert rr .message == message
195187
196- await client .execute (req_diag .RestartCommunicationsOptionRequest (slave = SLAVE ))
197- await client .execute (req_diag .ReturnDiagnosticRegisterRequest (slave = SLAVE ))
198- await client .execute (req_diag .ChangeAsciiInputDelimiterRequest (slave = SLAVE ))
199-
200- # NOT WORKING: _check_call(await client.execute(req_diag.ForceListenOnlyModeRequest(slave=SLAVE)))
201- # does not send a response
202-
203- await client .execute (req_diag .ClearCountersRequest ())
204- await client .execute (req_diag .ReturnBusCommunicationErrorCountRequest (slave = SLAVE ))
205- await client .execute (req_diag .ReturnBusExceptionErrorCountRequest (slave = SLAVE ))
206- await client .execute (req_diag .ReturnSlaveMessageCountRequest (slave = SLAVE ))
207- await client .execute (req_diag .ReturnSlaveNoResponseCountRequest (slave = SLAVE ))
208- await client .execute (req_diag .ReturnSlaveNAKCountRequest (slave = SLAVE ))
209- await client .execute (req_diag .ReturnSlaveBusyCountRequest (slave = SLAVE ))
210- await client .execute (
211- req_diag .ReturnSlaveBusCharacterOverrunCountRequest (slave = SLAVE )
212- )
213- await client .execute (req_diag .ReturnIopOverrunCountRequest (slave = SLAVE ))
214- await client .execute (req_diag .ClearOverrunCountRequest (slave = SLAVE ))
215- # NOT WORKING _check_call(await client.execute(req_diag.GetClearModbusPlusRequest(slave=SLAVE)))
188+ await client .diag_restart_communication (True , slave = SLAVE )
189+ await client .diag_read_diagnostic_register (slave = SLAVE )
190+ await client .diag_change_ascii_input_delimeter (slave = SLAVE )
191+
192+ # NOT WORKING: await client.diag_force_listen_only(slave=SLAVE)
193+
194+ await client .diag_clear_counters ()
195+ await client .diag_read_bus_comm_error_count (slave = SLAVE )
196+ await client .diag_read_bus_exception_error_count (slave = SLAVE )
197+ await client .diag_read_slave_message_count (slave = SLAVE )
198+ await client .diag_read_slave_no_response_count (slave = SLAVE )
199+ await client .diag_read_slave_nak_count (slave = SLAVE )
200+ await client .diag_read_slave_busy_count (slave = SLAVE )
201+ await client .diag_read_bus_char_overrun_count (slave = SLAVE )
202+ await client .diag_read_iop_overrun_count (slave = SLAVE )
203+ await client .diag_clear_overrun_counter (slave = SLAVE )
204+ # NOT WORKING await client.diag_getclear_modbus_response(slave=SLAVE)
216205
217206
218207# ------------------------
0 commit comments