Parallel Port
Here i will deal with parapllel ports in C,vb and MATLAB 7.0
Parallel ports are the 25 pin cute things that you will find behind your computer pannel. here is a picture below to show you the pin categories. Basically they are split into three categories.The control pins,status and data pins (as shown below).

Now dataports and status ports (pins actually) can be used for input and oputput data and the status are used by the computer to find out the status of an external device and thus can serve a good input port. Actually speaking mostly all these can be used for input and output but you can't use output to status pins. (*If your ports don't work just check your BIOS there will be a option to elect ports as bidirectional so just enable that option).
If you are using any os of higher than 'Me' your ports are protected for security reasons and thus you need to open it.You can get port opennig software called userport.sys . just open it and execute it and you can see it show this.

To monitor you port pin status just download a software caller parmon with which you can monitor your ports status and it looks as shown below

now in the above image you can see that all data pins are LOW(GREEN) and all HIGH(RED 5v). now you can see that all of the data port are all '0' and the status pins are '1' high. Note that the control pins donot indicate the actual number in the "DEC" column in the monitor screen since they are negative logic.
Here below shows that all data pins are high, a value 255 and the next having a value254

Start with C
in c adressing the port is very simple. just use the syntax outportb(address,value). Firstly note that the value is in hex i,e 255 is "FF" and here is how you will fiond the addess. check the 'Device manager' and click properties of 'COM1' which will show you this:

Normally we can use use '0×03FB' in plave of address. So outport(0×03FB,0xff); will output value "FF" to the data pins.of the parallel port.
To get an input from the port use : b = inportb(address) ; where bwill be a user defined variable. now this ends the discussion about C.
PORT ADDRESSING IN VB
download this DLL file and put it in the 'system' folder in your computer. now open a VB project and open a module and type in the followingin the plain module region.
Declare Sub vbOut Lib "WIN95IO.DLL" (ByVal nPort As Integer, ByVal nData As Integer)
Declare Sub vbOutw Lib "WIN95IO.DLL" (ByVal nPort As Integer, ByVal nData As Integer)
Declare Function vbInp Lib "WIN95IO.DLL" (ByVal nPort As Integer) As Integer
Declare Function vbInpw Lib "WIN95IO.DLL" (ByVal nPort As Integer) As Integer

now open a form and make a command button 'command1' and a textbox 'text1' now the following will letyou outputthe value to port (NOTE IT IS IN DECIMAL VALUE).
vbOut 888,255 <– here 888 suggests Data port (890 for control) and 255 is the data [variable]=vbInp([port]) <-- here the data from specifid port will be read to the vriable.

That's there.. i gues you all got it.
NOW MATLAB
Now the sad part is this all will work onlt in MATLAB 7.0 of greater version. now it is very simple. the following four lines will work to give you output.
open = daqhwinfo('parallel')
DIO1 = digitalio('parallel','LPT1');
DIO2 = digitalio('parallel','LPT1');
outreg = addline(DIO1, 0:7, 0, 'out');
inreg = addline(DIO2, 0:4, 1, 'in');
outreg is the variable in which output value will be put into by MATLAB and sent to ports and inreg is port to which the input value will be saved. now the '0:7' represents 8 pins of dataport and '0:4' represents 5 pins of status port.
putvalue(DIO1.Line(2),1) puts the value to line number "2" of the DIO1 configured port and the poutput value is 1.
getvalue(OBJ) will get the input value. incase u need help for this also just hold on.. today i'm a bit too tired and i'l put it up later.
–Have a nice day controlling your Parallel Ports.!! and please give your comments
nanoware said
WoW!
thank U very mUchchchchchch
i finally read a bit from pin data.1
again thnx
just a problem in yr page: i cant c images
i use firefox 1.5
very nice site
good luck
bye
madan said
oh thanks for that. but i see no problems with the pictures. can u send me a screenshot of how it looks to you to my mail id. madankumar.t@gmail.com
James said
Useful site, if I am to conroll individual pins of the parallel port via Matlab does the “daqhwinfo(‘parallel’)” mean I must have the data acquisition toolbox?
invobot said
yeah you’l still have to use those
abd said
hi
how can I use the port0 of LPT port as bidirectional, i.e. as in/out, in MATLAB. I hope to get answer. thanks.
my e-mail: nesleman4048@yahoo.com
madan said
@adb : i guess that should be done by your program on runtime. make it out when u wnaa out a value. and “in” when u expect some data from external device or something. Simultaneously biderectional i’m not sure of. sorry
Asaf said
I’m trying to use the data pins to input information to my computer. I’m using matlab and when I try to read the port I can only read the las value I assigned to it. The code I’m using is
open = daqhwinfo('parallel')
DIO1 = digitalio('parallel','LPT1');
inreg = addline(DIO1, 0:7, 0, 'in');
getvalue(DIO1)
I have all ready configured my BIOS settings but i just can’t get it to work.
Any suggestions?
haloola said
hi
just wantd 2 thank u on ur great work u really made my life easier
thx again
fayyaz said
hiz thts a realy a wonderful work
it helps a lot in ma porkject…..
Rakesh Babu G R said
Check this out guys.
http://www.mathworks.com/company/newsletters/digest/sept02/centronics.html
shivesh said
hi, thanks to provide usefull inforamation regardin PP.
I want to aquire digital value using Parallel port, but i am getting only last value. it is possible save all descrete value and reuse it.
Madan said
Hey man if the time doesnt synchronise then you’l get odd values only. To help you better may i know from where are you acquiring the datas?
Image capture using Webcam in Matlab « Madan said
[...] Parallel Port [...]
FERI-INDONESIA said
HI..
i have enjoyed explored programming MATLAB with PPI8255, but i confuse how to send configuration like mode, access port A,B,C. if other program like pascal, delphi, assembler. they send configuration through address 378 and 37A. i don’t how to do like that in MATLAB. i have though if port (0)/ port (1) and port(2) is adddressed to 378,379 and 37A so we can direct send configuration and data to its port. OK, hope for your helping. send your comment to my email..if you not feel weight
[feriyonika, student at GAdjah Mada University, major Electrical Enginering.30march07]
madan said
@FERI
Well i think you are just asking about how to address 8255 from matlab when you can just control the line pins. let me know if this is what you want to ask or anything different.
As far as i know the lines can only be individually controlled thus might not produce the required results witha 8255. I’l like to get into more detils with this question so i’l be happy if you can get ack here and put your ideas in.
Thanks
Madan
andres said
I Need acces the bit5 of control buffer
how I will do this to control the port 0 as bidireccional ?
andres said
To Asaf
If you set the bit 5 of the control buffer by other program as vB of Labview you will reed by matlab the port 0
shaktipada sarkar said
how can i write simulink output to parallel port
shaktipada sarkar said
hi,thanks to providing useful information on parallel port.now i want to write simulink output to matlab.please give information how can i do it.my email id sarkar_shaktipada@yahoo.co.in
NeoDeGenero said
Hi, this is great stuff.
Although i’m stumped at trying to write a string or a character to the Parallel Port (matlab)
Things i want to write are: eg. “F”, or more complicated “I -200 200 450 1000 54 54 68″
Would appreciate any help with writing strings in Matlab OR C to the parallel port.
Thanks!
email: neo_skool@hotmail.com
thammu said
My question is similar to ’shaktipada sarkar’. Is there a way for simulink model to read and write USB port.
gaurav said
hey i downloaded user port and executed too and when i start it,it shows driver not installed.may i know which driver its talking about.
madan said
Did u put the DLL file into the sys folder?
abhi said
hey dude…… fabulous work
asjid ali said
i want to control stepper motor or a relay with paralell port but data write or read must be throuh web site.i mean to say taht data should be sent from anywhere and relay that is attached a pc should be controlled.plz i am worried about it help m efor my project.
Ib / Vce(sat) said
well that was my final year project.
Hint : You can do it with php (You can call system functions from php directly)
good luck
Abdul Rahman said
thnx man it helped me alot in my project
Raymundo said
How i can send and recive 8 bits, because i use Simulink to control a system, I use a pin 2 to 9 to send y 10 to 17 to recive.
Some people told me that I have to make a S-Function.
Thanks for help me.
Sorry my English is pure
Alok said
Thank you very much for your suggestion.
Its working nicely
prathibha said
hi
please can someone tell me how to set bit 5 of control register of parallel port using matlab?
liyasa said
i want to store the data acquired through parallel port to a matrix. i am getting the data in a loop, but i need to store that data to a matrix and then to show that matrix as an image.
kindly help me
i am really stuck.
madan said
@liyasa
wow that was a god one… but thar shud be simple if u just put some thot to it….
Read some sinal to say u are sending a 8 bit data.. read port ten and sequentially keep saving it in the matrix…
Salil Banerjee said
Could u please tell me how can i control a parallel port using simulink.
leo said
hi.. gud day.
im want connect a LED to parallel port pin number 1, i want to control LED on/off..
please give some tips to do that.
leo said
hi.. gud day.
i want to connect a LED to parallel port pin number 1, i want to control LED on/off..
please give some tips to do that.
what is the output voltage coming from parallel port?
tahir said
Hello Sir,
thanks for this trivial info. i have a problem that i want to recieve optical encoder data through parallel port and want to use it in Matlab .Length of data is more then 1 pulse (say 500 pulses per second).can you please guide me how to do it.
tahir said
Hello Sir,
thanks for this trivial info. i have a problem that i want to recieve optical encoder data through parallel port and want to use it in Matlab .Length of data is more then 1 pulse (say 500 pulses per second).can you please guide me how to do it….. Tahir
gaurav rajoria said
hello to all,
i am working on my project in MATLAB and i want to give input through parallel port, and want to use them..
how can i do it?
please help
lotfi said
please help ,i use matlab with my laptop which doesn,t have lpt port ,i got usb 2 lpt cable but windows recognise it as “usb printer support ” not as ordinary lpt port,matlab didn,t recognise any lpt port
alok said
thanks……………
raghu said
how to read data lines D0-D7……?
raghu said
Can i do the same with matlab 6.5 version….?
raghu said
how to set the bidirectional bit in control register…i.e.how to access control register through matlab..?
mamtha said
how to configure data lines of parallel port as ‘in’ and read data from it using matlab 6.5… plz reply soon….
samy said
hi i have to control two stepping motor with PC via parallel port and i have the peogram source writen in boolean with C3.0. and i need the graohic software (DUALSTEP.EXE)to run my program.
Stefán Þ. said
Hi. I am trying to get information from a Pulse Oximeter through a parallel port into matlab, but I am having difficulties reading the data off it. I get values from the getvalue(obj) command but it seems to be static, id est it doesnt matter if it is pluged in or not , and it doesn’t matter if i have it in an active state. The reading is [1 1 1 1 0] for the status pins, 0 being the busy signal, and the data pins all give ones’s. Does anybody have an explaination of this?
Archie rono said
Can you pls tell me the codes on how to transmit 5 volts using parallel ports/com port/usb port. thanks!
Shit master said
Wtf man! Fabulous work??? there is no fucking work here. NOTHING WORKS!!!
DickCrunch
Wayne VEra said
Hi
I have created a application that reads off a photocell sensor that is place on a race track, and records race car laptimes. The application work fine, but I have noticed that on certain desktop or laptop computer the Status pins S3, S4 and S5 are high, with out any parallel port pluged into the computer. My application reads off status pin S3 for the sensor, but doesnt work when the status pin is set high on certain computers.
Any way I can set the status pins to be low when the application starts? And why is this happening?
Thanks
Javad Ahamad K.v said
this is very very usfull site
CK PATEL said
i want 3 or more stepper moter via lpt port interfacing in turo c coding circuit
Satish Sinha said
it’s really informative site…thanx madan!
but plz checkout why in some pages there is no image
i.e. the ckt diagrams don’t appear.
bcoz of this i am not able to get the ckt of h-bridge what u gave in ur next page… plz if u can send it to my mail..
rajesh said
HI
I am allso doing proj on interfacing with matlab but i don`t no how to interfac it plz help me . i want to move the dc motor
farhad said
hi
i used the paraller port for pulse generation for driving stepper motor.but from the parralel port of pc ,the maximum sample per second is about 35HZ.now i need much more frequency than it.
can anyone help me that how can i reach the large frequency using MATLAB(paraller or serial or USB port).
PRIYA said
Please send me the matlab M-file to control the pc parallel port without using DAQ Hardware
for parallel processing .
haytham douba said
i want to cotrol in lpt by matlab can you help me please what i do thank for you
haytham douba
Norhazwani Hanoom said
Hi there,
I just wondering,what if I use USB parallel port, can I still use matlab to control the parallel port? thanks.
Norhazwani Hanoom said
Hi there,
I just wondering,what if I use USB parallel port, can I still use matlab to control the parallel port? thanks.
Reply
madan said
yeah you can
shresth said
how??
explain further plz..
Waqas Rashid said
i want to convert the webcam video stream into frames per second,i need the code following process,please send me the code of matlab
shresth said
i am using matlab 7.4 and i m not able to send data through usb 2 parallel port with my laptop.
the laptop treats usb 2 parallel port as a printer port n not a lpt port.n i am getting this :
open = daqhwinfo(‘parallel’)
open =
AdaptorDllName: [1x69 char]
AdaptorDllVersion: ‘2.10 (R2007a)’
AdaptorName: ‘parallel’
BoardNames: {1×0 cell}
InstalledBoardIds: {1×0 cell}
ObjectConstructorName: {0×3 cell}
wich means dat it is not detecting any lpt port.
can anyone tell me what to do to access the parallel port as earliest as possible????
thanx in advance.
reply 2 : shresthbhutani@gmail.com
Elamaran said
hello everyone.!!
i’m facing the same problem that mentioned above. I need to use USB to parallel port converter for my project. I need the codes for interfacing it with matlab. Can any one give your idea pls…??