Enciende las luces de tu casa por computadora

Biblioteca enigma, sección de libros de consulta general en diferentes formatos
Avatar de Usuario
Enigma
Administrador del Sitio
Administrador del Sitio
Mensajes: 1268
Registrado: 20 Oct 2013, 16:26
Genero: Mujer
Profesion: Webmaster CEO SEO
Ubicacion: Matrix
Navegador: Chrome
Contactar:

Enciende las luces de tu casa por computadora

Mensaje sin leer por Enigma » 15 Dic 2013, 08:42

Enciende las luces de tu casa por computadora by Enigmaelectronica
Post Modificado y funcional para que todos lo puedan hacer fácilmente

Encuentrame en Google por Enigmaelectronica tambien en google+ entrando a la siguiente direccion: http://www.gplus.to/enigmaelectronica

Este aporte es Gratuito solo te pido que no quites mi autoría ni mis créditos. Saludos

hola, Hola!!!

Este es un proyecto en el cual a menudo mezclamos la electronica con la programacion, uniendolas con interfases, que en este caso, son por medio de un optoacoplador.

La idea se basa en poder controlar una serie de 8 dispositivos [por lo general luces] en una casa o algun lugar donde se requiera el control de la electricidad por medio remoto.

En mi post anterior publique mi compilacion de Turbo pascal, que viene parcheada y lista para ser usada sin correr el riesgo del temible error BSOD de DOS:
ERROR 20 DIVISION BY CERO

Porque elegir Pascal?

1)Primeramente porque es un lenguaje facil y rapido.
2)Al momento de compilar no se necesita de librerias.
3)Para este proyecto no usaremos una potente computadora
4)Puede usarse el ejecutable sin necesidad de instalarse primero, sin siquiera tener que usar algun sistema operativo, al menos con que tenga MS-DOS es suficiente.


Diagrama de la InterfaseAqui tenemos la interfase que usaremos para conectarla al puerto paralelo de la computadora:

Cabe aclarar que debemos hacer 8 de estos circuitos para poder controlarlos con el programa que mas adelante les dejo.


Es mas sencillo este circuito aunque digan lo contrario, en mi opinion, este circuito es mas facil de probar que confundirse con la puesta de los transistores...

Para la conexion:

Realicen 8 de estos circuitos, luego coloquen la entrada (R1) a cada pin de salida del puerto paralelo, del pin 2 al pin 9.

El puerto debe trabajar con la direccion 378h Base 1 en la direccion $0040 y segmento 0008
osea el puerto LPT1.

Si desean saber como trabaja, tanto este puerto, como otros, busquen mi post sobre libros de electronica o de programacion y acceso a puertos.

Primero descargate el compilador de Pascal, mas adelante les dare el enlace :D

Ahora empecemos por el asunto, Conozcamos la interfase:

Usando Circuitos integrados se la empresa motorola, que por su sencillez no deja de darnos cosas utiles como el "PASAJE POR CERO" y una tension de aislamiento cercano mayor a los 1 KiloVoltios.

el MOC usado es el 3040 (o su equivalente MOC3041) o un alternativo tambien como el siguiente diagrama:

Imagen

El TRIAC depende de lo que queramos controlar [por estado solido] interrumpiendo su electricidad.

Si la Carga es REISTIVA entonces usaremos un TIC226D que no pase de los 400 voltios
Si la Carga es INDUCTIVA entonces usaremos un TIC226M de unos 600 voltios de control

de lo anterior debemos tener cuidado de no sobrecargar la carga de trabajo del capacitor C1, poniendolo a un valor adecuado levemente superior a la carga del TRIAC.

El valor de R1 depende de la tension de entrada, R1 = 1000
(Uin - 1,3) / ILED (mA)
donde:
Uin se expresa en Voltios
R1 esta en Ohmios
ILED es la corriente que circula por el diodo LED en el optoacoplador expresada en mili Amperios.

ejemplo:
Uin = 12
ILED = 30 mA como en el MOC3040
R1 es en total = 356 Ohmios, estandar buscado cercano es de 330 Ohmios

12 - 1.3 = 10.7
10.7 / 30 = 0.356 = 356 Ohmios

Ahora sabemos que el puerto paralelo nos da un valor TTL de 5 voltios aplicamos la formula matematica para el calculo de la resistencia que el MOC3040 usara:

5 - 1.3 = 123 Ohmios = aproximandolo a un valor comercial nos da 125 Ohmios en R1

Ahora que tenemos los calculos procederemos a la programacion:

aqui esta el codigo fuente: si desean modificarlo. Si lo desean, tambien pueden descargarlo, si se desean ahorrar todo el trabajo de compilacion mas abajo del codigo fuente.


Codigo Fuente (algunas librerias no se usan, pueden eliminarlas)

Código: Seleccionar todo

uses DOS,graph,Crt,SVGA256,Txt;

label 100;
var
graphdriver,graphmode:integer;
nombre: string[17];
Font: array[0..767] of byte;
clave,Ch:char;
p: word absolute $0040:0008;
a,b,c,d,e,f,g,h: integer;
{----------------------------------------------------------------------------}

procedure inicio;
begin;
textbackground(blue);
clrscr;
gotoxy(17,10);
textcolor(white);
writeln('iniciando ambiente grafico, espere unos segundos');
gotoxy(10,30);
writeln('Por favor ingresa tu nombre para mostrarlo mas adelante');
gotoxy(10,33);
writeln('como usuario durante el programa');
writeln;
gotoxy(44,33);
textcolor(white);
textbackground(blue);
gotoxy(45,33);
read(nombre);
gotoxy(44,33);
delay(300);
clrscr;
end;

procedure Titulo;
begin
SetMode(1);
Bar(0,0,320{ancho horizontal},200{ancho vertical},blue{color fondo});
Print2(10,5,62,'Laboratorios Enigma software');{9 es violeta 16 es negro}
Print2(10,10,62,'');
Print2(30,50,62,' CONTROL PORT ');

Print2(10,160,62,' Presiona la Tecla [Enter]');
Print2(10,185,62,'(c)Gerson Enigma Guatemala 2005');
Ch:=ReadKey; Ch:=#0;
{este es el fondo principal del programa}
Bar(0,0,320,200,blue{color fondo});
Bar(2,2,316,20,9 {bluelight color fondo});
bar(2,186,316,18,9); {fondo de mensajes esc y F11}
bar(2,2,3,199,9);
bar(316,2,3,199,9);

Print2(115,10,62,'Control Port');
Print2(90,190,65,nombre);
print2(5,190,62,'Operador: ');
bar(7,35,220,88,black); {fondo de interruptores}
end;
{----------------------------------------------------------------------------}
procedure iniciodatos; {todos los bits a cero}
begin
delay(100);
port[p]:=0;
a:=0;
b:=0;
c:=0;
d:=0;
e:=0;
f:=0;
g:=0;
h:=0;
delay(100);
end;

procedure status;
begin
print2(85,25,65,'Estado');
Print2(5,126,65,' ');

print2(5,125,65,'[F1] terminal 1 [F7] Terminal 7');
print2(5,135,65,'[F2] Terminal 2 [F8] Terminal 8');
print2(5,145,65,'[F3] Terminal 3 [F9] Selec. Todos');
print2(5,155,65,'[F4] Terminal 4 [F10] Menu Ayuda ');
print2(5,165,65,'[F5] Terminal 5 ');
print2(5,175,65,'[F6] Terminal 6 [ESC] Salir');
end;

procedure instrucciones;
begin
end;

{----------------------------------------------------------------------------}
procedure estado;
begin

if port[p] = port[p]-1 then bar(10,40,200,10,black); print2(10,40,62,'interruptor [1] apagado');
if port[p] = port[p]+1 then bar(10,40,200,10,black); print2(10,40,62,'interruptor [1] Encendido');
if port[p] <> -1 or +1 then bar(10,40,200,10,black); print2(10,40,62,'interruptor [1] Data Error');

if port[p] = port[p]-2 then bar(10,50,200,10,black); print2(10,50,62,'interruptor [2] apagado');
if port[p] = port[p]+2 then bar(10,50,200,10,black); print2(10,50,62,'interruptor [2] Encendido');
if port[p] <> -2 or +2 then bar(10,50,200,10,black); print2(10,50,62,'interruptor [2] Data Error');

if port[p] = port[p]-4 then bar(10,60,200,10,black); print2(10,60,62,'interruptor [3] apagado');
if port[p] = port[p]+4 then bar(10,60,200,10,black); print2(10,60,62,'interruptor [3] Encendido');
if port[p] <> -4 or +4 then bar(10,60,200,10,black); print2(10,60,62,'interruptor [3] Data Error');

if port[p] = port[p]-8 then bar(10,70,200,10,black); print2(10,70,62,'interruptor [4] apagado');
if port[p] = port[p]+8 then bar(10,70,200,10,black); print2(10,70,62,'interruptor [4] Encendido');
if port[p] <> -8 or +8 then bar(10,70,200,10,black); print2(10,70,62,'interruptor [4] Data Error');

if port[p] = port[p]-16 then bar(10,80,200,10,black); print2(10,80,62,'interruptor [5] apagado');
if port[p] = port[p]+16 then bar(10,80,200,10,black); print2(10,80,62,'interruptor [5] Encendido');
if port[p] <> -16 or +16 then bar(10,80,200,10,black); print2(10,80,62,'interruptor [5] Data Error');

if port[p] = port[p]-32 then bar(10,90,200,10,black); print2(10,90,62,'interruptor [6] apagado');
if port[p] = port[p]+32 then bar(10,90,200,10,black); print2(10,90,62,'interruptor [6] Encendido');
if port[p] <> -32 or +32 then bar(10,90,200,10,black); print2(10,90,62,'interruptor [6] Data Error');

if port[p] = port[p]-64 then bar(10,100,200,10,black); print2(10,100,62,'interruptor [7] apagado');
if port[p] = port[p]+64 then bar(10,100,200,10,black); print2(10,100,62,'interruptor [7] Encendido');
if port[p] <> -64 or +64 then bar(10,100,200,10,black); print2(10,100,62,'interruptor [7] Data Error');

if port[p] = port[p]-128 then bar(10,110,200,10,black); print2(10,110,62,'interruptor [8] apagado');
if port[p] = port[p]+128 then bar(10,110,200,10,black); print2(10,110,62,'interruptor [8] Encendido');
if port[p] <> -128 or +128 then bar(10,110,200,10,black); print2(10,110,62,'interruptor [8] Data Error');

end;

procedure keys;

begin
estado;
repeat
begin
ch:=readkey;
if (ch = #0) then Begin
ch:= readkey;
case ch of

#59: begin {F1}
a := a+1;
if frac(a/2) = 0 then
begin
bar(10,40,210,10,black);
print2(10,40,62,'interruptor [1] apagado');
port[p]:=port[p]-1
end
else
begin
bar(10,40,210,10,black);
print2(10,40,62,'interruptor [1] Encendido');
port[p]:= port[p]+1
end;
end;

#60: begin {F2}
b := b+1;
if frac(b/2) = 0 then
begin
bar(10,50,210,10,black);
print2(10,50,62,'interruptor [2] apagado');
port[p]:=port[p]-2
end
else
begin
bar(10,50,210,10,black);
print2(10,50,62,'interruptor [2] Encendido');
port[p]:= port[p]+2
end;
end;

#61: begin {F3}
c := c+1;
if frac(c/2) = 0 then
begin
bar(10,60,210,10,black);
print2(10,60,62,'interruptor [3] apagado');
port[p]:=port[p]-4
end
else
begin
bar(10,60,210,10,black);
print2(10,60,62,'interruptor [3] Encendido');
port[p]:= port[p]+4
end;
end;

#62: begin {F4}
d := d+1;
if frac(d/2) = 0 then
begin
bar(10,70,210,10,black);
print2(10,70,62,'interruptor [4] apagado');
port[p]:=port[p]-8
end
else
begin
bar(10,70,210,10,black);
print2(10,70,62,'interruptor [4] Encendido');
port[p]:= port[p]+8
end;
end;

#63: begin {F5}
e := e+1;
if frac(e/2) = 0 then
begin
bar(10,80,210,10,black);
print2(10,80,62,'interruptor [5] apagado');
port[p]:=port[p]-16
end
else
begin
bar(10,80,210,10,black);
print2(10,80,62,'interruptor [5] Encendido');
port[p]:= port[p]+16
end;
end;

#64: begin {F6}
f := f+1;
if frac(f/2) = 0 then
begin
bar(10,90,210,10,black);
print2(10,90,62,'interruptor [6] apagado');
port[p]:=port[p]-32
end
else
begin
bar(10,90,210,10,black);
print2(10,90,62,'interruptor [6] Encendido');
port[p]:= port[p]+32
end;
end;

#65: begin {F7}
g := g+1;
if frac(g/2) = 0 then
begin
bar(10,100,210,10,black);
print2(10,100,62,'interruptor [7] apagado');
port[p]:=port[p]-64
end
else
begin
bar(10,100,210,10,black);
print2(10,100,62,'interruptor [7] Encendido');
port[p]:= port[p]+64
end;
end;

#66: begin {F8}
h := h+1;
if frac(h/2) = 0 then
begin
bar(10,110,210,10,black);
print2(10,110,62,'interruptor [8] apagado');
port[p]:=port[p]-128
end
else
begin
bar(10,110,210,10,black);
print2(10,110,62,'interruptor [8] Encendido');
port[p]:= port[p]+128
end;
end;

#70: {[F11]}
begin
bar(7,35,210,88,black); {fondo de interruptores}
print2(10,40,62,'Creado por ');
print2(10,60,62,'Gerson Hernandez');
print2(10,90,62,'(c) 2005 enigma');
end;

#68 : {[F10]}
begin
instrucciones;
titulo;
keys;
end;

#67: {[F9]}
begin
bar(7,35,210,88,black); {fondo de interruptores}
print2(10,40,62,'Encenderlos Todos [F2]');
print2(10,50,62,'Apagarlos Todos [F3]');
print2(10,60,62,'Regresar [Esc]');
print2(10,80,62,'Estado Actual:');
repeat
begin
ch:= readkey;
case ch of
#60:
begin {F2}
bar(10,100,210,10,black);
print2(10,100,62,'Todos Encendidos');
port[p]:=255;
end;
else
begin
bar(10,100,210,10,black);
print2(10,100,62,'Todos Apagados');
port[p]:= 0 ;
end;
end;
end;
until ch = #27;
bar(7,35,210,88,black); {fondo de interruptores}
keys;



end;
end;
end;
end;
until ch in [#27];
end;





procedure salir;
begin
Bar(0,0,320{ancho horizontal},200{ancho vertical},Blue{color fondo});
print2(19,50,62,'Saliendo del programa');
print2(90,120,62,' Cerrando Sesion');
print2(10,186,62,'Creado por Gerson Hernandez (c)2005');
sound(2700);
delay(100);
nosound;
Delay(700);

end;
{------------Main Program------------}

begin
FileRead('0808art.fnt',0,96,8,Font);
InstallFont(1,8,8,32,96,8,Font);
iniciodatos;
inicio;
Titulo;
status;
keys;

salir;
{ Ch:=ReadKey; Ch:=#0;}

end.

Notas Finales

La interfase del optoacoplador se debe poner a los pines siguientes del puerto paralelo:
El programa usa librerias en modo Grafico si no las tienen o no las quieren usar quiten lo que no es interese
Pines de datos:

[2][3][4][5][6][7][8][9]

Los pines del 18 al 25 se conectan todos juntos a Masa (0 Voltios = GND) y los restantes pines no se usan.

Imagen


Imagen


Quieren las cosas faciles?
Entonces les dejo el programa ya compilado:
Filename: PORT.rar
Filesize: 8 kB
Upload-Date: 31/05/2009

Download-Link:

Código: Seleccionar todo

http://rapidshare.com/files/239146411/PORT.rar

¿Ahhh? ¿No te gusta el DOS?
¿Quieres hacerlo en Visula Basic?

Gracias a la Valiosa Colaboracion del ingeniero Gerson Hernandez un amigo muy especial, en esta ocasión les tengo la segunda parte y final del tutorial.

Lo haremos por medio de Visual Basic 6.0 Service Pack 1

Imagen

Todo esto es posible Gracias a una libreria de codigo Cerrado pero de uso libre, se trata de la libreria IO.DLL que puede ser obtenido desde la web:

Código: Seleccionar todo

http://www.geekhideout.com/iodll.shtml
Aunque ya pueden descargarlo desde aqui, adjunto.

Prosigamos:
El control lo hace desde esa libreria, primero necesitamos tener la interfaz conectada y lista, ademas de los puertos LPT Paralelo en la direccion correcta: 378

Luego en Visual Basic colocamos los el formulario con los labels que ven en la imagen de arriba.
los chek button y los option button tambien tienen que estar.

bueno por falta de tiempo les dejo el codigo fuente, si señores, el codigo Fuente de como controlar el puerto paralelo by me, Enigma:

Esta parte va al inicio del codigo fuente del formulario FORM:

Código: Seleccionar todo

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
Este boton es Súmamente util, podemos cerrar el programa y dejar los estados de los pines tal y como queremos, sin necesidad de tener el programa siempre abierto.

Código: Seleccionar todo

Private Sub Command2_Click()
End
End Sub

En la seccion FORM LOAD va este codigo

Código: Seleccionar todo

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


Al poner esto evitamos salir mediante la X de la ventana Activa

Código: Seleccionar todo

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Cancel = 1                  'evita que se salga mediante la 'X'
End Sub

Esta opcion Cierra el programa y todo lo que haya ejecutado en la memoria del sistema

Código: Seleccionar todo

Private Sub Form_Unload(Cancel As Integer)  'si sale del programa
    Port_Reset                              'entonces reseteo salidas TTL
    End
End Sub


Solamente con el boton CMD llamado SALIR podemos salir del sistema

Código: Seleccionar todo

Private Sub cmdSalir_Click()    'si presiono SALIR, reseteo
    Port_Reset                  'las salidas TTL y salgo del programa
    End
End Sub

Esto Resetea y pone a 0 todos los pines del puerto paralelo

Código: Seleccionar todo

Private Sub Port_Reset()        'procedimiento para resetear salidas TTL
    PortOut Out_Port, 0
End Sub

Este comando nos pone en el programa que tipo de puerto paralelo es y su direccion

Código: Seleccionar todo

Private Sub cmbLptSelect_Click()
    
    SetLPTAddress              'llamo rutina para determinarar la direccion
                               'base del nuevo LPT elegido
End Sub

Este codigo Muestra el formulario de Ayuda y algun credito que quieran poner

Código: Seleccionar todo

Private Sub cmdHelpOnLpt_Click()
    frmHelpOnLpt.Show
End Sub

Esta seccion es la que Selecciona una de las 4 direcciones posibles del puerto paralelo

Código: Seleccionar todo

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

Aqui van los codigos de todos los CHECK BUTTON para cada Salida del puerto paralelo

Código: Seleccionar todo

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

Código: Seleccionar todo

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

Código: Seleccionar todo

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

Código: Seleccionar todo

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

Código: Seleccionar todo

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

Código: Seleccionar todo

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

Código: Seleccionar todo

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

Código: Seleccionar todo

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

Este nos muestra una imagen como por ejemplo un diagrama de conexiones, util para el que lo quiera armar

Código: Seleccionar todo

Private Sub Image2_Click()

End Sub


Muy importante, Debemos poner un TIMER y en el hacer doble clic y escribir el siguiente codigo

Código: Seleccionar todo

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

Luego Creamos un modulo llamado MODULE.BAS que contenga lo siguiente:

Código: Seleccionar todo

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

Luego ejecutamos con F5 y Compilamos para luego Generar el EXE.
Si desean Obtener todo el codigo fuente pueden descargarlo Gracias a la colaboracion del Backup de los archivos que uso en una empresa del Ingeniero Gerson Hernandez.

Descarga el archivo en formato ISO


Nombre puerto_paralelo_Files.iso
Formato Archivo de Imagen de Disco ISO
Tamaño: 7999 KB
Status: File available

Contenido: Codigo fuente del programa de control de puertos paralelos en Visual Basic
Enlaces:

Mirror Rapidshare

Código: Seleccionar todo

http://rapidshare.com/files/340298467/puerto_paralelo_Files.iso
Mirror MegaUpload

Código: Seleccionar todo

http://www.megaupload.com/?d=8GDJWQIM



Avatar de Usuario
Enigma
Administrador del Sitio
Administrador del Sitio
Mensajes: 1268
Registrado: 20 Oct 2013, 16:26
Genero: Mujer
Profesion: Webmaster CEO SEO
Ubicacion: Matrix
Navegador: Chrome
Contactar:

Re: Enciende las luces de tu casa por computadora

Mensaje sin leer por Enigma » 30 Dic 2015, 16:28

La licencia de la liberia (Tengo que ponerla por los créditos) y Los créditos a continuación sobre la IO.DLL

Synopsis

IO.DLL allows seamless port I/O operations for Windows 95/98/NT/2000/XP using the same library.
Introduction

In the pre-Windows days, it was a relatively simple matter to access I/O ports on a typical PC. Indeed, nearly every language sported a special command for doing so. As Windows emerged and gradually evolved, this flapping in the wind behaviour could no longer be tolerated because of operating system's ability to virtualize hardware.

Virtualizing hardware means that an application (typically a DOS box in Windows) believes it is talking directly to a physical device, but in reality it is talking to a driver that emulates the hardware, passing data back and forth as appropriate. This is how you are able to open dozens of DOS boxes in your Windows session, each one with the strange notion that it has exclusive access to peripherals such as the video adapter, keyboard, sound card and printer.

If one were to rudely bang out data to an I/O port that Windows thought it was in full control of, the "official bad thing" could occur, the severity of which depending upon the exact hardware that was being accessed. Actually, with the virtualization just mentioned, it is quite improbable that Windows would permit anything too nasty from occuring.

Windows 95/98 actually does allow I/O operations be executed at the application level, although you'd be hard pressed to find a language that supports this directly. Typically the programmer will have to resort to assembly language for this kind of low-level control. If you know what you are doing, this can be a quick and easy way to access I/O ports. Of course, not everyone knows, or desires to learn 80x86 assembly programming just because they want to turn on a lamp from their computer. However, the unwillingness to learn assembly language becomes rather trivial when faced with 9x's big brother.

Windows NT/2000/XP, being the secure operating system that it is, does not permit port I/O operations at the application level at all. Period. A program with inline IN and OUT assembly instructions that runs perfectly on Windows 95/98 will fail horribly when it comes to Windows NT/2000/XP.

Windows NT/2000/XP does, however, allow I/O instructions in its kernel mode drivers. A kernel mode driver runs at the most priviledged level of the processor and can do whatever it pleases, including screwing up the system beyond repair, thus writing a kernel mode driver is not for the feint of heart.

If you were to take it upon yourself to wade through the documentation of the Windows NT/2000/XP ddk and piece together a driver that was callable by your application to do the I/O instructions on behalf of your application, you'd probably notice something not too pleasant--this sort of access is painfully slow. The call from application level to system level typically takes about one millisecond. Compare this to the one microsecond that a normal I/O access takes. To further the insult, you are at the whim of the operating system. If it has tasks which it believes are of higher priority than your lowly call to your driver, it will perform them, making precise timing nearly impossible.

Obviously, writing a driver that does acts a proxy for the I/O calls isn't the most ideal solution. There is, however, a solution for NT/2000/XP that allows the same convienience of inline assembly language that 95/98 does.

As mentioned, a kernel mode driver can do whatever it wants. The implication here is that if another kernel mode driver shut off application access to the I/O ports, it should be possible for another kernel mode driver to turn it back on. This is where IO.DLL enters the picture.

Licensing


IO.DLL is completely free! However, you may not:
Charge others for it in any way. For example, you cannot sell it as a stand alone product.
Charge for an IO.DLL wrapper, such as an OCX or Delphi control whose purpose is just to put a fancy interface on IO.DLL. I consider these to be "derived works" and they must be provided free of charge.
Claim that it is your property.
Also, the author (that's me) cannot be held liable due to io.dll's failure to perform. As with most free stuff, you are on your own.
Source Code and Special Modifications

The source code is available for $1,000 US.
I'm willing to work with people should they require a special modification to IO.DLL. For example, you might have a strict timing requirement of some sort that can only be done in kernel mode. For a fee, I will modify IO.DLL and/or the embedded kernel mode driver for the task at hand.

Description of IO.DLL

IO.DLL provides a useful set of commands for reading and writing to the I/O ports. These commands are consistent between 95/98 and NT/2000/XP. Furthermore, there is no need for the programmer to learn assembly language or muck with kernel mode drivers. Simply link to the DLL and call the functions. It's that easy.

Windows NT/2000/XP is accomodated through the use of a small kernel mode driver that releases the ports as needed to the application. This driver is embedded in the DLL and is installed if Windows NT/2000/XP is determined to be the underlying operating system.

Due to the very minor overhead involved in dynamically linking to IO.DLL, and the optimized functions contained within, access to I/O ports is nearly as fast as if it was written in raw assembler and inlined in your application. This holds true for both Windows 95/98 and Windows NT/2000/XP.

Before moving on, it is probably prudent to mention that the technique employed in IO.DLL for releasing the ports to the application level isn't, strictly speaking, the proper way to do things. The proper way is to have a virtual device driver for Windows 95/98 and a kernel mode driver for Windows NT/2000/XP. This isn't very practical for many people though, nor is it really necessary. There are several successful commercial products on the market that do exactly what IO.DLL does. Let it be noted though that some of them are shady with their explanation of how their product works, meanwhile charging $500 or more for it.

What Ports can IO.DLL Access?

IO.DLL is capable of accessing only those ports that are inherent to the processor itself through the IN and OUT instructions. This means that it cannot access most add-in parallel ports or com ports because they are typically memory-mapped these days rather than IO-mapped. IO.DLL also cannot access virtual devices. Here is a table of what ports can be accessed:

IO Address Device
000-01F DMA controller #1
020-03F Interrupt controller
040-05F Timer
060-06F Keyboard controller
070-07F Real-time clock, CMOS Memory, NMI mask
080 manufacturer's diagnostics checkpoint
080-09F DMA page register
0A0-0BF Interrupt controller #2
0C0-0DF DMA controller #2
0F0-0FF Math Coprocessor
170-177 Hard disk (secondary)
1F0-17F Hard disk
200-207 Game I/O
278-27F LPT 2
2C0-2DF EGA #2
2E8-2EF COM 4
2F8-2FF COM 2
300-31F Prototype card
370-377 FDC (secondary)
378-37F LPT 1
380-38F SDLC
3A0-3AF bisynchronous port #1
3B0-3BF MDA
3C0-3CF EGA
3D0-3DF CGA and EGA
3E8-3EF COM 3
3F0-3F7 FDC
3F8-3FF COM 1

Enlace de la libreria:
io.zip 46K (Contains all the files)

Código: Seleccionar todo

http://www.geekhideout.com/downloads/io.zip
io.dll 46K

Código: Seleccionar todo

http://www.geekhideout.com/downloads/io.dll
The following two files are for C++ users. There is more info on these in the prototypes section.
io.cpp 1.3K

Código: Seleccionar todo

http://www.geekhideout.com/downloads/io.cpp

Código: Seleccionar todo

#include "io.h"

PORTOUT PortOut;
PORTWORDOUT PortWordOut;
PORTDWORDOUT PortDWordOut;
PORTIN PortIn;
PORTWORDIN PortWordIn;
PORTDWORDIN PortDWordIn;
SETPORTBIT SetPortBit;
CLRPORTBIT ClrPortBit;
NOTPORTBIT NotPortBit;
GETPORTBIT GetPortBit;
RIGHTPORTSHIFT RightPortShift;
LEFTPORTSHIFT LeftPortShift;
ISDRIVERINSTALLED IsDriverInstalled;

HMODULE hio;

void UnloadIODLL() {
	FreeLibrary(hio);
}

int LoadIODLL() {
	hio = LoadLibrary("io");
	if (hio == NULL) return 1;

	PortOut = (PORTOUT)GetProcAddress(hio, "PortOut");
	PortWordOut = (PORTWORDOUT)GetProcAddress(hio, "PortWordOut");
	PortDWordOut = (PORTDWORDOUT)GetProcAddress(hio, "PortDWordOut");
	PortIn = (PORTIN)GetProcAddress(hio, "PortIn");
	PortWordIn = (PORTWORDIN)GetProcAddress(hio, "PortWordIn");
	PortDWordIn = (PORTDWORDIN)GetProcAddress(hio, "PortDWordIn");
	SetPortBit = (SETPORTBIT)GetProcAddress(hio, "SetPortBit");
	ClrPortBit = (CLRPORTBIT)GetProcAddress(hio, "ClrPortBit");
	NotPortBit = (NOTPORTBIT)GetProcAddress(hio, "NotPortBit");
	GetPortBit = (GETPORTBIT)GetProcAddress(hio, "GetPortBit");
	RightPortShift = (RIGHTPORTSHIFT)GetProcAddress(hio, "RightPortShift");
	LeftPortShift = (LEFTPORTSHIFT)GetProcAddress(hio, "LeftPortShift");
	IsDriverInstalled = (ISDRIVERINSTALLED)GetProcAddress(hio, "IsDriverInstalled");

	atexit(UnloadIODLL);

	return 0;
}

io.h 1.2K
http://www.geekhideout.com/downloads/io.h

Código: Seleccionar todo

#include <windows.h>

typedef void (WINAPI *PORTOUT) (short int Port, char Data);
typedef void (WINAPI *PORTWORDOUT)(short int Port, short int Data);
typedef void (WINAPI *PORTDWORDOUT)(short int Port, int Data);
typedef char (WINAPI *PORTIN) (short int Port);
typedef short int (WINAPI *PORTWORDIN)(short int Port);
typedef int (WINAPI *PORTDWORDIN)(short int Port);
typedef void (WINAPI *SETPORTBIT)(short int Port, char Bit);
typedef void (WINAPI *CLRPORTBIT)(short int Port, char Bit);
typedef void (WINAPI *NOTPORTBIT)(short int Port, char Bit);
typedef short int (WINAPI *GETPORTBIT)(short int Port, char Bit);
typedef short int (WINAPI *RIGHTPORTSHIFT)(short int Port, short int Val);
typedef short int (WINAPI *LEFTPORTSHIFT)(short int Port, short int Val);
typedef short int (WINAPI *ISDRIVERINSTALLED)();

extern PORTOUT PortOut;
extern PORTWORDOUT PortWordOut;
extern PORTDWORDOUT PortDWordOut;
extern PORTIN PortIn;
extern PORTWORDIN PortWordIn;
extern PORTDWORDIN PortDWordIn;
extern SETPORTBIT SetPortBit;
extern CLRPORTBIT ClrPortBit;
extern NOTPORTBIT NotPortBit;
extern GETPORTBIT GetPortBit;
extern RIGHTPORTSHIFT RightPortShift;
extern LEFTPORTSHIFT LeftPortShift;
extern ISDRIVERINSTALLED IsDriverInstalled;

extern int LoadIODLL();
C/C++ Prototypes

void WINAPI PortOut(short int Port, char Data);
void WINAPI PortWordOut(short int Port, short int Data);
void WINAPI PortDWordOut(short int Port, int Data);
char WINAPI PortIn(short int Port);
short int WINAPI PortWordIn(short int Port);
int WINAPI PortDWordIn(short int Port);
void WINAPI SetPortBit(short int Port, char Bit);
void WINAPI ClrPortBit(short int Port, char Bit);
void WINAPI NotPortBit(short int Port, char Bit);
short int WINAPI GetPortBit(short int Port, char Bit);
short int WINAPI RightPortShift(short int Port, short int Val);
short int WINAPI LeftPortShift(short int Port, short int Val);
short int WINAPI IsDriverInstalled();
To use IO.DLL with Visual C++/ Borland C++, etc, you'll need to use LoadLibrary and GetProcAddress. Yes, it's more of a pain than using a .lib file, but because of name mangling, it's the only reliable way of calling the functions in IO.DLL. I've gone ahead and done the dirty work for you:

io.cpp

Código: Seleccionar todo

#include "io.h"

PORTOUT PortOut;
PORTWORDOUT PortWordOut;
PORTDWORDOUT PortDWordOut;
PORTIN PortIn;
PORTWORDIN PortWordIn;
PORTDWORDIN PortDWordIn;
SETPORTBIT SetPortBit;
CLRPORTBIT ClrPortBit;
NOTPORTBIT NotPortBit;
GETPORTBIT GetPortBit;
RIGHTPORTSHIFT RightPortShift;
LEFTPORTSHIFT LeftPortShift;
ISDRIVERINSTALLED IsDriverInstalled;

HMODULE hio;

void UnloadIODLL() {
	FreeLibrary(hio);
}

int LoadIODLL() {
	hio = LoadLibrary("io");
	if (hio == NULL) return 1;

	PortOut = (PORTOUT)GetProcAddress(hio, "PortOut");
	PortWordOut = (PORTWORDOUT)GetProcAddress(hio, "PortWordOut");
	PortDWordOut = (PORTDWORDOUT)GetProcAddress(hio, "PortDWordOut");
	PortIn = (PORTIN)GetProcAddress(hio, "PortIn");
	PortWordIn = (PORTWORDIN)GetProcAddress(hio, "PortWordIn");
	PortDWordIn = (PORTDWORDIN)GetProcAddress(hio, "PortDWordIn");
	SetPortBit = (SETPORTBIT)GetProcAddress(hio, "SetPortBit");
	ClrPortBit = (CLRPORTBIT)GetProcAddress(hio, "ClrPortBit");
	NotPortBit = (NOTPORTBIT)GetProcAddress(hio, "NotPortBit");
	GetPortBit = (GETPORTBIT)GetProcAddress(hio, "GetPortBit");
	RightPortShift = (RIGHTPORTSHIFT)GetProcAddress(hio, "RightPortShift");
	LeftPortShift = (LEFTPORTSHIFT)GetProcAddress(hio, "LeftPortShift");
	IsDriverInstalled = (ISDRIVERINSTALLED)GetProcAddress(hio, "IsDriverInstalled");

	atexit(UnloadIODLL);

	return 0;
}
io.h

Código: Seleccionar todo

#include <windows.h>

typedef void (WINAPI *PORTOUT) (short int Port, char Data);
typedef void (WINAPI *PORTWORDOUT)(short int Port, short int Data);
typedef void (WINAPI *PORTDWORDOUT)(short int Port, int Data);
typedef char (WINAPI *PORTIN) (short int Port);
typedef short int (WINAPI *PORTWORDIN)(short int Port);
typedef int (WINAPI *PORTDWORDIN)(short int Port);
typedef void (WINAPI *SETPORTBIT)(short int Port, char Bit);
typedef void (WINAPI *CLRPORTBIT)(short int Port, char Bit);
typedef void (WINAPI *NOTPORTBIT)(short int Port, char Bit);
typedef short int (WINAPI *GETPORTBIT)(short int Port, char Bit);
typedef short int (WINAPI *RIGHTPORTSHIFT)(short int Port, short int Val);
typedef short int (WINAPI *LEFTPORTSHIFT)(short int Port, short int Val);
typedef short int (WINAPI *ISDRIVERINSTALLED)();

extern PORTOUT PortOut;
extern PORTWORDOUT PortWordOut;
extern PORTDWORDOUT PortDWordOut;
extern PORTIN PortIn;
extern PORTWORDIN PortWordIn;
extern PORTDWORDIN PortDWordIn;
extern SETPORTBIT SetPortBit;
extern CLRPORTBIT ClrPortBit;
extern NOTPORTBIT NotPortBit;
extern GETPORTBIT GetPortBit;
extern RIGHTPORTSHIFT RightPortShift;
extern LEFTPORTSHIFT LeftPortShift;
extern ISDRIVERINSTALLED IsDriverInstalled;

extern int LoadIODLL();
Just save these two files and include them in your project. For a Visual C++, you may need to add #include "StdAfx.h" at the top of io.cpp otherwise the compiler will whine at you.

These two files take care of calling LoadLibrary and all the neccessary calls to GetProcAddress, making your life happy once again.

The only step you are required to do is call LoadIODLL somewhere at the beginning of your program. Make sure you do this or you will find yourself faced with all sorts of interesting crashes.

Please let me know if you find any errors in the above two files. They are new and haven't been tested all that much.

Delphi Prototypes

procedure PortOut(Port : Word; Data : Byte);
procedure PortWordOut(Port : Word; Data : Word);
procedure PortDWordOut(Port : Word; Data : DWord);
function PortIn(Port : Word) : Byte;
function PortWordIn(Port : Word) : Word;
function PortDWordIn(Port : Word) : DWord;
procedure SetPortBit(Port : Word; Bit : Byte);
procedure ClrPortBit(Port : Word; Bit : Byte);
procedure NotPortBit(Port : Word; Bit : Byte);
function GetPortBit(Port : Word; Bit : Byte) : WordBool;
function RightPortShift(Port : Word; Val : WordBool) : WordBool;
function LeftPortShift(Port : Word; Val : WordBool) : WordBool;
function IsDriverInstalled : Boolean;
Important! To use these functions in your Delphi program, the correct calling convention of stdcall is required. For example:
procedure PortOut(Port : Word; Data : Byte); stdcall; external 'io.dll';
Visual Basic Prototypes

Private Declare Sub PortOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Byte)
Private Declare Sub PortWordOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Integer)
Private Declare Sub PortDWordOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Long)
Private Declare Function PortIn Lib "IO.DLL" (ByVal Port As Integer) As Byte
Private Declare Function PortWordIn Lib "IO.DLL" (ByVal Port As Integer) As Integer
Private Declare Function PortDWordIn Lib "IO.DLL" (ByVal Port As Integer) As Long
Private Declare Sub SetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)
Private Declare Sub ClrPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)
Private Declare Sub NotPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)
Private Declare Function GetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte) As Boolean
Private Declare Function RightPortShift Lib "IO.DLL" (ByVal Port As Integer, ByVal Val As Boolean) As Boolean
Private Declare Function LeftPortShift Lib "IO.DLL" (ByVal Port As Integer, ByVal Val As Boolean) As Boolean
Private Declare Function IsDriverInstalled Lib "IO.DLL" As Boolean


Function Descriptions
Please refer to the prototype for the particular language you are using.

PortOut
Outputs a byte to the specified port.

PortWordOut
Outputs a word (16-bits) to the specified port.

PortDWordOut
Outputs a double word (32-bits) to the specified port.

PortIn
Reads a byte from the specified port.

PortWordIn
Reads a word (16-bits) from the specified port.

PortDWordIn
Reads a double word (32-bits) from the specified port.

SetPortBit
Sets the bit of the specified port.

ClrPortBit
Clears the bit of the specified port.

NotPortBit
Nots (inverts) the bit of the specified port.

GetPortBit
Returns the state of the specified bit.

RightPortShift
Shifts the specified port to the right. The LSB is returned, and the value passed becomes the MSB.

LeftPortShift
Shifts the specified port to the left. The MSB is returned, and the value passed becomes the LSB.

IsDriverInstalled
Returns non-zero if io.dll is installed and functioning. The primary purpose of this function is to ensure that the kernel mode driver for NT/2000/XP has been installed and is accessible.

Responder

Volver a “Area Ingenieria - Programacion - Web - Computacion”