📄 cremotem.htm
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage 2.0">
<title>CRemoteModbus class members</title>
</head>
<body bgcolor="#FFFFFF">
<p><font size="5"><strong>CRemoteModbus</strong></font></p>
<p><strong>class CRemoteModbus : public </strong><a
href="cmodbu.htm"><strong>CModbus </strong></a></p>
<p><a href="#CRemoteModbus::openConnection"><strong>openConnection</strong></a><strong>
- </strong>open<strong> </strong>a connection with a slave
device.</p>
<p><a href="#CRemoteModbus::CloseConnection"><strong>CloseConnection</strong></a><strong>
- </strong>close a connection with a slave device.</p>
<p><a href="modbuimp.htm#CModbus::TxRxMessage"><font size="3"><strong>TxRxMessage</strong></font></a><font
size="3"><strong> </strong></font>virtual CModbus implementation.
<font size="3">Send and receive a message from a slave.</font></p>
<p><a href="modbuimp.htm#CModbus::ErrorMessage"><strong>ErrorMessage</strong></a><strong>
</strong>virtual CModbus implementation.Return string description
of an error code.</p>
<p><font size="4"><strong>properties</strong></font></p>
<p><a href="#CRemoteModbus::Host"><strong>Host</strong></a><strong>
</strong>- Host name</p>
<p><a href="#CRemoteModbus::Port"><strong>Port</strong></a> - IP
Port </p>
<p><a href="#CRemoteModbus::Timeout"><strong>Timeout</strong></a>
- timeout ms</p>
<p><a href="#CRemoteModbus::ReconnectOnEveryMessage"><strong>ReconnectOnEveryMessage</strong></a>
- when this property is true each call to a modbus function call <a
href="#CRemoteModbus::openConnection"><strong>openConnection</strong></a><strong>
</strong>before sending a query and close the connection after
response was received.</p>
<p> </p>
<p><a name="CRemoteModbus::openConnection"></a><font size="5"><strong>CRemoteModbus::openConnection</strong></font></p>
<p><strong>BOOL openConnection(CString sHost="", WORD
nPort=0,DWORD dwTimeOut=0); //</strong></p>
<p><strong>Return Value</strong></p>
<p>TRUE if the open was successful; otherwise FALSE. </p>
<p><font size="3"><strong>Parameters </strong></font></p>
<p>sHost - Host name, IP (127.0.0.1) or name (pep1.modicon.com)
format.</p>
<p>nPort - IP port. Open Modbus protocol use port 502, but you
can use another port if you wish.</p>
<p>dwTimeOut - Time out in ms used for sending modbus messages to
a slave.</p>
<p><font size="3"><strong>Remarks</strong></font></p>
<p><font size="3">This function try to connect with a slave using
TCP/IP network.<strong> </strong></font>When
ReconnectOnEveryMessage is TRUE this function is called before
sending a query to the slave, otherwise the connection remains
opened until is explicit closed by <a
href="#CRemoteModbus::CloseConnection">closeconnection</a> or by
class destructor.Instead of using function parameters you can use
class properties for seting sHost , nPort and dwTimeOut.</p>
<p><strong>example</strong>:</p>
<p>CRemoteModbus remoteModbus;</p>
<p>WORD wError;<br>
CWordArray anRegs;<br>
<br>
anRegs.SetSize(3); <br>
</p>
<p>//open connection on host pep1.modicon.com , port 502 and
timeout of 5 seconds.</p>
<p>if (remoteModbus.<strong>openConnection("pep1.modicon.com",502,5000)
</strong>{</p>
<blockquote>
<p>//Reads 40108 ...40110 registers from slave 17 <br>
wError = remoteModbus.<font size="3">ReadOutputRegisters(17,107,3,</font>anRegs)
;</p>
<p>if (CModbus::ERR_OK==wError) {</p>
<p>TRACE("Reg 40108=%d", anRegs[0]);</p>
<p>}</p>
<p>remoteModbus.CloseConnection();</p>
</blockquote>
<p>}</p>
<p><strong>See also: </strong><a href="cmodbu.htm"><strong>CModbus</strong></a><strong>,</strong><a
href="#CRemoteModbus::CloseConnection"><strong>CloseConnection</strong></a></p>
<p> </p>
<p><a name="CRemoteModbus::CloseConnection"></a><font size="5"><strong>CRemoteModbus::CloseConnection</strong></font></p>
<p><strong>BOOL CRemoteModbus::CloseConnection()</strong></p>
<p> </p>
<p><strong>Return Value</strong></p>
<p>TRUE if the close was successful; otherwise FALSE. </p>
<p>Remarks:</p>
<p>Closes an the connection associated with this object. If
ReconnectOnEveryMessage is TRUE this function is called after the
response from a slave was received.</p>
<p><strong>example:</strong></p>
<p>See<strong> </strong><a href="#CRemoteModbus::openConnection"><strong>openConnection</strong></a><strong>.</strong></p>
<p><strong>See also: </strong><a href="cmodbu.htm"><strong>CModbus</strong></a><strong>,</strong><a
href="#CRemoteModbus::openConnection"><strong>openConnection</strong></a></p>
<p><a name="CRemoteModbus::Port"></a><font size="5"><strong>CRemoteModbus::Port</strong></font></p>
<p><strong>WORD Port();<br>
void Port(WORD wPort);</strong></p>
<p><strong>Remarks:</strong></p>
<p>Get/Set IP port. Open modbus protocol use port 502 as a
default.</p>
<p><a name="CRemoteModbus::Host"></a><font size="5"><strong>CRemoteModbus::Host</strong></font></p>
<p><strong>CString Host();<br>
void Host(LPCSTR szHost);</strong></p>
<p><strong>Remarks:</strong></p>
<p>Get/Set Host name. Can be numeric IP format like
198.345.125.30 or a name like pep1.modicon.com.</p>
<p> </p>
<p><a name="CRemoteModbus::Timeout"></a><font size="5"><strong>CRemoteModbus::Timeout</strong></font></p>
<p><strong>void Timeout(DWORD dwTimeout);<br>
DWORD Timeout();</strong></p>
<p><strong>Remarks:</strong></p>
<p>Modbus functions timeout in <strong>ms.</strong></p>
<p> </p>
<p> </p>
<p><a name="CRemoteModbus::ReconnectOnEveryMessage"></a><font
size="5"><strong>CRemoteModbus::ReconnectOnEveryMessage</strong></font></p>
<p><strong>void ReconnectOnEveryMessage(BOOL bReconnect);<br>
BOOL ReconnectOnEveryMessage();</strong></p>
<p><strong>Remarks:</strong></p>
<p>When this property is true each call to a modbus function call
<a href="#CRemoteModbus::openConnection"><strong>openConnection</strong></a><strong>
</strong>before sending a query and close the connection after
response was received. Making this property as TRUE can save some
resources from the server or slave because there is limit of
connections that a server can manage simultaneously, but the
communication will be slower because opening a connection can
take good amount of time.</p>
<p><strong>See also: </strong><a
href="#CRemoteModbus::openConnection"><strong>openConnection</strong></a><strong>,</strong><a
href="#CRemoteModbus::CloseConnection"><strong>CloseConnection</strong></a><strong>.</strong></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -