reading/writing to the parallel printer port

For issues with communication ports, protocols, etc.
Post Reply
keven
Posts: 6
Joined: Jul 20, 2021 11:47

reading/writing to the parallel printer port

Post by keven »

Hi...
I'm new here but I'm old Qbasic hacker...
I have written a program in Qbasic that reads and writes data to LPT1:

'Identify the LPT1 Address
DEF SEG = 0
pdata% = PEEK(&H408) + PEEK(&H409) * 256
IF pdata% = 0 THEN
PRINT " LPT1 not found"
SHELL "pause"
END
ELSE
PRINT " LPT1 found at &H"; HEX$(pdata%)
pstatus% = pdata% + 1
END IF
that worked with a line printer cable connected to a PC with a printer port running in a DOS environment.

Now I have a "newer" PC and a USB cable which has a parallel printer connector to an old dot matrix printer.
prints great with this Freebasic Code:

' Send some text to the Windows printer on LPT1:, using driver text imaging.
Open Lpt "LPT1:EMU=TTY" For Output As #1
Print #1, "Testing!"
Close

if freebasic can send data to LPT1(via the printer driver), is it also possible to send/read data from LPT1 at the connector pin level?

like this in Qbasic?:
' write a hex F8 to output port 378 to set pins 5,6,7 & 8 &(9)to hi
OUT pdata%, &HF8
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: reading/writing to the parallel printer port

Post by MrSwiss »

Simply put: only DOS allowes "direct HW (hardware) access".

All the other more modern OS's (operating systems) don't do that, in fact they "protect against direct HW access".
You'll have to use something like: in "Try to use inpout32.dll" thread to achieve that (on windows).
Read from there to the current tread-end (it's otherwise far too long ...).
keven
Posts: 6
Joined: Jul 20, 2021 11:47

Re: reading/writing to the parallel printer port

Post by keven »

keven wrote:
like this in FreeBasic?:

Dim pdata as integer
Lib inpout32.dll
pdata=888 ‘hex 378
‘ write a hex F8 to output port 378 to set pins 5,6,7 & 8 to hi
OUT pdata, &HF8
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: reading/writing to the parallel printer port

Post by MrSwiss »

You'll need both, the driver and the .dll ...
the .dll alone is not changing anything (it comunicates with the driver).

Q: How to use it? A: Read the documentation driver/.dll ...
keven
Posts: 6
Joined: Jul 20, 2021 11:47

Re: reading/writing to the parallel printer port

Post by keven »

Henrik Haftmann has written a version of inpout32.dll that can be used to replace the existing windows version. The interface to the parallel port is seamless as a driver is included in the dll. I guess I wouldn’t need to reference the dll, just execute the inp and out commands to parallel port address (defaulted to hex 378).
I be trying it out tomorrow... mite have to use the 64 bit version.
keven
Posts: 6
Joined: Jul 20, 2021 11:47

Re: reading/writing to the parallel printer port

Post by keven »

run this to compile:
C:\FreeBasic\FreeBASIC-1.08.1-winlibs-gcc-9.3.0\fbc64.exe –l inpoutx64.dll C:\LapCounter\TEST_FOLDER\MY4LANK1.bas

get this error message:
C:\FreeBasic\FreeBASIC-1.08.1-winlibs-gcc-9.3.0\bin\win64\ld.exe: cannot find -linpoutx64.dll

inpoutx64.dll is in the TEST_FOLDER as well as being located in the C:\Windows\SysWOW64 folder.....

what's going wrong?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: reading/writing to the parallel printer port

Post by MrSwiss »

Put a copy of the .dll to: [FBC-Dir]\lib\win64\ folder (the compiler needs it there).
Except you have the correct .dll.a file (in-/export library).

To run the compiled .exe, the .dll should be in the same folder ...
keven
Posts: 6
Joined: Jul 20, 2021 11:47

Re: reading/writing to the parallel printer port

Post by keven »

Mr. SWiss (or anyone else that mite know):

whats a InpOutx64.dll.a file?

and should it be here?:
C:\FreeBasic\FreeBASIC-1.08.1-winlibs-gcc-9.3.0\lib\win64
keven
Posts: 6
Joined: Jul 20, 2021 11:47

Re: reading/writing to the parallel printer port

Post by keven »

do I also need to put the inpout64x.lib some where for this to compile successfully?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: reading/writing to the parallel printer port

Post by MrSwiss »

InpOutx64.dll.a = in-/export library (description what a .dll contains)
If you don't have one, use the: InpOutx64.dll (instead)
keven wrote:and should it be here?:
C:\FreeBasic\FreeBASIC-1.08.1-winlibs-gcc-9.3.0\lib\win64\...
Yes, correct. This is just for compiling.
Read my previous post again until you understand it's meaning.
Post Reply