User guide
Ethernet Developers Guide
840 USE 115 00 Version 1.0
 75
The receive state machine maintains a variable which is the number of b
y
tes 
received. Initiall
y
 the receive state machine is in the RX_HEADER state, and the 
number of b
y
tes received is zero.
When OnTcpIpRead is called and the receive state is RX_HEADER OnTcpIpRead 
calls rx_ms
g
 with receive size e
q
ual to the header size.  On return OnTcpIpRead 
examines the number of b
y
tes received. If the number of b
y
tes received is not 
e
q
ual to the header size, then receive machine remains in the RX_HEADER state, 
and OnTcpIpRead returns.
If upon return, the number b
y
tes received is the same size as the header size, then 
the header has been received. OnTcpIpRead sets the number of b
y
tes received to 
zero, and the receive size is obtained from the header. These two values will be 
used the next time rx_ms
g
 is called. OnTcpIpRead also obtains the transaction 
identifier and the protocol t
y
pe from the header. If the transaction identifier 
matches the transmit re
q
uest identifier and the protocol t
y
pe is MODBUS, then 
OnTcpIpRead chan
g
es the receive state to RX_BODY. However if either 
transaction identifier does not match or the protocol is not MODBUS, then 
OnTcpIpRead chan
g
es the receive state to DUMP_BODY.
When OnTcpIpRead is called and the receive state is RX_BODY, OnTcpIpRead 
calls rx_ms
g
 with receive size e
q
ual to the value obtained from the header. On 
return OnTcpIpRead examines the number of b
y
tes received. If the number of 
b
y
tes received is not e
q
ual to the receive size, then the receive machine remains in 
the RX_HEADER state, and OnTcpIpRead returns.
If upon return the number of b
y
tes received is the same as the receive size, then 
OnTcpIpRead has read the response to a transaction. OnTcpIpRead saves the 
results and invalidates the client area which causes the results to be displa
y
. 
OnTcpIpRead also chan
g
es the transmit state to WAIT_TO_TX, and resets the 
state receive state machine b
y
 settin
g
 the state to RX_HEADER and the number of 
b
y
tes received to zero. It then returns.
When OnTcpIpRead is called and the receive state is DUMP_BODY, 
OnTcpIpRead calls rx_ms
g
 with receive size e
q
ual to the value obtained from the 
header. On return OnTcpIpRead examines the number of b
y
tes received. If the 
number of b
y
tes received is not e
q
ual to the receive size, then the receive machine 
remains in the RX_HEADER state, and OnTcpIpRead returns.
If upon return the number of b
y
tes received is the same as the receive size, the 
OnTcpIpRead has completed readin
g
 the messa
g
e. Since this messa
g
e does not 
correspond to an transaction, the onl
y
 processin
g
 OnTcIpRead performs is 
resettin
g
 the receive state machine.










