Buenas.
El ejemplo es muy sencillo activa unas salidas y lee el pin "SELECT IN", el programa se diseño para una aplicación ejemplo que tenía una protección Mochila.
Si alguien está interesado en los fuentes y sabe algún site donde dejarlos que me lo haga saber.
'Aquí está mi modulo de las declaraciones.
Public Declare Sub PortOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Byte)
Public Declare Sub PortWordOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Integer)
Public Declare Sub PortDWordOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Long)
Public Declare Function PortIn Lib "IO.DLL" (ByVal Port As Integer) As Byte
Public Declare Function PortWordIn Lib "IO.DLL" (ByVal Port As Integer) As Integer
Public Declare Function PortDWordIn Lib "IO.DLL" (ByVal Port As Integer) As Long
Public Declare Sub SetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)
Public Declare Sub ClrPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)
Public Declare Sub NotPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)
Public Declare Function GetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte) As Boolean
Public Declare Function RightPortShift Lib "IO.DLL" (ByVal Port As Integer, ByVal Val As Boolean) As Boolean
Public Declare Function LeftPortShift Lib "IO.DLL" (ByVal Port As Integer, ByVal Val As Boolean) As Boolean
Public Declare Function IsDriverInstalled Lib "IO.DLL" () As Boolean
'api de retardo
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'Mi formulario
Dim sOrt As Byte 'valor de la salida puerto paralelo
Dim sIn As Byte 'valor de la entrada puerto paralelo
Dim pOut As Integer 'direccion del puerto paralelo para Activacion
Dim pIn As Integer 'direccion del puerto paralelo para lectura
Private Sub Form_Load()
Dim icon_punter As String
If IsDriverInstalled = True Then
icon_punter = App.Path & "\" & "Harrow.cur" 'icono personalizado para la pantalla
Screen.MouseIcon = LoadPicture(icon_punter)
pOut = &H378 'puerto LPT1 (salida datos)
pIn = &H379 'puerto LPT1 (Status impresora)
sOrt = 0 'desactivo todas las salidas
PortOut pOut, sOrt 'lo saco por el puerto
Call Lee_Pin_Select 'leo el estado del pin
Else
MsgBox "El Driver no se encuentra cargado en memoria ", vbCritical + vbOKOnly, "Error"
Unload Me
End If
End Sub
Private Sub lblEntradas_Click(Index As Integer)
Dim valor As Byte
valor = 2 ^ Index
If shpEntradas(Index).BackColor = vbWhite Then
sOrt = sOrt Or valor
shpEntradas(Index).BackColor = RGB(255, 0, 255)
Else
sOrt = sOrt - valor
shpEntradas(Index).BackColor = vbWhite
End If
'Sacalo por el puerto
PortOut pOut, sOrt 'lo saco por el puerto
'un pequeño retardo para no leer el pin inmediatamente
Sleep (100)
Call Lee_Pin_Select
End Sub
Private Sub Lee_Pin_Select()
sIn = PortIn(pIn) 'obtengo el valor del puerto paralelo &H379(LPT1) Status
sIn = sIn And &H10 'mascara para obtener el estado del pin Select In
If sIn = &H10 Then
lblPinSelect.Caption = "1"
Else
lblPinSelect.Caption = "0"
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Screen.MousePointer = 0
End Sub
Private Sub fmrEntradas_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Screen.MousePointer = 0
End Sub
Private Sub lblEntradas_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Screen.MousePointer = 99
End Sub