pymodbus.repl package

Pymodbus REPL Module.

Copyright (c) 2018 Riptide IO, Inc. All Rights Reserved.

Submodules

pymodbus.repl.client module

Modbus Clients to be used with REPL.

Copyright (c) 2018 Riptide IO, Inc. All Rights Reserved.

class pymodbus.repl.client.ExtendedRequestSupport

Bases: object

change_ascii_input_delimiter(data=0, **kwargs)

Diagnostic sub command, Change message delimiter for future requests.

Parameters:
  • data – New delimiter character
  • unit – The slave unit this request is targeting
Returns:

clear_counters(data=0, **kwargs)

Diagnostic sub command, Clear all counters and diag registers.

Parameters:
  • data – Data field (0x0000)
  • unit – The slave unit this request is targeting
Returns:

clear_overrun_count(data=0, **kwargs)

Diagnostic sub command, Clear over run counter.

Parameters:
  • data – Data field (0x0000)
  • unit – The slave unit this request is targeting
Returns:

force_listen_only_mode(data=0, **kwargs)

Diagnostic sub command, Forces the addressed remote device to its Listen Only Mode.

Parameters:
  • data – Data field (0x0000)
  • unit – The slave unit this request is targeting
Returns:

get_clear_modbus_plus(data=0, **kwargs)

Diagnostic sub command, Get or clear stats of remote modbus plus device.

Parameters:
  • data – Data field (0x0000)
  • unit – The slave unit this request is targeting
Returns:

get_com_event_counter(**kwargs)

Read status word and an event count from the remote device’s communication event counter.

Parameters:unit – The slave unit this request is targeting
Returns:
get_com_event_log(**kwargs)

Read status word, event count, message count, and a field of event bytes from the remote device.

Parameters:unit – The slave unit this request is targeting
Returns:
mask_write_register(address=0, and_mask=65535, or_mask=0, **kwargs)

Mask content of holding register at address with and_mask and or_mask.

Parameters:
  • address – Reference address of register
  • and_mask – And Mask
  • or_mask – OR Mask
  • unit – The slave unit this request is targeting
Returns:

read_coils(address, count=1, **kwargs)

Reads count coils from a given slave starting at address.

Parameters:
  • address – The starting address to read from
  • count – The number of coils to read
  • unit – The slave unit this request is targeting
Returns:

List of register values

read_device_information(read_code=None, object_id=0, **kwargs)

Read the identification and additional information of remote slave.

Parameters:
  • read_code – Read Device ID code (0x01/0x02/0x03/0x04)
  • object_id – Identification of the first object to obtain.
  • unit – The slave unit this request is targeting
Returns:

read_discrete_inputs(address, count=1, **kwargs)

Reads count number of discrete inputs starting at offset address.

Parameters:
  • address – The starting address to read from
  • count – The number of coils to read
  • unit – The slave unit this request is targeting
Returns:

List of bits

read_exception_status(**kwargs)
Read the contents of eight Exception Status outputs in a remote device.
Parameters:unit – The slave unit this request is targeting
Returns:
read_holding_registers(address, count=1, **kwargs)

Read count number of holding registers starting at address.

Parameters:
  • address – starting register offset to read from
  • count – Number of registers to read
  • unit – The slave unit this request is targeting
Returns:

read_input_registers(address, count=1, **kwargs)

Read count number of input registers starting at address.

Parameters:
  • address – starting register offset to read from to
  • count – Number of registers to read
  • unit – The slave unit this request is targeting
Returns:

readwrite_registers(read_address, read_count, write_address, write_registers, **kwargs)

Read read_count number of holding registers starting at read_address and write write_registers starting at write_address.

Parameters:
  • read_address – register offset to read from
  • read_count – Number of registers to read
  • write_address – register offset to write to
  • write_registers – List of register values to write (comma seperated)
  • unit – The slave unit this request is targeting
Returns:

report_slave_id(**kwargs)

Report information about remote slave ID.

Parameters:unit – The slave unit this request is targeting
Returns:
restart_comm_option(toggle=False, **kwargs)

Diagnostic sub command, initialize and restart remote devices serial interface and clear all of its communications event counters .

Parameters:
  • toggle – Toggle Status [ON(0xff00)/OFF(0x0000]
  • unit – The slave unit this request is targeting
Returns:

return_bus_com_error_count(data=0, **kwargs)

Diagnostic sub command, Return count of CRC errors received by remote slave.

Parameters:
  • data – Data field (0x0000)
  • unit – The slave unit this request is targeting
Returns:

return_bus_exception_error_count(data=0, **kwargs)

Diagnostic sub command, Return count of Modbus exceptions returned by remote slave.

Parameters:
  • data – Data field (0x0000)
  • unit – The slave unit this request is targeting
Returns:

return_bus_message_count(data=0, **kwargs)

Diagnostic sub command, Return count of message detected on bus by remote slave.

Parameters:
  • data – Data field (0x0000)
  • unit – The slave unit this request is targeting
Returns:

return_diagnostic_register(data=0, **kwargs)

Diagnostic sub command, Read 16-bit diagnostic register.

Parameters:
  • data – Data field (0x0000)
  • unit – The slave unit this request is targeting
Returns:

return_iop_overrun_count(data=0, **kwargs)

Diagnostic sub command, Return count of iop overrun errors by remote slave.

Parameters:
  • data – Data field (0x0000)
  • unit – The slave unit this request is targeting
Returns:

return_query_data(message=0, **kwargs)

Diagnostic sub command , Loop back data sent in response.

Parameters:
  • message – Message to be looped back
  • unit – The slave unit this request is targeting
Returns:

return_slave_bus_char_overrun_count(data=0, **kwargs)

Diagnostic sub command, Return count of messages not handled by remote slave due to character overrun condition.

Parameters:
  • data – Data field (0x0000)
  • unit – The slave unit this request is targeting
Returns:

return_slave_busy_count(data=0, **kwargs)

Diagnostic sub command, Return count of server busy exceptions sent by remote slave.

Parameters:
  • data – Data field (0x0000)
  • unit – The slave unit this request is targeting
Returns:

return_slave_message_count(data=0, **kwargs)

Diagnostic sub command, Return count of messages addressed to remote slave.

Parameters:
  • data – Data field (0x0000)
  • unit – The slave unit this request is targeting
Returns:

return_slave_no_ack_count(data=0, **kwargs)

Diagnostic sub command, Return count of NO ACK exceptions sent by remote slave.

Parameters:
  • data – Data field (0x0000)
  • unit – The slave unit this request is targeting
Returns:

return_slave_no_response_count(data=0, **kwargs)

Diagnostic sub command, Return count of No responses by remote slave.

Parameters:
  • data – Data field (0x0000)
  • unit – The slave unit this request is targeting
Returns:

write_coil(address, value, **kwargs)

Write value to coil at address.

Parameters:
  • address – coil offset to write to
  • value – bit value to write
  • unit – The slave unit this request is targeting
Returns:

write_coils(address, values, **kwargs)

Write value to coil at address.

Parameters:
  • address – coil offset to write to
  • value – list of bit values to write (comma seperated)
  • unit – The slave unit this request is targeting
Returns:

write_register(address, value, **kwargs)

Write value to register at address.

Parameters:
  • address – register offset to write to
  • value – register value to write
  • unit – The slave unit this request is targeting
Returns:

write_registers(address, values, **kwargs)

Write list of values to registers starting at address.

Parameters:
  • address – register offset to write to
  • value – list of register value to write (comma seperated)
  • unit – The slave unit this request is targeting
Returns:

class pymodbus.repl.client.ModbusSerialClient(method, **kwargs)

Bases: pymodbus.repl.client.ExtendedRequestSupport, pymodbus.client.sync.ModbusSerialClient

get_baudrate()

Serial Port baudrate.

Returns:Current baudrate
get_bytesize()

Number of data bits.

Returns:Current bytesize
get_parity()

Enable Parity Checking.

Returns:Current parity setting
get_port()

Serial Port.

Returns:Current Serial port
get_serial_settings()

Gets Current Serial port settings.

Returns:Current Serial settings as dict.
get_stopbits()

Number of stop bits.

Returns:Current Stop bits
get_timeout()

Serial Port Read timeout.

Returns:Current read imeout.
set_baudrate(value)

Baudrate setter.

Parameters:value – <supported baudrate>
set_bytesize(value)

Byte size setter.

Parameters:value – Possible values (5, 6, 7, 8)
set_parity(value)

Parity Setter.

Parameters:value – Possible values (‘N’, ‘E’, ‘O’, ‘M’, ‘S’)
set_port(value)

Serial Port setter.

Parameters:value – New port
set_stopbits(value)

Stop bit setter.

Parameters:value – Possible values (1, 1.5, 2)
set_timeout(value)

Read timeout setter.

Parameters:value – Read Timeout in seconds
class pymodbus.repl.client.ModbusTcpClient(**kwargs)

Bases: pymodbus.repl.client.ExtendedRequestSupport, pymodbus.client.sync.ModbusTcpClient

pymodbus.repl.completer module

Command Completion for pymodbus REPL.

Copyright (c) 2018 Riptide IO, Inc. All Rights Reserved.

class pymodbus.repl.completer.CmdCompleter(client, commands=None, ignore_case=True)

Bases: prompt_toolkit.completion.base.Completer

Completer for Pymodbus REPL.

arg_completions(words, word_before_cursor)

Generates arguments completions based on the input.

Parameters:
  • words – The input text broken into word tokens.
  • word_before_cursor – The current word before the cursor, which might be one or more blank spaces.
Returns:

A list of completions.

command_names
commands
completing_arg(words, word_before_cursor)

Determine if we are currently completing an argument.

Parameters:
  • words – The input text broken into word tokens.
  • word_before_cursor – The current word before the cursor, which might be one or more blank spaces.
Returns:

Specifies whether we are currently completing an arg.

completing_command(words, word_before_cursor)

Determine if we are dealing with supported command.

Parameters:
  • words – Input text broken in to word tokens.
  • word_before_cursor – The current word before the cursor, which might be one or more blank spaces.
Returns:

get_completions(document, complete_event)

Get completions for the current scope.

Parameters:
  • document – An instance of prompt_toolkit.Document.
  • complete_event – (Unused).
Returns:

Yields an instance of prompt_toolkit.completion.Completion.

word_matches(word, word_before_cursor)

Match the word and word before cursor

Parameters:
  • words – The input text broken into word tokens.
  • word_before_cursor – The current word before the cursor, which might be one or more blank spaces.
Returns:

True if matched.

pymodbus.repl.helper module

Helper Module for REPL actions.

Copyright (c) 2018 Riptide IO, Inc. All Rights Reserved.

class pymodbus.repl.helper.Command(name, signature, doc, unit=False)

Bases: object

Class representing Commands to be consumed by Completer.

create_completion()

Create command completion meta data.

Returns:
get_completion()

Gets a list of completions.

Returns:
get_meta(cmd)

Get Meta info of a given command.

Parameters:cmd – Name of command.
Returns:Dict containing meta info.
class pymodbus.repl.helper.Result(result)

Bases: object

Represent result command.

data = None
decode(formatters, byte_order='big', word_order='big')

Decode the register response to known formatters.

Parameters:
  • formatters – int8/16/32/64, uint8/16/32/64, float32/64
  • byte_order – little/big
  • word_order – little/big
Returns:

Decoded Value

function_code = None
print_result(data=None)

Prettu print result object.

Parameters:data – Data to be printed.
Returns:
raw()

Return raw result dict.

Returns:
pymodbus.repl.helper.get_commands(client)

Helper method to retrieve all required methods and attributes of a client object and convert it to commands.

Parameters:client – Modbus Client object.
Returns:

pymodbus.repl.main module

Pymodbus REPL Entry point.

Copyright (c) 2018 Riptide IO, Inc. All Rights Reserved.

class pymodbus.repl.main.CaseInsenstiveChoice(choices, case_sensitive=True)

Bases: click.types.Choice

Case Insensitive choice for click commands and options

convert(value, param, ctx)

Convert args to uppercase for evaluation.

class pymodbus.repl.main.NumericChoice(choices, typ)

Bases: click.types.Choice

Numeric choice for click arguments and options.

convert(value, param, ctx)
pymodbus.repl.main.bottom_toolbar()

Console toolbar. :return:

pymodbus.repl.main.cli(client)