Parallel Port

For issues with communication ports, protocols, etc.
Post Reply
Volker Alexander
Posts: 3
Joined: Dec 01, 2009 4:14

Parallel Port

Post by Volker Alexander »

Hello,
I am new or better unborn to FreeBASIC :) since I never used it so far.

Most important question for me is:
Can I succeed with FreeBASIC under WinXP in sending binary data to certains of the parallel port pins and reading data from other pins at the same time?

E.g.: Data pins 0 to 3 should be output for communicating with an external device, 4 to 7 should be input for reading feedback. Then writing and reading ones and zeros with FreeBASIC under WinXP to and from the parallel port...

Thank you in advance,
Volker Alexander
Antoni
Posts: 1393
Joined: May 27, 2005 15:40
Location: Barcelona, Spain

Post by Antoni »

Not an expert, but as the Hardware subforum has several threads on communicating with parallel port, I guess what you want to do is possible in FB.
Volker Alexander
Posts: 3
Joined: Dec 01, 2009 4:14

Post by Volker Alexander »

Hi Antoni,
thank you for your post. Is there any a little bit more specific information? Especially I would like to know whether it's possible to run the port half and half, that means 4 bit as output and at the same time 4 bit as input. Or do I have to re-open the port every data direction change?
Thanx,
Volker Alexander
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Post by phishguy »

Instead of using data pins for input, you can use the printer status pins.
You could theoretically use the data pins for input and output at almost the same time. However, it isn't very safe if you inadvertantly set one of the pins to a low output while sending a high signal from your external device (poof!).
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Post by Richard »

Code: Select all

'--------------------------------------
'  parallel port adapter interface 
'--------------------------------------
' DB25 Signal  Data  parallel Reg  Bit 
' pins name    dirn  register bit value
'--------------------------------------
'  2   data0   I/O   data     0     1  
'  3   data1   I/O   data     1     2  
'  4   data2   I/O   data     2     4  
'  5   data2   I/O   data     3     8  
'  6   data2   I/O   data     4    16  
'  7   data2   I/O   data     5    32  
'  8   data2   I/O   data     6    64  
'  9   data7   I/O   data     7   128  
'--------------------------------------
' 15  nError   In    status   3     8  
' 13  Select   In	 Status   4    16  
' 12 PaperOut  In    Status   5    32  
' 10   nAck	   In    Status   6    64  
' 11   busy    In    status   7   128  
'--------------------------------------
'  1  nStrobe  Out   Control  0    1   
' 14 Linefeed  Out   Control  1    2   
' 16 nInitial  Out   Control  2    4   
' 17 nSelPrtr  Out   control  3    8   
' 18-25	Ground
'--------------------------------------

Enum    ' these are all global integer constants
    ' addresses for the parallel port used
    LPT1 = &H378    ' IBM PC standards
    LPT2 = &H278    
    BaseAddress = LPT1      ' select your parallel port
    ParDataReg = BaseAddress + 0
    ParStatReg = BaseAddress + 1
    ParContReg = BaseAddress + 2
End Enum

' example output code
Out ParDataReg, 0   ' clear the data register
Out ParDataReg, 2   ' set bit 1 of the data register, value 2

' example input code
Dim As Integer d

d = Inp(ParStatReg) ' read all staus bits
print Hex(d,2)

d = d And 2     ' keep bit 1 only
print Hex(d,2)

sleep
Volker Alexander
Posts: 3
Joined: Dec 01, 2009 4:14

Post by Volker Alexander »

Thank you phishguy, thank you Richard!
Jim Barlow
Posts: 43
Joined: Sep 23, 2005 0:37

Post by Jim Barlow »

phishguy wrote:Instead of using data pins for input, you can use the printer status pins.
You could theoretically use the data pins for input and output at almost the same time. However, it isn't very safe if you inadvertantly set one of the pins to a low output while sending a high signal from your external device (poof!).
I think it is advisable to use an "add-in" parallel card on these projects, never use the mainboard's built-in port.
bfuller
Posts: 366
Joined: Jun 02, 2007 12:35
Location: Sydney, Australia

Post by bfuller »

never use the mainboard's built-in port
I'm curious, why did you say that? (I have my own thoughts about access to various pins etc, but wonder why you say it so convincingly)--can you list the reasons or is it just a gut feel opinion?
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Post by phishguy »

Actually, the only difference in risk is blowing up the built in port as opposed to an add in port. There is still a risk of blowing up your main board if you apply incorrect voltages. The safest thing to do is to add optoisolators to you inputs and outputs.
Post Reply