Hardware Reference
In-Depth Information
The following is an example of how Inpout32.dll can be used in conjunction
with a Visual Basic program that displays the status of each bit of the PC's
standard parallel port:
Inpout32.bas contains the following declarations:
Public Declare Function Inp Lib "inpout32.dll" _
Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Public Declare Sub Out Lib "inpout32.dll" _
Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As
Integer)
and the main project file is as follows:
Dim Port1 As Integer
Dim Port2 As Integer
Dim Port3 As Integer
Dim portdata As Integer
'
Private Sub Exitbutton_Click()
End
End Sub
'
Private Sub Form_Load()
' Port addresses for standard printer port
Port1 = &H378 'Data
Port2 = &H379 'Status
Port3 = &H37A 'Control
' Initialise port with all bits reset
portdata = &H0
Out Port1, (portdata)
End Sub
'
Private Sub Read_port_Click()
portdata = Inp(Port2)
If portdata And 1 Then bit0_led.FillColor = "&H000000FF" _
Else bit0_led.FillColor = "&H00E0E0E0"
If portdata And &H2 Then bit1_led.FillColor = "&H000000FF" _
Else bit1_led.FillColor = "&H00E0E0E0"
If portdata And &H4 Then bit2_led.FillColor = "&H000000FF" _
Else bit2_led.FillColor = "&H00E0E0E0"
If portdata And &H8 Then bit3_led.FillColor = "&H000000FF" _
Else bit3_led.FillColor = "&H00E0E0E0"
If portdata And &H10 Then bit4_led.FillColor = "&H000000FF" _
Else bit4_led.FillColor = "&H00E0E0E0"
If portdata And &H20 Then bit5_led.FillColor = "&H000000FF" _
Else bit5_led.FillColor = "&H00E0E0E0"
If portdata And &H40 Then bit6_led.FillColor = "&H000000FF" _
Else bit6_led.FillColor = "&H00E0E0E0"
If portdata And &H80 Then bit7_led.FillColor = "&H000000FF" _
Else bit7_led.FillColor = "&H00E0E0E0"
End Sub
The output produced by the inpout.dll Visual Basic demonstration program
is shown in Figure 6.10.
Search WWH ::




Custom Search