devel:modbus_tcp_ip
Differences
This shows you the differences between two versions of the page.
Previous revision | |||
— | devel:modbus_tcp_ip [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Use of this connection ====== | ||
+ | **RTS2** provides connection for working with Modbus TCP/IP protocol. The advantage of this connection is that it inherits from Rts2Conn, and so can be easily integrated into Rts2 as another connection. There is a sample code how to use it: | ||
+ | |||
+ | <code c++> | ||
+ | class Zelio: | ||
+ | { | ||
+ | private: | ||
+ | HostString *host; | ||
+ | |||
+ | rts2core:: | ||
+ | |||
+ | protected: | ||
+ | virtual int processOption (int in_opt); | ||
+ | |||
+ | public: | ||
+ | Zelio (int argc, char **argv); | ||
+ | virtual ~Zelio (void); | ||
+ | virtual int init (); | ||
+ | |||
+ | virtual int info (); | ||
+ | }; | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | int | ||
+ | Zelio:: | ||
+ | { | ||
+ | switch (in_opt) | ||
+ | { | ||
+ | // process hoststring (port can be specified after :) | ||
+ | case ' | ||
+ | host = new HostString (optarg, " | ||
+ | break; | ||
+ | default: | ||
+ | return Rts2Sensor:: | ||
+ | } | ||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | |||
+ | Zelio:: | ||
+ | :Rts2Sensor (argc, argv) | ||
+ | { | ||
+ | host = NULL; | ||
+ | |||
+ | addOption (' | ||
+ | } | ||
+ | |||
+ | |||
+ | Zelio:: | ||
+ | { | ||
+ | delete zelioConn; | ||
+ | delete host; | ||
+ | } | ||
+ | |||
+ | |||
+ | int | ||
+ | Zelio::info () | ||
+ | { | ||
+ | // call Modbus TCP/IP coild query | ||
+ | zelioConn-> | ||
+ | return Rts2Sensor:: | ||
+ | } | ||
+ | |||
+ | |||
+ | int | ||
+ | Zelio::init () | ||
+ | { | ||
+ | int ret = Rts2Sensor:: | ||
+ | if (ret) | ||
+ | return ret; | ||
+ | |||
+ | zelioConn = new rts2core:: | ||
+ | return zelioConn-> | ||
+ | } | ||
+ | |||
+ | |||
+ | int | ||
+ | main (int argc, char **argv) | ||
+ | { | ||
+ | Zelio device = Zelio (argc, argv); | ||
+ | return device.run (); | ||
+ | } | ||
+ | </ |
devel/modbus_tcp_ip.txt · Last modified: 2008/11/14 00:00 (external edit)