|  | 
|  | 1 | +Pymodbus REPL (Read Evaluate Print Loop) | 
|  | 2 | +========================================= | 
|  | 3 | + | 
|  | 4 | +Installation | 
|  | 5 | +------------ | 
|  | 6 | + | 
|  | 7 | +Project repo `pymodbus-repl <https://github.com/pymodbus-dev/repl>`__ | 
|  | 8 | + | 
|  | 9 | +Install as pymodbus optional dependency | 
|  | 10 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 
|  | 11 | + | 
|  | 12 | +:: | 
|  | 13 | + | 
|  | 14 | +   $ pip install ".[repl]" | 
|  | 15 | + | 
|  | 16 | +Install directly from the github repo | 
|  | 17 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 
|  | 18 | + | 
|  | 19 | +:: | 
|  | 20 | + | 
|  | 21 | +   $ pip install "git+https://github.com/pymodbus-dev/repl" | 
|  | 22 | + | 
|  | 23 | +Usage Instructions | 
|  | 24 | +------------------ | 
|  | 25 | + | 
|  | 26 | +RTU and TCP are supported as of now | 
|  | 27 | + | 
|  | 28 | +:: | 
|  | 29 | + | 
|  | 30 | +   bash-3.2$ pymodbus.console | 
|  | 31 | +   Usage: pymodbus.console [OPTIONS] COMMAND [ARGS]... | 
|  | 32 | + | 
|  | 33 | +   Options: | 
|  | 34 | +     --version       Show the version and exit. | 
|  | 35 | +     --verbose       Verbose logs | 
|  | 36 | +     --support-diag  Support Diagnostic messages | 
|  | 37 | +     --help          Show this message and exit. | 
|  | 38 | + | 
|  | 39 | +   Commands: | 
|  | 40 | +     serial | 
|  | 41 | +     tcp | 
|  | 42 | + | 
|  | 43 | +TCP Options | 
|  | 44 | + | 
|  | 45 | +:: | 
|  | 46 | + | 
|  | 47 | +   bash-3.2$ pymodbus.console tcp --help | 
|  | 48 | +   Usage: pymodbus.console tcp [OPTIONS] | 
|  | 49 | + | 
|  | 50 | +   Options: | 
|  | 51 | +     --host TEXT     Modbus TCP IP | 
|  | 52 | +     --port INTEGER  Modbus TCP port | 
|  | 53 | +     --help          Show this message and exit. | 
|  | 54 | + | 
|  | 55 | + | 
|  | 56 | +SERIAL Options | 
|  | 57 | + | 
|  | 58 | +:: | 
|  | 59 | + | 
|  | 60 | +   bash-3.2$ pymodbus.console serial --help | 
|  | 61 | +   Usage: pymodbus.console serial [OPTIONS] | 
|  | 62 | + | 
|  | 63 | +   Options: | 
|  | 64 | +     --method TEXT          Modbus Serial Mode (rtu/ascii) | 
|  | 65 | +     --port TEXT            Modbus RTU port | 
|  | 66 | +     --baudrate INTEGER     Modbus RTU serial baudrate to use. | 
|  | 67 | +     --bytesize [5|6|7|8]   Modbus RTU serial Number of data bits. Possible | 
|  | 68 | +                            values: FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS. | 
|  | 69 | +     --parity [N|E|O|M|S]   Modbus RTU serial parity.  Enable parity checking. | 
|  | 70 | +                            Possible values: PARITY_NONE, PARITY_EVEN, PARITY_ODD | 
|  | 71 | +                            PARITY_MARK, PARITY_SPACE. Default to 'N' | 
|  | 72 | +     --stopbits [1|1.5|2]   Modbus RTU serial stop bits. Number of stop bits. | 
|  | 73 | +                            Possible values: STOPBITS_ONE, | 
|  | 74 | +                            STOPBITS_ONE_POINT_FIVE, STOPBITS_TWO. Default to '1' | 
|  | 75 | +     --xonxoff INTEGER      Modbus RTU serial xonxoff.  Enable software flow | 
|  | 76 | +                            control. | 
|  | 77 | +     --rtscts INTEGER       Modbus RTU serial rtscts. Enable hardware (RTS/CTS) | 
|  | 78 | +                            flow control. | 
|  | 79 | +     --dsrdtr INTEGER       Modbus RTU serial dsrdtr. Enable hardware (DSR/DTR) | 
|  | 80 | +                            flow control. | 
|  | 81 | +     --timeout FLOAT        Modbus RTU serial read timeout. | 
|  | 82 | +     --write-timeout FLOAT  Modbus RTU serial write timeout. | 
|  | 83 | +     --help                 Show this message and exit. | 
|  | 84 | + | 
|  | 85 | +To view all available commands type ``help`` | 
|  | 86 | + | 
|  | 87 | +TCP | 
|  | 88 | + | 
|  | 89 | +:: | 
|  | 90 | + | 
|  | 91 | +   $ pymodbus.console tcp --host 192.168.128.126 --port 5020 | 
|  | 92 | + | 
|  | 93 | +   > help | 
|  | 94 | +   Available commands: | 
|  | 95 | +   client.change_ascii_input_delimiter          Diagnostic sub command, Change message delimiter for future requests. | 
|  | 96 | +   client.clear_counters                        Diagnostic sub command, Clear all counters and diag registers. | 
|  | 97 | +   client.clear_overrun_count                   Diagnostic sub command, Clear over run counter. | 
|  | 98 | +   client.close                                 Closes the underlying socket connection | 
|  | 99 | +   client.connect                               Connect to the modbus tcp server | 
|  | 100 | +   client.debug_enabled                         Returns a boolean indicating if debug is enabled. | 
|  | 101 | +   client.force_listen_only_mode                Diagnostic sub command, Forces the addressed remote device to         its Listen Only Mode. | 
|  | 102 | +   client.get_clear_modbus_plus                 Diagnostic sub command, Get or clear stats of remote          modbus plus device. | 
|  | 103 | +   client.get_com_event_counter                 Read  status word and an event count from the remote device's         communication event counter. | 
|  | 104 | +   client.get_com_event_log                     Read  status word, event count, message count, and a field of event bytes from the remote device. | 
|  | 105 | +   client.host                                  Read Only! | 
|  | 106 | +   client.idle_time                             Bus Idle Time to initiate next transaction | 
|  | 107 | +   client.is_socket_open                        Check whether the underlying socket/serial is open or not. | 
|  | 108 | +   client.last_frame_end                        Read Only! | 
|  | 109 | +   client.mask_write_register                   Mask content of holding register at `address`          with `and_mask` and `or_mask`. | 
|  | 110 | +   client.port                                  Read Only! | 
|  | 111 | +   client.read_coils                            Reads `count` coils from a given slave starting at `address`. | 
|  | 112 | +   client.read_device_information               Read the identification and additional information of remote slave. | 
|  | 113 | +   client.read_discrete_inputs                  Reads `count` number of discrete inputs starting at offset `address`. | 
|  | 114 | +   client.read_exception_status                 Read the contents of eight Exception Status outputs in a remote          device. | 
|  | 115 | +   client.read_holding_registers                Read `count` number of holding registers starting at `address`. | 
|  | 116 | +   client.read_input_registers                  Read `count` number of input registers starting at `address`. | 
|  | 117 | +   client.readwrite_registers                   Read `read_count` number of holding registers starting at         `read_address`  and write `write_registers`         starting at `write_address`. | 
|  | 118 | +   client.report_slave_id                       Report information about remote slave ID. | 
|  | 119 | +   client.restart_comm_option                   Diagnostic sub command, initialize and restart remote devices serial         interface and clear all of its communications event counters . | 
|  | 120 | +   client.return_bus_com_error_count            Diagnostic sub command, Return count of CRC errors         received by remote slave. | 
|  | 121 | +   client.return_bus_exception_error_count      Diagnostic sub command, Return count of Modbus exceptions         returned by remote slave. | 
|  | 122 | +   client.return_bus_message_count              Diagnostic sub command, Return count of message detected on bus          by remote slave. | 
|  | 123 | +   client.return_diagnostic_register            Diagnostic sub command, Read 16-bit diagnostic register. | 
|  | 124 | +   client.return_iop_overrun_count              Diagnostic sub command, Return count of iop overrun errors         by remote slave. | 
|  | 125 | +   client.return_query_data                     Diagnostic sub command , Loop back data sent in response. | 
|  | 126 | +   client.return_slave_bus_char_overrun_count   Diagnostic sub command, Return count of messages not handled          by remote slave due to character overrun condition. | 
|  | 127 | +   client.return_slave_busy_count               Diagnostic sub command, Return count of server busy exceptions sent          by remote slave. | 
|  | 128 | +   client.return_slave_message_count            Diagnostic sub command, Return count of messages addressed to         remote slave. | 
|  | 129 | +   client.return_slave_no_ack_count             Diagnostic sub command, Return count of NO ACK exceptions sent          by remote slave. | 
|  | 130 | +   client.return_slave_no_response_count        Diagnostic sub command, Return count of No responses  by remote slave. | 
|  | 131 | +   client.silent_interval                       Read Only! | 
|  | 132 | +   client.state                                 Read Only! | 
|  | 133 | +   client.timeout                               Read Only! | 
|  | 134 | +   client.write_coil                            Write `value` to coil at `address`. | 
|  | 135 | +   client.write_coils                           Write `value` to coil at `address`. | 
|  | 136 | +   client.write_register                        Write `value` to register at `address`. | 
|  | 137 | +   client.write_registers                       Write list of `values` to registers starting at `address`. | 
|  | 138 | + | 
|  | 139 | +SERIAL | 
|  | 140 | + | 
|  | 141 | +:: | 
|  | 142 | + | 
|  | 143 | +   $ pymodbus.console serial --port /dev/ttyUSB0 --baudrate 19200 --timeout 2 | 
|  | 144 | +   > help | 
|  | 145 | +   Available commands: | 
|  | 146 | +   client.baudrate                              Read Only! | 
|  | 147 | +   client.bytesize                              Read Only! | 
|  | 148 | +   client.change_ascii_input_delimiter          Diagnostic sub command, Change message delimiter for future requests. | 
|  | 149 | +   client.clear_counters                        Diagnostic sub command, Clear all counters and diag registers. | 
|  | 150 | +   client.clear_overrun_count                   Diagnostic sub command, Clear over run counter. | 
|  | 151 | +   client.close                                 Closes the underlying socket connection | 
|  | 152 | +   client.connect                               Connect to the modbus serial server | 
|  | 153 | +   client.debug_enabled                         Returns a boolean indicating if debug is enabled. | 
|  | 154 | +   client.force_listen_only_mode                Diagnostic sub command, Forces the addressed remote device to         its Listen Only Mode. | 
|  | 155 | +   client.get_baudrate                          Serial Port baudrate. | 
|  | 156 | +   client.get_bytesize                          Number of data bits. | 
|  | 157 | +   client.get_clear_modbus_plus                 Diagnostic sub command, Get or clear stats of remote          modbus plus device. | 
|  | 158 | +   client.get_com_event_counter                 Read  status word and an event count from the remote device's         communication event counter. | 
|  | 159 | +   client.get_com_event_log                     Read  status word, event count, message count, and a field of event bytes from the remote device. | 
|  | 160 | +   client.get_parity                            Enable Parity Checking. | 
|  | 161 | +   client.get_port                              Serial Port. | 
|  | 162 | +   client.get_serial_settings                   Gets Current Serial port settings. | 
|  | 163 | +   client.get_stopbits                          Number of stop bits. | 
|  | 164 | +   client.get_timeout                           Serial Port Read timeout. | 
|  | 165 | +   client.idle_time                             Bus Idle Time to initiate next transaction | 
|  | 166 | +   client.inter_byte_timeout                    Read Only! | 
|  | 167 | +   client.is_socket_open                        c l i e n t . i s   s o c k e t   o p e n | 
|  | 168 | +   client.mask_write_register                   Mask content of holding register at `address`          with `and_mask` and `or_mask`. | 
|  | 169 | +   client.method                                Read Only! | 
|  | 170 | +   client.parity                                Read Only! | 
|  | 171 | +   client.port                                  Read Only! | 
|  | 172 | +   client.read_coils                            Reads `count` coils from a given slave starting at `address`. | 
|  | 173 | +   client.read_device_information               Read the identification and additional information of remote slave. | 
|  | 174 | +   client.read_discrete_inputs                  Reads `count` number of discrete inputs starting at offset `address`. | 
|  | 175 | +   client.read_exception_status                 Read the contents of eight Exception Status outputs in a remote          device. | 
|  | 176 | +   client.read_holding_registers                Read `count` number of holding registers starting at `address`. | 
|  | 177 | +   client.read_input_registers                  Read `count` number of input registers starting at `address`. | 
|  | 178 | +   client.readwrite_registers                   Read `read_count` number of holding registers starting at         `read_address`  and write `write_registers`         starting at `write_address`. | 
|  | 179 | +   client.report_slave_id                       Report information about remote slave ID. | 
|  | 180 | +   client.restart_comm_option                   Diagnostic sub command, initialize and restart remote devices serial         interface and clear all of its communications event counters . | 
|  | 181 | +   client.return_bus_com_error_count            Diagnostic sub command, Return count of CRC errors         received by remote slave. | 
|  | 182 | +   client.return_bus_exception_error_count      Diagnostic sub command, Return count of Modbus exceptions         returned by remote slave. | 
|  | 183 | +   client.return_bus_message_count              Diagnostic sub command, Return count of message detected on bus          by remote slave. | 
|  | 184 | +   client.return_diagnostic_register            Diagnostic sub command, Read 16-bit diagnostic register. | 
|  | 185 | +   client.return_iop_overrun_count              Diagnostic sub command, Return count of iop overrun errors         by remote slave. | 
|  | 186 | +   client.return_query_data                     Diagnostic sub command , Loop back data sent in response. | 
|  | 187 | +   client.return_slave_bus_char_overrun_count   Diagnostic sub command, Return count of messages not handled          by remote slave due to character overrun condition. | 
|  | 188 | +   client.return_slave_busy_count               Diagnostic sub command, Return count of server busy exceptions sent          by remote slave. | 
|  | 189 | +   client.return_slave_message_count            Diagnostic sub command, Return count of messages addressed to         remote slave. | 
|  | 190 | +   client.return_slave_no_ack_count             Diagnostic sub command, Return count of NO ACK exceptions sent          by remote slave. | 
|  | 191 | +   client.return_slave_no_response_count        Diagnostic sub command, Return count of No responses  by remote slave. | 
|  | 192 | +   client.set_baudrate                          Baudrate setter. | 
|  | 193 | +   client.set_bytesize                          Byte size setter. | 
|  | 194 | +   client.set_parity                            Parity Setter. | 
|  | 195 | +   client.set_port                              Serial Port setter. | 
|  | 196 | +   client.set_stopbits                          Stop bit setter. | 
|  | 197 | +   client.set_timeout                           Read timeout setter. | 
|  | 198 | +   client.silent_interval                       Read Only! | 
|  | 199 | +   client.state                                 Read Only! | 
|  | 200 | +   client.stopbits                              Read Only! | 
|  | 201 | +   client.timeout                               Read Only! | 
|  | 202 | +   client.write_coil                            Write `value` to coil at `address`. | 
|  | 203 | +   client.write_coils                           Write `value` to coil at `address`. | 
|  | 204 | +   client.write_register                        Write `value` to register at `address`. | 
|  | 205 | +   client.write_registers                       Write list of `values` to registers starting at `address`. | 
|  | 206 | +   result.decode                                Decode the register response to known formatters. | 
|  | 207 | +   result.raw                                   Return raw result dict. | 
|  | 208 | + | 
|  | 209 | +Every command has auto suggestion on the arguments supported, arg and | 
|  | 210 | +value are to be supplied in ``arg=val`` format. | 
|  | 211 | + | 
|  | 212 | +:: | 
|  | 213 | + | 
|  | 214 | + | 
|  | 215 | +   > client.read_holding_registers count=4 address=9 slave=1 | 
|  | 216 | +   { | 
|  | 217 | +       "registers": [ | 
|  | 218 | +           60497, | 
|  | 219 | +           47134, | 
|  | 220 | +           34091, | 
|  | 221 | +           15424 | 
|  | 222 | +       ] | 
|  | 223 | +   } | 
|  | 224 | + | 
|  | 225 | +The last result could be accessed with ``result.raw`` command | 
|  | 226 | + | 
|  | 227 | +:: | 
|  | 228 | + | 
|  | 229 | +   > result.raw | 
|  | 230 | +   { | 
|  | 231 | +       "registers": [ | 
|  | 232 | +           15626, | 
|  | 233 | +           55203, | 
|  | 234 | +           28733, | 
|  | 235 | +           18368 | 
|  | 236 | +       ] | 
|  | 237 | +   } | 
|  | 238 | + | 
|  | 239 | +For Holding and Input register reads, the decoded value could be viewed | 
|  | 240 | +with ``result.decode`` | 
|  | 241 | + | 
|  | 242 | +:: | 
|  | 243 | + | 
|  | 244 | +   > result.decode word_order=little byte_order=little formatters=float64 | 
|  | 245 | +   28.17 | 
|  | 246 | + | 
|  | 247 | +   > | 
|  | 248 | + | 
|  | 249 | +Client settings could be retrieved and altered as well. | 
|  | 250 | + | 
|  | 251 | +:: | 
|  | 252 | + | 
|  | 253 | +   > # For serial settings | 
|  | 254 | + | 
|  | 255 | +   > # Check the serial mode | 
|  | 256 | +   > client.method | 
|  | 257 | +   "rtu" | 
|  | 258 | + | 
|  | 259 | +   > client.get_serial_settings | 
|  | 260 | +   { | 
|  | 261 | +       "t1.5": 0.00171875, | 
|  | 262 | +       "baudrate": 9600, | 
|  | 263 | +       "read timeout": 0.5, | 
|  | 264 | +       "port": "/dev/ptyp0", | 
|  | 265 | +       "t3.5": 0.00401, | 
|  | 266 | +       "bytesize": 8, | 
|  | 267 | +       "parity": "N", | 
|  | 268 | +       "stopbits": 1.0 | 
|  | 269 | +   } | 
|  | 270 | +   > client.set_timeout value=1 | 
|  | 271 | +   null | 
|  | 272 | + | 
|  | 273 | +   > client.get_timeout | 
|  | 274 | +   1.0 | 
|  | 275 | + | 
|  | 276 | +   > client.get_serial_settings | 
|  | 277 | +   { | 
|  | 278 | +       "t1.5": 0.00171875, | 
|  | 279 | +       "baudrate": 9600, | 
|  | 280 | +       "read timeout": 1.0, | 
|  | 281 | +       "port": "/dev/ptyp0", | 
|  | 282 | +       "t3.5": 0.00401, | 
|  | 283 | +       "bytesize": 8, | 
|  | 284 | +       "parity": "N", | 
|  | 285 | +       "stopbits": 1.0 | 
|  | 286 | +   } | 
|  | 287 | + | 
|  | 288 | +Demo | 
|  | 289 | +---- | 
|  | 290 | + | 
|  | 291 | +.. |asciicast| image:: https://asciinema.org/a/y1xOk7lm59U1bRBE2N1pDIj2o.png | 
|  | 292 | +   :target: https://asciinema.org/a/y1xOk7lm59U1bRBE2N1pDIj2o | 
|  | 293 | +.. |asciicast2| image:: https://asciinema.org/a/edUqZN77fdjxL2toisiilJNwI.png | 
|  | 294 | +   :target: https://asciinema.org/a/edUqZN77fdjxL2toisiilJNwI | 
|  | 295 | + | 
|  | 296 | + | 
|  | 297 | +Pymodbus REPL Client | 
|  | 298 | +^^^^^^^^^^^^^^^^^^^^ | 
|  | 299 | + | 
|  | 300 | +Pymodbus REPL comes with many handy features such as payload decoder | 
|  | 301 | +to directly retrieve the values in desired format and supports all | 
|  | 302 | +the diagnostic function codes directly . | 
|  | 303 | + | 
|  | 304 | +For more info on REPL Client refer  `pymodbus repl client <https://github.com/pymodbus-dev/repl/blob/main/pymodbus/repl/client/README.rst>`__ | 
|  | 305 | + | 
|  | 306 | +.. image:: https://asciinema.org/a/y1xOk7lm59U1bRBE2N1pDIj2o.png | 
|  | 307 | +   :target: https://asciinema.org/a/y1xOk7lm59U1bRBE2N1pDIj2o | 
|  | 308 | + | 
|  | 309 | + | 
|  | 310 | +Pymodbus REPL Server | 
|  | 311 | +^^^^^^^^^^^^^^^^^^^^ | 
|  | 312 | + | 
|  | 313 | +Pymodbus also comes with a REPL server to quickly run an asynchronous server with additional capabilities out of the box like simulating errors, delay, mangled messages etc. | 
|  | 314 | + | 
|  | 315 | +For more info on REPL Server refer `pymodbus repl server <https://github.com/pymodbus-dev/repl/blob/main/pymodbus/repl/server/README.rst>`__ | 
|  | 316 | + | 
|  | 317 | +.. image:: https://img.youtube.com/vi/OutaVz0JkWg/maxresdefault.jpg | 
|  | 318 | +   :target: https://youtu.be/OutaVz0JkWg | 
0 commit comments