Invobot : Artificially intelligent

Lets make machines intelligent

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).

parallel port pins

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.

userport image

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

pram

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

pram pram

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:

device manager
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

module

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.

command

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

63 Responses to “Parallel Port”

  1. 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

  2. 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

  3. 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?

  4. invobot said

    yeah you’l still have to use those

  5. 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

  6. 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

  7. 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?

  8. haloola said

    hi
    just wantd 2 thank u on ur great work u really made my life easier
    thx again

  9. fayyaz said

    hiz thts a realy a wonderful work
    it helps a lot in ma porkject…..

  10. Check this out guys.
    http://www.mathworks.com/company/newsletters/digest/sept02/centronics.html

  11. 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.

  12. 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?

  13. [...] Parallel Port [...]

  14. 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]

  15. 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

  16. andres said

    I Need acces the bit5 of control buffer
    how I will do this to control the port 0 as bidireccional ?

  17. 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

  18. shaktipada sarkar said

    how can i write simulink output to parallel port

  19. 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

  20. 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

  21. thammu said

    My question is similar to ’shaktipada sarkar’. Is there a way for simulink model to read and write USB port.

  22. 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.

  23. madan said

    Did u put the DLL file into the sys folder?

  24. abhi said

    hey dude…… fabulous work

  25. 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.

  26. well that was my final year project.
    Hint : You can do it with php (You can call system functions from php directly)

    good luck

  27. Abdul Rahman said

    thnx man it helped me alot in my project

  28. 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

  29. Alok said

    Thank you very much for your suggestion.

    Its working nicely

  30. prathibha said

    hi
    please can someone tell me how to set bit 5 of control register of parallel port using matlab?

  31. 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.

  32. 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…

  33. Salil Banerjee said

    Could u please tell me how can i control a parallel port using simulink.

  34. 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.

  35. 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?

  36. 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.

  37. 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

  38. 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

  39. 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

  40. alok said

    thanks……………

  41. raghu said

    how to read data lines D0-D7……?

  42. raghu said

    Can i do the same with matlab 6.5 version….?

  43. raghu said

    how to set the bidirectional bit in control register…i.e.how to access control register through matlab..?

  44. mamtha said

    how to configure data lines of parallel port as ‘in’ and read data from it using matlab 6.5… plz reply soon….

  45. 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.

  46. 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?

  47. Archie rono said

    Can you pls tell me the codes on how to transmit 5 volts using parallel ports/com port/usb port. thanks!

  48. Shit master said

    Wtf man! Fabulous work??? there is no fucking work here. NOTHING WORKS!!!
    DickCrunch

  49. 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

  50. Javad Ahamad K.v said

    this is very very usfull site

  51. CK PATEL said

    i want 3 or more stepper moter via lpt port interfacing in turo c coding circuit

  52. 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..

  53. 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

  54. 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).

  55. PRIYA said

    Please send me the matlab M-file to control the pc parallel port without using DAQ Hardware
    for parallel processing .

  56. haytham douba said

    i want to cotrol in lpt by matlab can you help me please what i do thank for you
    haytham douba

  57. 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.

  58. 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

  59. 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

  60. 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

  61. 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…??

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>