<h2>Name</h2>

<b>modbus</b> - Tcl interface to libmodbus

<h2>Synopsis</h2>

<tt>package require Tcl 8.6</tt><br>
<tt>package require modbus</tt><br>
<tt>modbus::new <i>cmd host
<tt>modbus::new <i>serial baud parity data stop
<tt><i>cmd</i> destroy</tt><br>
<tt><i>cmd</i> connect</tt><br>
<tt><i>cmd</i> close</tt><br>
<tt><i>cmd</i> setchan
<tt><i>cmd</i> response_timeout
<tt><i>cmd</i> serial_mode
<tt><i>cmd</i> read_bits <i>addr
<tt><i>cmd</i> read_input_bits <i>addr
<tt><i>cmd</i> read_registers <i>addr
<tt><i>cmd</i> read_input_registers <i>addr
<tt><i>cmd</i> write_bit <i>addr
<tt><i>cmd</i> write_register <i>addr
<tt><i>cmd</i> write_bits <i>addr value
<tt><i>cmd</i> write_registers <i>addr value
<tt><i>cmd</i> set_slave

<h2>Description</h2>

This  package provides a Tcl interface to libmodbus (see <a using Ffidl and TclOO.

<h2>Commands</h2>

<tt>modbus::new <i>cmd host

    Creates a new command which implements a Modbus-TCP  connection object to the given (IP address or hostname) and (symbolic or numeric TCP port). Further operations on  that object are carried out by invoking methods on

<tt>modbus::new <i>serial baud parity data stop

    Creates a new command which implements a Modbus-RTU connection object on the serial line with parameters rate, (N=none,  O=odd, E=even), bits, and bits. The optional parameter specifies the Modbus-RTU  slave address and defaults to zero. Further operations on that object are carried out by invoking methods on

<tt><i>cmd</i> destroy</tt>

    Destroys the connection object releases resources and closes communications links.

<tt><i>cmd</i> connect</tt>

    Connects the connection object to its peer (a TCP server for Modbus-TCP or a serial line for Modbus-RTU).

<tt><i>cmd</i> close</tt>

    Closes the connection (either the socket or the serial line) of the connection object

<tt><i>cmd</i> setchan

    On POSIX platforms, this method duplicates the operating system handle of the Tcl channel and wraps it into the connection object. The Tcl channel can be closed immediately after this operation. Depending on  the constructor, the  operating system handle must provide socket or tty semantics for further I/O methods on to succeed. On Windows platforms, this method is not supported.

<tt><i>cmd</i> response_time

     Queries or sets the response timeout on the connection object The timeout is specified in milliseconds.

<tt><i>cmd</i> serial_mode

     Queries or sets RS-232 or RS-485 mode on the Modbus-RTU connection  object  For RS-232 mode must be 0, for RS-485 it must be 1.

<tt><i>cmd</i> read_bits <i>addr

     Reads coil status bits starting with address from the connection object Number defaults to one.

<tt><i>cmd</i> read_input_bits <i>addr

     Reads input status bits starting with address from the connection object Number defaults to one.

<tt><i>cmd</i> read_registers <i>addr

     Reads holding registers starting with address from the connection object Number defaults to one.

<tt><i>cmd</i> read_input_registers <i>addr

     Reads input registers starting with address from the connection object Number defaults to one.

<tt><i>cmd</i> write_bit <i>addr

     Writes into the coil status bit with address on the connection object

<tt><i>cmd</i> write_register <i>addr

     Writes into the holding register with address on the connection object

<tt><i>cmd</i> write_bits <i>addr value

     Writes one ore more values into the coil status bits starting with address on the connection object

<tt><i>cmd</i> write_registers <i>addr value

     Writes one ore more values into the holding registers starting with address on the connection object

<tt><i>cmd</i> set_slave

     Sets the slave address for Modbus-RTU on the connection object to