Artifact Content
Not logged in

Artifact dfb81d0a3824ec7072dea5e25b22121637cec361:

Wiki page [modbus] by chw 2020-11-05 14:56:19.
D 2020-11-05T14:56:19.614
L modbus
P 138d161dd978a10d2796b17b76bf8ba7909ad786
U chw
W 5439
<h2>modbus command</h2>

<h3>Name</h3>

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

<h3>Synopsis</h3>

<tt>package require Tcl 8.6</tt><br>
<tt>package require modbus</tt><br>
<tt>modbus::new <i>cmd host service</i></tt><br>
<tt>modbus::new <i>cmd serial baud parity data stop ?slave_addr?</i></tt><br>
<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 <i>chan</i></tt><br>
<tt><i>cmd</i> response_timeout <i>?ms?</i></tt><br>
<tt><i>cmd</i> serial_mode <i>?mode?</i></tt><br>
<tt><i>cmd</i> read_bits <i>addr ?number?</i></tt><br>
<tt><i>cmd</i> read_input_bits <i>addr ?number?</i></tt><br>
<tt><i>cmd</i> read_registers <i>addr ?number?</i></tt><br>
<tt><i>cmd</i> read_input_registers <i>addr ?number?</i></tt><br>
<tt><i>cmd</i> write_bit <i>addr value</i></tt><br>
<tt><i>cmd</i> write_register <i>addr value</i></tt><br>
<tt><i>cmd</i> write_bits <i>addr value ...</i></tt><br>
<tt><i>cmd</i> write_registers <i>addr value ...</i></tt><br>
<tt><i>cmd</i> set_slave <i>slave_addr</i></tt><br>

<h3>Description</h3>

This package provides a Tcl interface to libmodbus (see <a href="http://libmodbus.org">http://libmodus.org</a>) using Ffidl and TclOO.

<h3>Commands</h3>

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

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

<tt>modbus::new <i>cmd serial baud parity data stop ?slave_addr?</i></tt>

    Creates a new command <tt><i>cmd</i></tt> which implements a Modbus-RTU connection object on the serial line <tt><i>serial</i></tt> with parameters <tt><i>baud</i></tt> rate, <tt><i>parity</i></tt> (N=none,  O=odd, E=even), <tt><i>data</i></tt> bits, and <tt><i>stop</i></tt> bits. The optional parameter <tt><i>slave_addr</i></tt> 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></tt>.

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

    Destroys the connection object <tt><i>cmd</i></tt>, releases resources and closes communications links.

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

    Connects the connection object <tt><i>cmd</i></tt> 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></tt>.

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

    On POSIX platforms, this method duplicates the operating system handle of the Tcl channel <tt><i>chan</i></tt> and wraps it into the <tt><i>cmd</i></tt> 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 <tt><i>cmd</i></tt> to succeed. On Windows platforms, this method is not supported.

<tt><i>cmd</i> response_time <i>?ms?</i></tt>

     Queries or sets the response timeout on the connection object <tt><i>cmd</i></tt>. The timeout is specified in milliseconds.

<tt><i>cmd</i> serial_mode <i>?mode?</i></tt>

     Queries or sets RS-232 or RS-485 mode on the Modbus-RTU connection  object  <tt><i>cmd</i></tt>. For RS-232 mode must be 0, for RS-485 it must be 1.

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

     Reads <tt><i>number</i></tt> coil status bits starting with address <tt><i>addr</i></tt> from the connection object <tt><i>cmd</i></tt>. Number defaults to one.

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

     Reads <tt><i>number</i></tt> input status bits starting with address <tt><i>addr</i></tt> from the connection object <tt><i>cmd</i></tt>. Number defaults to one.

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

     Reads <tt><i>number</i></tt> holding registers starting with address <tt><i>addr</i></tt> from the connection object <tt><i>cmd</i></tt>. Number defaults to one.

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

     Reads <tt><i>number</i></tt> input registers starting with address <tt><i>addr</i></tt> from the connection object <tt><i>cmd</i></tt>. Number defaults to one.

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

     Writes <tt><i>value</i></tt> into the coil status bit with address <tt><i>addr</i></tt> on the connection object <tt><i>cmd</i></tt>.

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

     Writes <tt><i>value</i></tt> into the holding register with address <tt><i>addr</i></tt> on the connection object <tt><i>cmd</i></tt>.

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

     Writes one ore more values into the coil status bits starting with address <tt><i>addr</i></tt> on the connection object <tt><i>cmd</i></tt>.

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

     Writes one ore more values into the holding registers starting with address <tt><i>addr</i></tt> on the connection object <tt><i>cmd</i></tt>.

<tt><i>cmd</i> set_slave <i>?slave_addr?</i></tt>

     Sets the slave address for Modbus-RTU on the connection object <tt><i>cmd</i></tt> to <tt><i>slave_addr</i></tt>.

Z bee5257bdfdce854d02724bf94e959c6