int eth32_input_successive(eth32 handle, int port, int max, int *value, int *status);
This function instructs the ETH32 device to read the specified port multiple times in succession until two consecutive reads yield the same result. This function is useful for situations where a multi-bit value is being read, for example, the output of a digital counter chip. When reading such a value, it is always possible to read the value during a transition state as bits are changing and an invalid value is represented. By requiring that two successive reads match, any invalid transition values are automatically ignored. The device continues to read the port until one of the following conditions is met:
Two successive reads give the same port value. This value is returned.
The port was read the maximum number of times specified in the command without a match occurring.
This functionality is implemented directly within the ETH32 device (as opposed to the API), making it very fast and efficient with network traffic.
handle - The value returned by the eth32_open function.
port - Specifies the port number (0-3) to read.
max - The maximum number of times to read the port (2-255).
value - Pointer to a variable which will receive the port value. This will be the last value read from the port, regardless of whether or not two successive reads ever matched.
status - Pointer to a variable which will receive the number of times the port had to be read to get a successive match. If no match was ever seen, this will be zero.
This function returns zero on success and a negative error code on failure. Please note that the function is considered to succeed even if a matching value between two successive reads is never seen. Please see the Error Codes section for possible error codes.
eth32 handle; int result; int value; int status; // .... Your code that establishes a connection here // Read the value of port 0, limit to 20 reads result=eth32_input_successive(handle, 0, 20, &value, &status); if(result) { // handle error } if(status==0) { // Never saw the same value twice in a row } else { printf("The port value is %d.\n", value); }