Receive State Machine. Schneider Electric Quantum 140 NOE 771 10 FactoryCast Ethernet Module, Quantum 140 NOE 771 00 Ethernet Module
Реклама
Реклама
Appendix B Ethernet Developers Guide
Receive State Machine
Description
The receive state machine receives a response to a transaction by first reading the header, determining the size of the rest of the message, and then reading the body of the message. The different states of the receive state machine are as follows. z
RX_HEADER. In the RX_HEADER state, the receive machine is receiving the message header. z
RX_BODY. In the RX_HEADER state, the receive machine is receiving the response message associated to the requested transaction. z
DUMP_BODY. In the DUMP_BODY state, the receive message is receiving a message, but there is no associated transaction with respect to this message.
The window socket DLL generates the FD_READ event whenever there is data to be read. If only part of the data is read, it generates another event. CSample_View
OnTcpIpRead function processes the FD_READ event, and drives the receive state machine.
When a FD_READ event is generated it is possible that the complete message is not present. The remote node may have attempted to send a 100 byte response, but the transport system may have only had buffer space to transmit three bytes.
The receiver will get a FD_READ for the three bytes. OnTcpIpRead calls
CSample_View rx_msg to read the receive data into the buffer. There are three parameters to rx_msg. The first parameter is a pointer to a receive buffer. The second input parameter is the receive size. The third parameter is both an input and output parameter. On both input and output the third parameter is the number of bytes read. These parameters allow the processing of a partially received message.
The receive state machine maintains a variable which is the number of bytes received. Initially the receive state machine is in the RX_HEADER state, and the number of bytes received is zero.
When OnTcpIpRead is called and the receive state is RX_HEADER OnTcpIpRead calls rx_msg with receive size equal to the header size. On return OnTcpIpRead examines the number of bytes received. If the number of bytes received is not equal to the header size, then receive machine remains in the RX_HEADER state, and OnTcpIpRead returns.
840 USE 116 00 Version 1.0
201
Appendix B Ethernet Developers Guide
Receive State Machine, continued
Description, continued
If upon return, the number of bytes received is the same size as the header size, then the header has been received. OnTcpIpRead sets the number of bytes received to zero, and the receive size is obtained from the header. These two values will be used the next time rx_msg is called. OnTcpIpRead also obtains the transaction identifier and the protocol type from the header. If the transaction identifier matches the transmit request identifier and the protocol type is MODBUS, then OnTcpIpRead changes the receive state to RX_BODY. However if either transaction identifier does not match or the protocol is not MODBUS, then
OnTcpIpRead changes the receive state to DUMP_BODY.
When OnTcpIpRead is called and the receive state is RX_BODY, OnTcpIpRead calls rx_msg with receive size equal to the value obtained from the header. On return OnTcpIpRead examines the number of bytes received. If the number of bytes received is not equal to the receive size, then the receive machine remains in the RX_HEADER state, and OnTcpIpRead returns.
If upon return the number of bytes 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 display.
OnTcpIpRead also changes the transmit state to WAIT_TO_TX, and resets the state receive state machine by setting the state to RX_HEADER and the number of bytes received to zero. It then returns.
When OnTcpIpRead is called and the receive state is DUMP_BODY,
OnTcpIpRead calls rx_msg with receive size equal to the value obtained from the header. On return OnTcpIpRead examines the number of bytes received. If the number of bytes received is not equal to the receive size, then the receive machine remains in the RX_HEADER state, and OnTcpIpRead returns.
If upon return the number of bytes received is the same as the receive size, the
OnTcpIpRead has completed reading the message. Since this message does not correspond to an transaction, the only processing OnTcIpRead performs is resetting the receive state machine.
The member function rx_msg calls the window socket recv function to read data.
The recv function either returns a non negative number that is the number of bytes read or it returns an error. If the number bytes read is zero, then the connection no longer exits, and rx_msg closes the socket, and sets the transmit state to IDLE. If the recv function returns the error indicating that no receive data is available, then rx_msg just returns. For any other recv function error, rx_msg closes the socket, and sets the transmit state to IDLE.
202
840 USE 116 00 Version 1.0
Завантажити
Реклама