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