parallel port interfacing
TRANSCRIPT
PARALLEL PORT INTERFACING
SANDICO, ARWIN
SEVILLA, BRIGETTE MECCA
VALENZUELA, GEORGEN
VICTORIANO, RICHARD
VIZCARRA, JAMES DARWIN
GROUP 8
PARALLEL PORTRefers to processes that occur simultaneously.
Printers and other devices are said to be either parallel or serial. Parallel means the device is capable of receiving more than one bit at a time (that is, it receives several bits in parallel). Most modern printers are parallel.
Using function Inp32 and Out32 extremely need to reference to Address Printer Port in order to verify and send value in each bit of Printer Port that will be divided into 3 parts:
oDATAoSTATUSoCONTROL
Reference to Address Printer Port
1) DATA is the part that send data, 8 bit to Printer (also
computer) that we will control signal in each bit in order to
connect with printer for reference position of Data Port that will
equal to base printer port position.
LPT1 Data=H378 LPT2 Data=H278
2) STATUS is the part that verifies the status of printer such as the printer is error, out of paper, sending signal to work, etc. We can use Status Port to control equipment as Input (+5 Vdc) for reference of Data Port Data Port will equal to the position of base printer port+1. LPT1 Status=H379 (H378+1) LPT2 Status=H279 (H278+1)
3) CONTROL is the part that control working of printer such as Strobe, Auto linefeed, Select printer, etc. It can receive and sent data, 6 bit for reference position of Data Port will be equal to the position of base printer port+1 LPT1 Status=H37A(H378+2) LPT2 Status=H27A(H278+2)
the art of connecting computers and peripherals
COMPUTER INTERFACING?
THE PROBLEM:Writing programs to talk with parallel port was pretty easy in old DOS days and inWin95/98 too. We can use Inporb and outportb or _inp() or _Outp functions in our program withoutany problem if we are running the program on Dos or WIN95/98.
But entering to the new era ofNT clone operating systems like WIN NT4, WIN2000, WINXP, all this simplicity goes away.
There is a problemin writing a program that can talk to parallel port successfully in NT based operating systems.
WHY?
Is a family of Operating Systems produced by Microsoft
It was originally designed to be a powerful high-level-language-based, processor-
independent, multiprocessing, multiuser operating system
NT was the first fully 32-bit version of Windows
Windows 3.1x and Windows 9x, were 16-bit/32-bit hybrids
Windows 2000 Windows XP. Windows Vista, Windows 7 are based on Windows NT
WINDOWS NT
Being a very secure operating system, Windows NT assigns some privileges and restrictions to different types of programs running on it
It classifies all the programs in to two categories , User mode and Kernel mode
USER MODEPrograms generally
written falls in the user mode category.
Restricted to use certain instructions like IN, OUT etc..
Not restricted to such instructions
KERNEL MODE
write a kernel mode driver capable of reading and writing data to parallel port
and let the usermode program to communicate with it
THE SOLUTION:
"DLl"(Dynamic Link
Library)
collection of small programs, which can be called upon when needed by the executable program (EXE) that is running
The DLL lets the executable communicate with a specific device such as a printer
Is an executable file that cannot run on its own, it can only run from inside an executable file, eg. an engine of a car
START PROGRAMMING
Example 1:
Programming by using
Function Out and Inp
Output Port - Private Declare Function Private Declare Sub Out Lib "DllPort.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
Input Port - Private Declare Function Private Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Dim PortData ' variable for data at port
Const AddressLPT1 =&H378 'Constant for position of Printer Port 1(LPT1) and Data Port
Const Statusport1 =AddressLPT1+1 ' Constant for position of Status Port(LPT1))
Const Controlport1 =AddressLPT1+2 ' Constant for position of Control Port (LPT1))
Const AddressLPT2 =&H278 ' Constant for position of Printer Port 2(LPT2)และData Portt
Const Statusport2 =AddressLPT2+1 ' Constant for position of Status Port(LPT2)
Controlport2 =AddressLPT2+2 ' Constant for position of Control Port (LPT2))
For sending value via Parallel Port, you can do like this; Call Out (PortAddress,Data)
For getting value at Parallel Port
Inp (PortAddress)
So now, we will write code in control, starting to send value to control Parallel Port. You must put in Textbox and send value out by clicking at Command
Button, for getting value at port will show label.
Private Sub Command1_Click() PortData = Val("&H" & Text1.Text) 'count value in Textbox to put in variable PortData Call Out(AddressLPT1, PortData) ''send to Port Label1.Caption = Hex(Inp(AddressLPT1)) ''read value from I/O Port LPT1 as HexadenaryEnd Sub
Sending output signal
Sending value of PortAddress at Printer Port =&H378 Data that is value that send
to Printer Port by sending by use Hexadenary, but port will transform data as binary numeral system that has 8 bit
such as Hexadenary &H0F at Port =000011112 of binary numeral system.
Example 2:
Programming to get input signal from Printer Port
Function we use for getting data via Printer Status Port from DLL file (Dllport.Dll) needs reference Address Printer Status Port that will be Address from Printer Data Port that is added one position such as Address LPT1=H378 -->Status Port =H378+1=H379, etc.
LPT1 Status=H379 (H378+1) LPT2 Status=H279 (H278+1)
There will be the example of connecting signal like below
Option Explicit
Private Declare Function Inp Lib "Dllport.dll" Alias "Inp32" (ByVal PortAddress As Integer) As IntegerPrivate Declare Sub Out Lib "Dllport.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
We will find value when there will be signal in port by using And by permanent value in Decimal Number'like bit 0=1 | bit 1=2 | bit 2=4 | bit 3=8 | bit 4=16 | bit 5=32 | bit 6=64 | bit 7=128'When input is 1, there will be file is about 5 Vdc to which connector, it will show permanent value as Decimal Number
Private Sub Command1_Click()
Label1.Caption = (Inp(&H379)) And 8 ' 8 ' read value of error signal at bit’s position at 3 Label2.Caption = (Inp(&H379)) And 16 ' read value of Select signal at bit’s position at 4 Label3.Caption = (Inp(&H379)) And 32 ' read value of Select Paper Empty at bit’s position at 5 Label4.Caption = (Inp(&H379)) And 64 ' read value of ACK signal at bit’s position at 6 Label5.Caption = (Inp(&H379)) And 128 ' read value of Busy signal at bit’s position at 7' For condition that work in the case of having input signal, sending value out Data Port If Label1.Caption = 8 Then Out &H378, 1 ' sending signal out Data Port bit 0 If Label2.Caption = 16 Then Out &H378, 2 ' sending signal out Data Port bit 1 If Label3.Caption = 32 Then Out &H378, 4 ' sending signal out Data Port bit 2 If Label4.Caption = 64 Then Out &H378, 8 ' sending signal out Data Port bit 3 If Label5.Caption = 128 Then Out &H378, 16 ' sending signal out Data Port bit 4
End Sub
The example of program run: