SetDirection Method

Public Sub SetDirection(ByVal port As Long, ByVal direction As Long)

Summary

This method sets the direction register for a digital I/O port, which configures each pin (bit) of the port as an input or output. The direction of each bit of the port can be set individually, meaning that some bits of the port can be inputs at the same time that other bits on the same port are outputs. A 1-bit in the direction register causes the corresponding bit of the port to be put into output mode, while a 0-bit specifies input mode. For example, a value of F0 hex would put bits 0-3 into input mode and bits 4-7 into output mode.

Parameters

  • port - The port number (0-5).

  • direction - The new direction register for the port.

Return Value

This method does not return a value.

Remarks

Port 3 shares its pins with the analog channels. When the ADC is enabled, all pins of port 3 are forced into input mode. The direction register of port 3 cannot be modified while the ADC is enabled.

The valid range for the direction parameter is any 8-bit number (ranges from 0 to 255). However, note that because ports 4 and 5 are single-bit ports, only bit 0 will have any effect on those ports.

For your convenience, constants for the direction parameter are provided that configure the port bits to be all inputs or all outputs. These are, respectively, DIR_INPUT and DIR_OUTPUT.

Example
Private Sub example()
    
    ' Set up error handling for this routine
    On Error GoTo myerror
    
    Set dev = New Eth32
    
    ' .... Your code that establishes a connection here

	' Configure all odd bits of port 0 as inputs and even bits as outputs
	'  Direction parameter of 10101010 binary, which is &HAA hex or 170 decimal
	dev.SetDirection 0, 170

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

GetDirection Method, GetDirectionBit Method, SetDirectionBit Method