Parallel Port
-
- Posts: 3
- Joined: Dec 01, 2009 4:14
Parallel Port
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
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
-
- Posts: 3
- Joined: Dec 01, 2009 4:14
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
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
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!).
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!).
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
-
- Posts: 3
- Joined: Dec 01, 2009 4:14
-
- Posts: 43
- Joined: Sep 23, 2005 0:37
I think it is advisable to use an "add-in" parallel card on these projects, never use the mainboard's built-in port.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!).