Puerto paralelo

Como puedo manejar el puerto paralelo desde xp para prender luces o leds

1 Respuesta

Respuesta
1
Es fácil debes ocupar la una dll llamada io.dll que la puedes encontrar gratis en internet luego
en visual basic que te sirve para todos los windows incluido xp
En un modulo
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 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
en el formulario
Option Explicit
Public Out_TTL As Byte 'contiene el BYTE a sacar por el puerto
Public In_Port As Integer 'continen la direccion de lectura del LPT
Public Out_Port As Integer 'contiene la direcc.para escribir al LPT
Private Sub Form_Load() 'procedimiento inicial
'Configura la COMBOLIST cmbLptSelect
cmbLptSelect.AddItem "0x378"
cmbLptSelect.AddItem "0x278"
cmbLptSelect.AddItem "0x3BC"
'Establece LPT1 como default
cmbLptSelect.ListIndex = 0
SetLPTAddress 'estable direccion base del LTP
Port_Reset 'reseteo salidas TTL
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = 1 'evita que se salga mediante la 'X'
End Sub
Private Sub Form_Unload(Cancel As Integer) 'si sale del programa
Port_Reset 'entonces reseteo salidas TTL
End
End Sub
Private Sub cmdSalir_Click() 'si presiono SALIR, reseteo
Port_Reset 'las salidas TTL y salgo del programa
End
End Sub
Private Sub Port_Reset() 'procedimiento para resetear salidas TTL
PortOut Out_Port, 0
End Sub
Private Sub cmbLptSelect_Click()
SetLPTAddress 'llamo rutina para determinarar la direccion
'base del nuevo LPT elegido
End Sub
Private Sub SetLPTAddress() 'establece la direccion correpondiente
'al puerto seleccionado
Select Case cmbLptSelect.ListIndex
Case Is = 0
Out_Port = &H378
Case Is = 1
Out_Port = &H278
Case Is = 2
Out_Port = &H3BC
End Select
In_Port = Out_Port + 1
End Sub
Private Sub Chkttl0_Click() 'invierto estado de TTL0
If chkTTL0.Value = 1 Then
SetPortBit Out_Port, 0
chkTTL0.Caption = "Salida TTL0 = 1 - ALTO"
Else
ClrPortBit Out_Port, 0
chkTTL0.Caption = "Salida TTL0 = 0 - BAJO"
End If
End Sub
Private Sub Chkttl1_Click() 'invierto estado de TTL1
If chkTTL1.Value = 1 Then
SetPortBit Out_Port, 1
chkTTL1.Caption = "Salida TTL1 = 1 - ALTO"
Else
ClrPortBit Out_Port, 1
chkTTL1.Caption = "Salida TTL1 = 0 - BAJO"
End If
End Sub
Private Sub Chkttl2_Click() 'invierto estado de TTL2
If chkTTL2.Value = 1 Then
SetPortBit Out_Port, 2
chkTTL2.Caption = "Salida TTL2 = 1 - ALTO"
Else
ClrPortBit Out_Port, 2
chkTTL2.Caption = "Salida TTL2 = 0 - BAJO"
End If
End Sub
Private Sub Chkttl3_Click() 'invierto estado de TTL3
If chkTTL3.Value = 1 Then
SetPortBit Out_Port, 3
chkTTL3.Caption = "Salida TTL3 = 1 - ALTO"
Else
ClrPortBit Out_Port, 3
chkTTL3.Caption = "Salida TTL3 = 0 - BAJO"
End If
End Sub
Private Sub Chkttl4_Click() 'invierto estado de TTL4
If chkTTL4.Value = 1 Then
SetPortBit Out_Port, 4
chkTTL4.Caption = "Salida TTL4 = 1 - ALTO"
Else
ClrPortBit Out_Port, 4
chkTTL4.Caption = "Salida TTL4 = 0 - BAJO"
End If
End Sub
Private Sub Chkttl5_Click() 'invierto estado de TTL5
If chkTTL5.Value = 1 Then
SetPortBit Out_Port, 5
chkTTL5.Caption = "Salida TTL5 = 1 - ALTO"
Else
ClrPortBit Out_Port, 5
chkTTL5.Caption = "Salida TTL5 = 0 - BAJO"
End If
End Sub
Private Sub Chkttl6_Click() 'invierto estado de TTL6
If chkTTL6.Value = 1 Then
SetPortBit Out_Port, 6
chkTTL6.Caption = "Salida TTL6 = 1 - ALTO"
Else
ClrPortBit Out_Port, 6
chkTTL6.Caption = "Salida TTL6 = 0 - BAJO"
End If
End Sub
Private Sub Chkttl7_Click() 'invierto estado de TTL7
If chkTTL7.Value = 1 Then
SetPortBit Out_Port, 7
chkTTL7.Caption = "Salida TTL7 = 1 - ALTO"
Else
ClrPortBit Out_Port, 7
chkTTL7.Caption = "Salida TTL7 = 0 - BAJO"
End If
End Sub
Private Sub Timer1_Timer() 'timer de 50ms para refrescar en
Dim Lectura As Byte 'pantalla el estado de las
Dim Estado(3) As Byte 'entradas INPUT 0 a 3
Dim Estado_Str(3) As String
Dim Bucle As Byte
Lectura = PortIn(In_Port) 'leo el puerto de entrada
'filtro solo los bit's que necesito conocer
Estado(0) = Lectura And &H8 '= 00001000 en Binario
Estado(1) = Lectura And &H10 '= 00010000 en Binario
Estado(2) = Lectura And &H20 '= 00100000 en Binario
Estado(3) = Lectura And &H40 '= 01000000 en Binario
For Bucle = 0 To 3
If Estado(Bucle) <> 0 Then
Estado_Str(Bucle) = "1 - ALTO"
Else
Estado_Str(Bucle) = "0 - BAJO"
End If
Next Bucle
lblInput0.Caption = "INPUT 0 = " & Estado_Str(0)
lblInput1.Caption = "INPUT 1 = " & Estado_Str(1)
lblInput2.Caption = "INPUT 2 = " & Estado_Str(2)
lblInput3.Caption = "INPUT 3 = " & Estado_Str(3)
End Sub
y en la misma carpeta colocas la io.dll
Ahora los leds o lucecitas
Debes conectarlas al puerto de datos pata 2 a 9 y el otro pin del leds a tirra del puerto que puede ser de la pata 18 a la 25 al hacer click en los check se encenderá o apagara una luz o led
eso es todo espero que te sirva y cualquier otra consulta escríbeme

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas