User guide

Ethernet Developers Guide
840 USE 115 00 Version 1.0
73
If the remote node is an IP address, or if it’s a name that has been resolved, then
CSample_View tcpip_connect_r
q
function is called to initiate a connect re
q
uest to
the remote node. The listen port for the connect re
q
uest is five hundred and two,
and is defined b
y
the constant MBAP_LISTEN_PORT in modbus.h. If
tcpip_connect_r
q
succeeded in initiatin
g
a connect re
q
uest, then tcpip_connect_r
q
chan
g
es the transmit state to CONNECTING, otherwise it chan
g
es the transmit
state to IDLE.
The window sockets DLL
g
enerates a FD_CONNECT event which indicates if the
connect re
q
uest succeeded or failed. CSample_View OnTcpIpConnect function
processes the FD_CONNECT event. If the connect re
q
uest succeeded,
OnTcpIpConnect chan
g
es the transmit state to CONNECTED, otherwise it
chan
g
es the state to IDLE.
Recall that MFC architectural framework calls CSample_View OnPollInterval
member function to processes WM_POLL_INTERVAL messa
g
e sent as result of
CMainFrame class processin
g
a WM_TIMER messa
g
e. OnPollInterval examines
the transmit state. If the transmit state is CONNECTED, and the user has selected
a transaction t
y
pe, then OnPollInterval calls CSample_View TransmitUserRe
q
uest
function.
TransmitUserRe
q
uest encodes a re
q
uest based on the transaction t
y
pe, saves the
current time, and calls CSample_View TransmitMessa
g
e function. OnPollInterval
uses the saved time to determine when to transmit the next re
q
uest.
TransmitMessa
g
e attempts to send a messa
g
e to the remote side. To send the
messa
g
e, TransmitMessa
g
e enters a loop. In the bod
y
of the loop transmit
messa
g
e calls the window socket DLL send function. The followin
g
lists the
outcomes of the send function and the actions taken.
The messa
g
e was sent successfull
y
. TransmitMessa
g
e chan
g
es the transmit
state to TX_DONE and exits the loop.
Onl
y
part of the messa
g
e was sent. TransmitMessa
g
e reenters the loop.
Send function returns an error indicatin
g
there is no buffer space within the
transport s
y
stem. TransmitMessa
g
e chan
g
es the transmit state to BLOCKED
and exists the loop.
Send function returns some other error. TransmitMessa
g
e closes the
connection, chan
g
es the transmit state to IDLE, and exits the loop.
When buffer space within the transport s
y
stem becomes available to transmit
messa
g
es, the window socket DLL
g
enerates a FD_WRITE event. CSample_View
OnTcpWrite function processes the FD_WRITE function b
y
callin
g
TransmitMessa
g
e.