>Here's the Zipped compiled executable if you don't have PBforms
You do not need to have PBForms installed to compile code created by/using PBForms.
Announcement
Collapse
No announcement yet.
Accessing a printer port through a PCMCIA card
Collapse
X
-
I forgot to mention that Microsoft's parport.sys driver in XP has a lovely new 'feature' can interfere with port access as well. Every few seconds it polls each parallel port (why, I don't know). Doing so changes some bits in base_address + 2. You may want to add the following to your registry:
Code:Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Parport\Parameters] "ParEnableLegacyZip"=dword:00000001 "DisableWarmPoll"=dword:00000001
Code:#COMPILE EXE #DIM ALL '------------------------------------------------------------------------------ ' ** Includes ** '------------------------------------------------------------------------------ #INCLUDE "WIN32API.INC" #INCLUDE "COMMCTRL.INC" #INCLUDE "PBForms.INC" '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Constants ** '------------------------------------------------------------------------------ %IDD_PPD_MAIN = 1000 %IDC_PPD_FLBL = 1010 %IDC_PPD_FTB = 1011 %IDC_PPD_UHLBL = 1020 %IDC_PPD_UTB = 1021 %IDC_PPD_ULBL = 1022 %IDC_PPD_NTB = 1031 %IDC_PPD_NLBL = 1032 %IDC_PPD_WLBL = 1040 %IDC_PPD_W0TB = 1041 %IDC_PPD_H2 = 1042 %IDC_PPD_W1TB = 1043 %IDC_PPD_H4 = 1044 %IDC_PPD_RLBL = 1050 %IDC_PPD_R0LBL = 1051 %IDC_PPD_H3 = 1052 %IDC_PPD_R1LBL = 1053 %IDC_PPD_H5 = 1054 %IDC_PPD_P0LBL = 1060 %IDC_PPD_P1LBL = 1061 %IDC_PPD_CHK = 1070 '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Declarations ** '------------------------------------------------------------------------------ 'WINIO 'needs .DLL and .VXD for Win98, .SYS for Win2K 'DECLARE FUNCTION MapPhysToLin LIB "WinIo.dll" ALIAS "MapPhysToLin" _ ' (BYVAL PhysAddr AS LONG, BYVAL PhysSize AS LONG, BYREF PhysMemHandle AS LONG) AS LONG 'DECLARE FUNCTION UnmapPhysicalMemory LIB "WinIo.dll" ALIAS "UnmapPhysicalMemory" _ ' (BYVAL PhysMemHandle AS LONG, BYVAL LinAddr AS LONG) AS INTEGER DECLARE FUNCTION GetPhysLong LIB "WinIo.dll" ALIAS "GetPhysLong" _ (BYVAL PhysAddr AS LONG, BYREF PhysVal AS WORD) AS INTEGER 'DECLARE FUNCTION SetPhysLong LIB "WinIo.dll" ALIAS "SetPhysLong" _ ' (BYVAL PhysAddr AS LONG, BYVAL PhysVal AS LONG) AS INTEGER 'DECLARE FUNCTION GetPortVal LIB "WinIo.dll" ALIAS "GetPortVal" _ ' (BYVAL PortAddr AS INTEGER, BYREF PortVal AS BYTE, BYVAL bSize AS BYTE) AS INTEGER 'DECLARE FUNCTION SetPortVal LIB "WinIo.dll" ALIAS "SetPortVal" _ ' (BYVAL PortAddr AS INTEGER, BYVAL PortVal AS BYTE, BYVAL bSize AS BYTE) AS INTEGER DECLARE FUNCTION InitializeWinIo LIB "WinIo.dll" ALIAS "InitializeWinIo" () AS INTEGER DECLARE FUNCTION ShutdownWinIo LIB "WinIo.dll" ALIAS "ShutdownWinIo" () AS INTEGER 'DECLARE FUNCTION InstallWinIoDriver LIB "WinIo.dll" ALIAS "InstallWinIoDriver" _ ' (BYVAL DriverPath AS STRING, BYVAL Mode AS INTEGER) AS INTEGER 'DECLARE FUNCTION RemoveWinIoDriver LIB "WinIo.dll" ALIAS "RemoveWinIoDriver" () AS INTEGER DECLARE CALLBACK FUNCTION ShowPPD_MAINProc() DECLARE FUNCTION ShowPPD_MAIN(BYVAL hParent AS DWORD) AS LONG GLOBAL BasePort() AS WORD GLOBAL colr AS BYTE '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Main Application Entry Point ** '------------------------------------------------------------------------------ FUNCTION PBMAIN() REDIM BasePort(5) 'BasePort(0) is # of ports 'BasePort(1-4) port address 'BasePort(5) is port tested colr = 0 ShowPPD_MAIN %HWND_DESKTOP END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** CallBacks ** '------------------------------------------------------------------------------ CALLBACK FUNCTION ShowPPD_MAINProc() LOCAL i, j, k, l, m AS BYTE, p AS INTEGER, t AS STRING, n AS LONG SELECT CASE AS LONG CBMSG CASE %WM_INITDIALOG i = InitializeWinIo 'initialize WINIO (0 if fails) 'get parallel port structure & base addresses i = GetPhysLong(&H411, BasePort(0)) BasePort(0) = BasePort(0) AND 255 SHIFT RIGHT BasePort(0), 6 'printer port count FOR i = 1 TO BasePort(0) j = GetPhysLong(&H406 + ( 2 * i ), BasePort(i)) NEXT i BasePort(5) = BasePort(1) SELECT CASE BasePort(0) CASE 1 t =" 1 Port at: " + HEX$(BasePort(1),3) + "h" CASE 2 t = " 2 Ports at: " + HEX$(BasePort(1),3) + "h, " _ + HEX$(BasePort(2),3) + "h" CASE 3 t = " 3 Ports at: " + HEX$(BasePort(1),3) + "h, " _ + HEX$(BasePort(2),3) + "h, "+ HEX$(BasePort(3),3) + "h" CASE 4 t = " 4 Ports at: " + HEX$(BasePort(1),3) + "h, " _ + HEX$(BasePort(2),3) + "h, "+ HEX$(BasePort(3),3) + "h, " _ + HEX$(BasePort(4),3) + "h" CASE ELSE t = " No Parallel Ports Identified" 'force one BasePort(0) = 1 BasePort(5) = &H378 END SELECT CONTROL SET TEXT CBHNDL, %IDC_PPD_FTB, t CONTROL SET TEXT CBHNDL, %IDC_PPD_UTB, HEX$(BasePort(5),3) CONTROL SET TEXT CBHNDL, %IDC_PPD_W0TB, "AA" CONTROL SET TEXT CBHNDL, %IDC_PPD_W1TB, "55" CASE %WM_TIMER p = BasePort(5) ! mov dx,p ;set up PPort ! in al,dx ! mov k,al CONTROL SET TEXT CBHNDL, %IDC_PPD_R1LBL, HEX$(k,2) IF ISFALSE colr THEN CONTROL SET COLOR CBHNDL, %IDC_PPD_R1LBL, %RED, %WHITE colr = 1 ELSE CONTROL SET COLOR CBHNDL, %IDC_PPD_R1LBL, -1, %WHITE colr = 0 END IF CASE %WM_COMMAND ' Process control notifications IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = %BN_PAINT THEN KillTimer CBHNDL, %IDD_PPD_MAIN SELECT CASE AS LONG CBCTL CASE %IDC_PPD_UTB CASE %IDC_PPD_CHK CONTROL DISABLE CBHNDL, CBCTL CONTROL GET TEXT CBHNDL, %IDC_PPD_UTB TO t BasePort(5) = VAL("&h" + t) CONTROL SET TEXT CBHNDL, %IDC_PPD_UTB, HEX$(BasePort(5), 4) CONTROL GET TEXT CBHNDL, %IDC_PPD_NTB TO t n = MAX(VAL(t), 1) CONTROL SET TEXT CBHNDL, %IDC_PPD_NTB, FORMAT$(n) CONTROL GET TEXT CBHNDL, %IDC_PPD_W0TB TO t j = VAL("&h" + t) CONTROL SET TEXT CBHNDL, %IDC_PPD_W0TB, HEX$(j, 2) CONTROL GET TEXT CBHNDL, %IDC_PPD_W1TB TO t k = VAL("&h" + t) CONTROL SET TEXT CBHNDL, %IDC_PPD_W1TB, HEX$(k, 2) 'MSGBOX HEX$(BasePort(5),3) + ", " + hex$(j, 2) + ", " + hex$(k, 2) CONTROL SET COLOR CBHNDL, %IDC_PPD_R1LBL, -1, %WHITE colr = 0 i = SetPriorityClass(GetCurrentProcess(), %REALTIME_PRIORITY_CLASS) p = BasePort(5) ! mov ecx,n ! mov dx,p ;set up PPort fFor: 'FOR CX = FirstEl TO LastEl ! mov al,j ! out dx,al ;output w0 ! jmp here1 here1: ! jmp here1a here1a: ! in al,dx ! mov l,al ! mov al,k ! out dx,al ;output w1 ! jmp here2 here2: ! jmp here2a here2a: ! in al,dx ! mov m,al ! dec ecx ! jz TidyUp ! jmp fFor TidyUp: '! mov al,&h00 ;reset to 0 '! out dx,al i = SetPriorityClass(GetCurrentProcess(), %NORMAL_PRIORITY_CLASS) CONTROL SET TEXT CBHNDL, %IDC_PPD_R0LBL, HEX$(l,2) CONTROL SET TEXT CBHNDL, %IDC_PPD_R1LBL, HEX$(m,2) CONTROL SET CHECK CBHNDL, CBCTL, 0 CONTROL ENABLE CBHNDL, CBCTL SetTimer CBHNDL, %IDD_PPD_MAIN, 1000, BYVAL %NULL END SELECT END IF CASE %WM_DESTROY KillTimer CBHNDL, %IDD_PPD_MAIN i = ShutdownWinIo 'stop WINIO service END SELECT END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Dialogs ** '------------------------------------------------------------------------------ FUNCTION ShowPPD_MAIN(BYVAL hParent AS DWORD) AS LONG LOCAL lRslt AS LONG LOCAL hDlg AS DWORD LOCAL hFont1 AS DWORD DIALOG NEW hParent, "Parallel Port Diagnostic 1.0", 237, 180, 183, 75, _ %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR _ %WS_SYSMENU OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR _ %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT _ OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO _ hDlg DIALOG SET COLOR hDlg, -1, RGB(249, 240, 181) CONTROL ADD LABEL, hDlg, %IDC_PPD_FLBL, "Found:", 5, 5, 30, 15, _ %WS_CHILD OR %WS_VISIBLE OR %SS_RIGHT OR %SS_CENTERIMAGE, _ %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL SET COLOR hDlg, %IDC_PPD_FLBL, -1, -2 CONTROL ADD LABEL, hDlg, %IDC_PPD_FTB, "", 40, 5, 138, 15, %WS_CHILD OR _ %WS_VISIBLE OR %SS_LEFT OR %SS_CENTERIMAGE, %WS_EX_CLIENTEDGE OR _ %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL SET COLOR hDlg, %IDC_PPD_FTB, -1, %WHITE CONTROL ADD LABEL, hDlg, %IDC_PPD_ULBL, "Use:", 5, 20, 30, 15, _ %WS_CHILD OR %WS_VISIBLE OR %SS_RIGHT OR %SS_CENTERIMAGE, _ %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL SET COLOR hDlg, %IDC_PPD_ULBL, -1, -2 CONTROL ADD TEXTBOX, hDlg, %IDC_PPD_UTB, "", 40, 20, 29, 15, %WS_CHILD _ OR %WS_VISIBLE OR %ES_LEFT, %WS_EX_CLIENTEDGE OR %WS_EX_RIGHT OR _ %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR CONTROL ADD LABEL, hDlg, %IDC_PPD_UHLBL, "h", 70, 20, 5, 15, %WS_CHILD _ OR %WS_VISIBLE OR %SS_LEFT OR %SS_CENTERIMAGE, %WS_EX_LEFT OR _ %WS_EX_LTRREADING CONTROL SET COLOR hDlg, %IDC_PPD_UHLBL, -1, -2 CONTROL ADD LABEL, hDlg, %IDC_PPD_NLBL, "Rept:", 5, 35, 30, 15, _ %WS_CHILD OR %WS_VISIBLE OR %SS_RIGHT OR %SS_CENTERIMAGE, _ %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL SET COLOR hDlg, %IDC_PPD_NLBL, -1, -2 CONTROL ADD TEXTBOX, hDlg, %IDC_PPD_NTB, "1", 40, 35, 30, 15, %WS_CHILD _ OR %WS_VISIBLE OR %ES_LEFT, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR _ %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR CONTROL ADD TEXTBOX, hDlg, %IDC_PPD_W0TB, "", 113, 40, 16, 15, _ %WS_CHILD OR %WS_VISIBLE OR %ES_LEFT, %WS_EX_CLIENTEDGE OR _ %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR CONTROL ADD TEXTBOX, hDlg, %IDC_PPD_W1TB, "", 113, 55, 16, 15, _ %WS_CHILD OR %WS_VISIBLE OR %ES_LEFT, %WS_EX_CLIENTEDGE OR _ %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR CONTROL ADD CHECKBOX, hDlg, %IDC_PPD_CHK, "Check", 15, 55, 40, 15, _ %WS_VISIBLE OR %WS_TABSTOP OR %BS_PUSHLIKE OR %BS_CENTER OR _ %BS_VCENTER OR %BS_TEXT CONTROL ADD LABEL, hDlg, %IDC_PPD_WLBL, "Write", 110, 25, 25, 15, _ %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER OR %SS_CENTERIMAGE, _ %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL SET COLOR hDlg, %IDC_PPD_WLBL, -1, -2 CONTROL ADD LABEL, hDlg, %IDC_PPD_RLBL, "Read", 140, 25, 25, 15, _ %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER OR %SS_CENTERIMAGE, _ %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL SET COLOR hDlg, %IDC_PPD_RLBL, -1, -2 CONTROL ADD LABEL, hDlg, %IDC_PPD_P0LBL, "Pattern0:", 75, 40, 35, 15, _ %WS_CHILD OR %WS_VISIBLE OR %SS_RIGHT OR %SS_CENTERIMAGE, _ %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL SET COLOR hDlg, %IDC_PPD_P0LBL, -1, -2 CONTROL ADD LABEL, hDlg, %IDC_PPD_H2, "h", 130, 40, 5, 15, %WS_CHILD OR _ %WS_VISIBLE OR %SS_LEFT OR %SS_CENTERIMAGE, %WS_EX_LEFT OR _ %WS_EX_LTRREADING CONTROL SET COLOR hDlg, %IDC_PPD_H2, -1, -2 CONTROL ADD LABEL, hDlg, %IDC_PPD_R0LBL, "", 142, 40, 16, 15, _ %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT OR %SS_CENTERIMAGE, _ %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL SET COLOR hDlg, %IDC_PPD_R0LBL, -1, %WHITE CONTROL ADD LABEL, hDlg, %IDC_PPD_H3, "h", 159, 40, 5, 15, %WS_CHILD OR _ %WS_VISIBLE OR %SS_LEFT OR %SS_CENTERIMAGE, %WS_EX_LEFT OR _ %WS_EX_LTRREADING CONTROL SET COLOR hDlg, %IDC_PPD_H3, -1, -2 CONTROL ADD LABEL, hDlg, %IDC_PPD_P1LBL, "Pattern1:", 75, 55, 35, 15, _ %WS_CHILD OR %WS_VISIBLE OR %SS_RIGHT OR %SS_CENTERIMAGE, _ %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL SET COLOR hDlg, %IDC_PPD_P1LBL, -1, -2 CONTROL ADD LABEL, hDlg, %IDC_PPD_H4, "h", 130, 55, 5, 15, %WS_CHILD OR _ %WS_VISIBLE OR %SS_LEFT OR %SS_CENTERIMAGE, %WS_EX_LEFT OR _ %WS_EX_LTRREADING CONTROL SET COLOR hDlg, %IDC_PPD_H4, -1, -2 CONTROL ADD LABEL, hDlg, %IDC_PPD_R1LBL, "", 142, 55, 16, 15, _ %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT OR %SS_CENTERIMAGE, _ %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL SET COLOR hDlg, %IDC_PPD_R1LBL, -1, %WHITE CONTROL ADD LABEL, hDlg, %IDC_PPD_H5, "h", 159, 55, 5, 15, %WS_CHILD OR _ %WS_VISIBLE OR %SS_LEFT OR %SS_CENTERIMAGE, %WS_EX_LEFT OR _ %WS_EX_LTRREADING CONTROL SET COLOR hDlg, %IDC_PPD_H5, -1, -2 hFont1 = PBFormsMakeFont("MS Sans Serif", 10, 400, %FALSE, %FALSE, _ %FALSE, %ANSI_CHARSET) DIALOG SEND hDlg, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_UTB, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_NTB, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_W0TB, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_W1TB, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_CHK, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_FLBL, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_FTB, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_ULBL, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_NLBL, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_UHLBL, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_WLBL, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_RLBL, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_P0LBL, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_H2, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_R0LBL, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_H3, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_P1LBL, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_H4, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_R1LBL, %WM_SETFONT, hFont1, 0 CONTROL SEND hDlg, %IDC_PPD_H5, %WM_SETFONT, hFont1, 0 DIALOG SHOW MODAL hDlg, CALL ShowPPD_MAINProc TO lRslt DeleteObject hFont1 FUNCTION = lRslt END FUNCTION '------------------------------------------------------------------------------
Leave a comment:
-
Alan,
Accessing DLL's is easy (as long as they are documented correctly)
I had written a program in Power Basic for DOS that used to control scientific instrumentation using the 25 pin parrallel port. Most lapyots etc don't have these ports available anymore so I have started writing a new program using PB 7.0.
(Somebody with more knowledge than I will correct me if I am wrong with that statement) but from my knowledge, unless PBCC can access the pins directly while running under an "NT based" system and not a "Home based" system (which "SUPPOSEDLY" do not exist anymore....but we all know they do) , then you will need to rely on the documentation of the "Lower Level" driver to access the ports pins directly"
Leave a comment:
-
If you NEED legacy port addresses (03BC, 0378, 0278), I STRONGLY recommed the TransPC card (http://www.transdigital.net). It's about $90, and does not require any drivers for Windows 98/XP/Vista. If you can handle PNP addresses, there are $20 cards that work OK.
To get to them under Windows, use a ring0 driver like WINIO. Wrapper functions can be found in this forum. I use this setup to manage a medical device with great success.
Leave a comment:
-
>Are DLL's easy to access under PB Win 7.0 or later?
Yes.
If they provide a DLL, that's just a collection of FUNCTIONs and SUBs. You call them the same as procedures you write.
If they provide a DLL, 'somewhere' they must also be providing a list of functions and/or a 'header' file. The header file is more than likely NOT in PB-compatible syntax, so you will be looking at converting that.
You may have heard the term "API" thrown around somewhat freely here...
Header File + DLL(s) + description = Applications Program Interface.
Leave a comment:
-
Accessing a printer port through a PCMCIA card
Hi,
I had written a program in Power Basic for DOS that used to control scientific instrumentation using the 25 pin parrallel port. Most lapyots etc don't have these ports available anymore so I have started writing a new program using PB 7.0.
I have found a company called Transdigital.net that sells PCMCIA cards with a 25 pin port on the end for using a printer port on laptops etc.
They say: Add-on Standard Parallel Port for Notebook PCs to connect printers and other parallel devices ( JTAG chip programers, data acquisition, machine proces control, scientific measurement systems and software protection dongles).
:Installs as a fully featured bi-directional I/O mapped parallel port as LPT1, LPT2 or LPT3
They supply a driver for all the Windows versions and I was wondering if I can still access all of the 25 pins as I did under MS-DOS or up until Windows98 which still worked ok using the DOS program.
Has anyone had any experience in accessing DLL's or something that I could use to communicate with such a device?
Are DLL's easy to access under PB Win 7.0 or later?
Does anyone have any example code at all.
I have contacted the company and I am waiting for a reply.
Cheers
AlanTags: None
Leave a comment: