LPT1 Port Access

For issues with communication ports, protocols, etc.
k7
Posts: 25
Joined: Aug 10, 2007 8:40
Location: Tasmania, Australia
Contact:

LPT1 Port Access

Postby k7 » Oct 18, 2007 5:25

Hello. I require a program that sends small integers to the LPT1/Parallel port. The computer is running Windows 2000 and I believe the port address is &378(hexadec). I have currently been using a QBasic program that used to work on a Win95 machine but I don't think it'll work the same because Win2000 doesn't allow DOS to access the hardware ports or something because it is emulated. Is my program possible in FB?
D.J.Peters
Posts: 8026
Joined: May 28, 2005 3:28
Contact:

Postby D.J.Peters » Oct 18, 2007 10:37

you can try Open LPT
http://www.freebasic.net/wiki/wikka.php ... yPgOpenLpt

or a dll

pport.bi

Code: Select all

Declare Function PPortIn Lib "inpout32.dll" Alias "Inp32" (ByVal PortAddress As short) As short
Declare Sub      PPortOut Lib "inpout32.dll" Alias "Out32" (ByVal PortAddress As short, ByVal Value As short)

and the dll
http://alice-dsl.net/d.j.peters/libs/inpout32.dll
(not tested)

Joshy
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Postby phishguy » Oct 18, 2007 11:30

Freebasic does allow access to the IO ports using INP and OUT commands. Just take note if the following:
Using true port access in the Windows version requires the program to install a device driver. For that reason, Windows executables using hardware port access should be run with administrator permits the first time. Further runs just activate the already installed driver. The driver hs only 3K in size and is embedded in the executable.


No need for special drivers or DLL's.
k7
Posts: 25
Joined: Aug 10, 2007 8:40
Location: Tasmania, Australia
Contact:

Postby k7 » Oct 19, 2007 11:57

Got it fixed!
Just used the original QB program, which just used the OUT command, and declared all the variables at the start and now it works exactly how it should. Why doesn't the QB program work though? Would it have anything to do with Windows 2000 restricting access to hardware ports for DOS/16-bit?
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Postby phishguy » Oct 19, 2007 12:24

Yes, when running a program that doesn't use a port driver to get around the restricted access you can't access the ports. Thus, QB can't access the ports and Freebasic can.


Why doesn't the QB program work though? Would it have anything to do with Windows 2000 restricting access to hardware ports for DOS/16-bit?
jtlodi
Posts: 3
Joined: Jan 02, 2008 22:50
Location: Rural Wisconsin, USA

Problem opening COM1:

Postby jtlodi » Jan 06, 2008 15:59

Thanks for posting your replies. However I'm still stumped.

Here's a little program that is supposed to open the COM1 port and return
a 'result' from the controller board attached to the serial port.
'-----------------------------------------------------
Dim Result As Byte
Result=Open Com ("COM1:9600,N,8,1" AS 1)
Print "Did the port open ?? (0=Yes) -->",result

' The 'result' prints as '2'
' according to the documentation, it should return either a 0 or -1 ?????
'-----------------------------------------------------------------------------------

This does run when I'm booted to DOS but not Windows XP so I must be missing something. It runs under QB just fine.

In phishguy's response he quoted:

Using true port access in the Windows version requires the program to install a device driver. For that reason, Windows executables using hardware port access should be run with administrator permits the first time. Further runs just activate the already installed driver. The driver is only 3K in size and is embedded in the executable.

Which device driver and where can I find it?
How do I link it to my program?
... or ...
am I supposed to be using the INP / OUT keywords instead of Print #1?

Regards,
jtlodi
coderJeff
Site Admin
Posts: 3184
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Postby coderJeff » Jan 06, 2008 17:48

The docs are wrong. No idea why I wrote that. 0=success, otherwise an error code. 2 indicates "file not found".

Error codes are in the wiki (should have a better page though):
http://www.freebasic.net/wiki/wikka.php ... KeyPgError

Is COM1 remapped to a different number under winXP? It should work same as QB. If not remapped you could try supressing some control lines with ,DS,RS,CS, options.

I assume you are using 0.18.3 since serial port access in DOS was not possible in earlier versions of FreeBASIC.
jtlodi
Posts: 3
Joined: Jan 02, 2008 22:50
Location: Rural Wisconsin, USA

Serial Port Access

Postby jtlodi » Jan 07, 2008 0:39

Thanks, CoderJeff ...

After I posted the question, I checked the running processes in the task manager and noticed that I already had a session of the FB program running.

When I canceled the process and tried rerunning the EXE ... it worked fine.

I'll bet this happened because I tried running the program without supplying power to the controller board on the other end of the serial cable. The program was searching for a response from the board. Of course I probably was a little impatient and closed the DOS window. Chalk this up to 'operator error'. The program works fine.

In another vein ... can you point me to sample code that shows how to utilize SUBs. I'm having trouble understanding the proper syntax to use in conjunction with type declarations.

Thanks,

jtlodi
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

man oh oooman

Postby thesanman112 » Mar 01, 2008 7:40

you guys that dont know about fb lpt1 and com...just tell me the bytes i need to send to the port....the time...the entire sequence of events that will be sent back....and i'll do the rest....
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

heres one answer

Postby thesanman112 » Mar 01, 2008 7:46

the reason there is file not found error,, or number two is because there is no printer attached to the port.

f1=freefile
open"lpt1" for random as f1
put #f1,9000,"1"
'print result2
sleep

can you tell me how to access the i2c programmer...like what I need to send it....understand????
edit:
heres a newer better question, what do i need to send to parrallel port l2c programmer to communicate with eeproms attached...anyone got some examples???
there must be a certain sequence of events, or certain bytes that get sent out that are a common control...like 'give me these bytes' but the word give meaning something, like a certain byte that is constant ,or maybe its just rec number and it gets returned to buffer...hmmmm
get out!!!

Return to “Hardware Interfaces / Communication”

Who is online

Users browsing this forum: No registered users and 1 guest