Using matlab to control LPT port

28 sec read

Download the following 4 files:

  1. porttalk.sys, copy to C:\WINDOWS\system32\drivers
  2. lptread.m
  3. lptread.mexw32
  4. lptwrite.mexw32

Copy the last three files to a directory where your matlab can access.

Your LPT port number is probably 0x378 (or 888). Assume lptport is the port number, then we use lptread to read from the port:

val = lptread(lptport)

and use lptwrite to write to the port

lptwrite(lptport, val)

As a real example, we want to control the step motor Gary created to investigate motion artifact in fMRI. Here is a sample code:

lptport = hex2dec('378');
dir = hex2dec('40');
data = hex2dec('20');
for ii=1:30
lptwrite(lptport, data+dir);
pause(0.005)
lptwrite(lptport, dir)
pause(0.005)
end

Author of lptread.m: Erik Flister, UCSD, 2006. Adapted from Andreas Widmann.

nirs2img, create an image file from NIRS data

Update 2021/2/27: If you find griddata3 not working, try to change griddata3 to griddata. I was asked where to get nirs2img script. Here it...
Xu Cui
51 sec read

mergefile.m – a MatLab script to merge CSV files

My wife asked me to write a script to merge some csv files she has. Usually this can be accomplished by a simple command in...
Xu Cui
35 sec read

xjview 9.6 released

In this version, we modified the templates for 3-D render view and use a high-resolution template. It also includes a few scalp view. You...
Xu Cui
31 sec read

5 Replies to “Using matlab to control LPT port”

  1. sorry, i couldnt access this command in matlab 7.you asked to download four file but it didnt work .there is a command error about lptread and lptwrite.

    if there are any solution different than this please re send

    thanx in advance
    sudip

  2. Undefined function or variable ‘lptwrite’.

    Error in lptdeneme (line 5)
    lptwrite(lptport, data+dir);

  3. I have Windows 64-bit, and the MATLAB cannot recognize the lptwrite function.
    I get the following error
    Undefined function or variable ‘lptwrite’.

    Does lptwrite only works on 32-bit? Could you please help me with this?

    Thanks,
    Nidhi

Leave a Reply to Xu Cui Cancel reply

Your email address will not be published. Required fields are marked *

Loading