Hi!
Presently I try to write a program to send/read data from and to the parallelport. For that problem I use the following code by using the
io.dll (http://www.geekhideout.com/iodll.shtml).
PortNum.l = $378 ; PortNummer Datenregisters (LPT1)
PortNumS.l = $379 ; PortNummer Statusregisters (LPT1)
PortNumC.l = $37A ; PortNummer Controlregisters (LPT1)
i.b = 0
Ergebnis.b=0
j.l=0
;---------------------------------------(check library file open)------------------LibOpen.l = OpenLibrary(1,"io.dll")
If LibOpen = 0
End
EndIf
AdrPortOut.l = IsFunction(1, "PortOut")
AdrPortIn.l = IsFunction(1, "PortIn")
CallFunctionFast(AdrPortOut, PortNum,22)
;-----------------------------Öffnen der Funktionen der io.dll-------------------
StartZeit=ElapsedMilliseconds()
Repeat
CallFunctionFast(AdrPortOut, PortNum,220); write 80h to port 378h
Ergebnis.b=CallFunctionFast(AdrPortIn, PortNum)
INC j
Until j = 360000
StopZeit=ElapsedMilliseconds()
Zeit = StopZeit - StartZeit
Zahl$ = StrF(Zeit)
Ergebnis.b = MessageRequester("Zeit", Zahl$, #PB_MessageRequester_Ok)
;------------------------------------------------------------------------------------
However I am a bit suppriesed that the code is quite "slow"
Is it possible to increase the speed by modifieing the code or do I use a wrong way to write or read datas from the parallelport.
Thank a lot for your help
Martin
Parallelport programming
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Hi, I made saveral programs in PB to manage Parallel port under any windows, and it was all perfect, fast and nice. But is used Winio instead iodll.
You can download here: http://www.vb-fun.de/cgi-bin/downloadto ... omponenten
You need only these files:
WinIo.chm
WinIo.dll
WinIo.sys
WinIo.vxd
and WinIo.dll and WinIo.sys must be viewable by your .exe
You can download here: http://www.vb-fun.de/cgi-bin/downloadto ... omponenten
You need only these files:
WinIo.chm
WinIo.dll
WinIo.sys
WinIo.vxd
and WinIo.dll and WinIo.sys must be viewable by your .exe
-
- User
- Posts: 46
- Joined: Sat Jan 08, 2005 7:46 pm
Parallelport
Thank you very much for your help.
Do you have a small code that using the Winio.dll in PureBasic.
I would be great if you post it here.
Thanks
Martin
Do you have a small code that using the Winio.dll in PureBasic.
I would be great if you post it here.
Thanks
Martin
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
This is the smaller i found that i made 3 years ago for the company i was working. It is for test a hopper (a coin container used in coin automatic machines)
Code: Select all
;This program uses polling (not interrupt) method only.
;NOTE: it's necessary to amplify signals.
;Pay attention to the inversion of signals when amplified!.
;-Constants definitions
#AW_HOR_POSITIVE = $1 ;Animates the window from left To right. This flag can be used with roll Or slide animation.
#AW_HOR_NEGATIVE = $2 ;Animates the window from right To left. This flag can be used with roll Or slide animation.
#AW_VER_POSITIVE = $4 ;Animates the window from top To bottom. This flag can be used with roll Or slide animation.
#AW_VER_NEGATIVE = $8 ;Animates the window from bottom To top. This flag can be used with roll Or slide animation.
#AW_CENTER = $10 ;Makes the window appear To collapse inward If AW_HIDE is used Or expand outward If the AW_HIDE is not used.
#AW_HIDE = $10000 ;Hides the window. By default, the window is shown.
#AW_ACTIVATE = $20000 ;Activates the window.
#AW_SLIDE = $40000 ;Uses slide animation. By default, roll animation is used.
#AW_BLEND = $80000 ;Uses a fade effect. This flag can be used only If hwnd is a top-level window.
Procedure AW(wi,b,c) ;thanks to Timo (Freak)
Shared AW.b
If AW.b
OpenLibrary(1,"user32.dll")
CallFunction(1,"AnimateWindow",wi,b,c)
CloseLibrary(1)
Else
If c&#AW_HIDE:ShowWindow_(wi,#SW_HIDE):Else:ShowWindow_(wi,#SW_SHOW):EndIf
EndIf
EndProcedure
If OpenWindow(0, 300,300,260,60, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget,"HOPPER")=0
MessageBox_(0,"Something fails: i can't open window","Error",#MB_ICONSTOP)
End
EndIf
HideWindow(0,1) ;La escondo para que luego aparezca en pantalla todo a la vez
If CreateGadgetList(WindowID(0))=0
MessageBox_(0,"Something fails: i can't create gadgetlist","Error",#MB_ICONSTOP)
CloseWindow(0)
End
EndIf
ButtonGadget(1, 6,6, 50, 20, "LPT1",#PB_Button_Toggle):GadgetToolTip(1,"Pulsar aquí si está en LPT1")
ButtonGadget(2, 56,6, 50, 20, "LPT2",#PB_Button_Toggle):GadgetToolTip(2,"Pulsar aquí si está en LPT2")
ButtonGadget(3, 106,6, 50, 20, "LPT3",#PB_Button_Toggle):GadgetToolTip(3,"Pulsar aquí si está en LPT3")
DisableGadget(1,1):DisableGadget(2,1):DisableGadget(3,1)
ButtonGadget(5, 160,6, 90, 20, "Sacar moneda")
ButtonGadget(6, 6,30,90, 20, "STOP!")
;-INITS----------------------------------------------
AW.b=0
If OpenLibrary(1,"user32.dll")
If IsFunction(1,"AnimateWindow")
AW.b=1
EndIf
CloseLibrary(1)
EndIf
If OpenLibrary(0,"winio.dll")=0:MessageBox_(0,"Está instalado WinIO en este PC?"+Chr(10)+"No puedo abrir winio.dll !"+Chr(10)+Chr(10)+"NOTA:"+Chr(10)+"Es necesario tener WinIo.DLL, WinIo.VXD y WinIo.SYS en el mismo directorio que este ejecutable","Error",#MB_ICONQUESTION):End:EndIf
If CallFunction(0,"InitializeWinIo")=0:MessageBox_(0,"Está instalado WinIO en este PC"+Chr(10)+"Pero no se inicializa !","Error" ,#MB_ICONEXCLAMATION):End:EndIf
Gosub GetPortsAddr
Gosub GadgetReset
ActivateWindow()
AW(WindowID(),200,#AW_BLEND) ;Muestro todo el FrontEnd
;-MAIN------------------------------------------------
Repeat
Gosub Interact
Until EventID = #PB_EventCloseWindow
Gosub MOTOROFF
If LPTPort.w
Gosub LPTPortReset
EndIf
;-EXIT
AW(WindowID(),200,#AW_CENTER|#AW_HIDE)
CallFunction(0,"ShutdownWinIo")
CloseLibrary(0)
CloseWindow(0)
End
;-SUBRUTINAS----
Interact:
Delay(1)
EventID.l = WindowEvent()
If EventID=#PB_EventGadget
Select EventGadgetID()
Case 1 ;LPT1 button pressed
If LPTPort.w=LPT1Port
;LPT1 deselection:
Gosub LPTPortReset:Gosub GadgetReset
Else
;LPT1 selection:
LPTPort.w=LPT1Port:DisableGadget(2,1):DisableGadget(3,1):Gosub LPTPortSet
EndIf
Case 2 ;LPT2 button pressed
If LPTPort.w=LPT2Port
;LPT2 deselection:
Gosub LPTPortReset:Gosub GadgetReset
Else
;LPT2 selection:
LPTPort.w=LPT2Port:DisableGadget(1,1):DisableGadget(3,1):Gosub LPTPortSet
EndIf
Case 3 ;LPT3 button pressed
If LPTPort.w=LPT3Port
;LPT3 deselection:
Gosub LPTPortReset:Gosub GadgetReset
Else
;LPT3 selection:
LPTPort.w=LPT3Port:DisableGadget(1,1):DisableGadget(2,1):Gosub LPTPortSet
EndIf
Case 5
If LPTPort.w
Gosub MOTORON ;MOTOR ON
EndIf
Case 6
Gosub MOTOROFF
EndSelect
EndIf
If LPTPort.w
Gosub Refresh ;Mirar si hay flanco de pulso
If OUT<>OUTa:Gosub MOTOROFF:OUTa=OUT:EndIf
EndIf
Return
LPTPortSet:
ECP=0
CallFunction(0,"SetPortVal",LPTPort.w+2,$E4,1):Delay(10)
CallFunction(0,"GetPortVal",LPTPort.w+2,@a,1)
If a&$ff<>$E4:ECP=1
;entonces ECP mode
CallFunction(0,"SetPortVal",LPTPort.w+$0402,$34,1):Delay(10) ;if LPT is in ECP mode, then degrade it to Bi-Directional mode
EndIf
CallFunction(0,"SetPortVal",LPTPort.w+2,$84,1):Delay(10) ;set LPT port to OUTPUT mode
Return
LPTPortReset:
CallFunction(0,"SetPortVal",LPTPort.w+2,$84,1):Delay(10) ;release LPT port to default (OUTPUT) mode
If ECP:CallFunction(0,"SetPortVal",LPTPort.w+$0402,$14,1):Delay(10):EndIf ;restore LPT to ECP mode
Return
GetPortsAddr:
CallFunction(0,"GetPhysLong",$00000408,@LPT1Port):LPT1Port&$FFFF ;Obtiene la dirección física I/O de LPT1
CallFunction(0,"GetPhysLong",$0000040a,@LPT2Port):LPT2Port&$FFFF ;Obtiene la dirección física I/O de LPT2
CallFunction(0,"GetPhysLong",$0000040c,@LPT3Port):LPT3Port&$FFFF ;Obtiene la dirección física I/O de LPT3
Return
GadgetReset: ;cuando no hay seleccionado ningun puerto:
OUTa=0:OUT=0:ECP=0
LPTPort.w=0 ;reseteamos variables
If LPT1Port:DisableGadget(1,0):EndIf ;actualizamos los botones de seleccion de puerto (LPT1, LPT2 y LPT3)
If LPT2Port:DisableGadget(2,0):EndIf
If LPT3Port:DisableGadget(3,0):EndIf
Return
Refresh: ;Mirar si hay flanco de pulso
CallFunction(0,"GetPortVal",LPTPort+1,@OUT,1):OUT>>6&1
Return
MOTORON:
CallFunction(0,"SetPortVal",LPTPort.w,$20,1) ;MOTOR ON
Return
MOTOROFF:
CallFunction(0,"SetPortVal",LPTPort.w,$00,1) ;MOTOR OFF
Return