Protocols‎ > ‎

Parallel port in matlab (via JAVA)

If you like to read the STATUS pins or write to the DATA pins of a parallel port, from within Matlab, you can do it using JAVA. At least in version 6 and higher java classes can be called from within Matlab. The matlab help suggests the parallel port can be accessed via the Sun Java commapi (javax.comm) classes. This may be true, but I could not read the status bits using this classes. On the internet I couldn't find any successful accounts of using these standard java extensions to do this.

Luckily, Juan Gabriel Del Cid Portillo wrote a java class that does work. You can find the class, driver and manual for linux in and for windows in (files attached to this page). Download and unzip the files. Then add the folder that is parent to the 'parport' folder containing the parallelport java class to matlab class path:
>> edit classpath.txt
and add a line (make sure there is no trailing white space at the end!)

For linux it is also necessary to add the parallelport library to matlab java library path 
>> edit librarypath.txt
and add line (make sure there is no trailing white space at the end!)

For XP (and possibly other versions of Windows) you need to give users control of the parallel port. For this you can use the UserPort utility, attached at the bottom of this page. Download and run it to give everybody access to the addres of the parallel port (usually address 0x378, check Windows/Settings/System for address of ports), and restart matlab. 

By default on Ubuntu, only root can read and write to the parallel port. While this should be possible to change, I did not manage easily. In want of a better solution, I run matlab as root by

$ sudo matlab

Usage in matlab:
import parport.ParallelPort; lpt1=ParallelPort( hex2dec('378') ) % adress 0x378 is usually starting address of LPT1, % can be checked via windows system settings status=dec2bin( % read status pins % if nothing connected: '01111111' % if all grounded: '10000111' % (highest) bit 7: pin 11 Busy INVERTED % bit 6: pin 10 Acknowledge % bit 5: pin 12 Out of Paper % bit 4: pin 13 Selected % bit 3: pin 15 I/O Error % bit 2: % bit 1: % bit 0:

Alexander Heimel,
Jun 14, 2013, 7:15 AM
Alexander Heimel,
Jun 14, 2013, 7:16 AM
Alexander Heimel,
Jun 14, 2013, 8:01 AM
Alexander Heimel,
Jun 14, 2013, 7:16 AM