InputSuccessive Method

Public Function InputSuccessive(ByVal port As Long, ByVal maxcount As Long, _
                                ByRef status As Long) As Long

Summary

This method instructs the ETH32 device to read the specified port multiple times in succession until two consecutive reads yield the same result. This method 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 (in other words, back to back) 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.

Parameters

  • port - Specifies the port number (0-3) to read.

  • maxcount - The maximum number of times to read the port (2-255).

  • status - Output parameter 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.

Return Value

This method returns a Long. The return value is the last value read from the port, regardless of whether or not two successive reads ever matched.

Example
Private Sub example()
    Dim portval As Long
    Dim status As Long
    
    ' Set up error handling for this routine
    On Error GoTo myerror
    
    Set dev = New Eth32
    
    ' .... Your code that establishes a connection here
    
    ' Read the value of an 8-bit counter on port 0, limit to 20 reads
    portval = dev.InputSuccessive(0, 20, status)
    
    If status = 0 Then
        ' Never saw the same value twice in a row
    Else
        ' The port value is in the portval variable
    End If

    Exit Sub
myerror:
    MsgBox "ETH32 error: " & dev.ErrorString(Err.Number)
End Sub
        
See Also

InputByte Method, SetDirection Method