Send Triggers via Parallel Port in Linux – using pp & ppMEX.c

This method is developed by Erik Flister. It is designed to read/write TTL levels on parallel port pins under Linux, win32 (using porttalk), or matlab32 on win64 (using io32). This method includes two code files: pp.m and ppMex.c.

The way to implement this method is easy, just to insert a line of code in your matlab script. To even simplify the triggering job, I wrote a function here to share. So you basically only need to input the triggers you want to send into the trigger.m function. For example, trigger(1); trigger(2).

Download all three files at here:

pp_ppMexDownload

trigger.m

function trigger(sti_trigger)

% [input] = pp(pins,[output],[slowChecks],[port],[address])
% pp(uint8([2 3 4 5 6 7 8 9]), [0 0 0 0 0 0 0 0], 0, uint8(0), uint64(53248));

if sti_trigger == 0
    bin_value = [0 0 0 0 0 0 0 0];
    pp(uint8([2 3 4 5 6 7 8 9]), bin_value, 0, uint8(0), uint64(53248));
end

if sti_trigger == 1
    bin_value = [1 0 0 0 0 0 0 0];
    pp(uint8([2 3 4 5 6 7 8 9]), bin_value, 0, uint8(0), uint64(53248));
end

if (1 < sti_trigger)&&(sti_trigger < 4)
    bin_value = strcat('000000',dec2bin(sti_trigger));
    bin_value = fliplr(bin_value);
    bin_value = bin_value - '0' ;
    pp(uint8([2 3 4 5 6 7 8 9]), bin_value, 0, uint8(0), uint64(53248));
end

if (3 < sti_trigger)&&(sti_trigger < 8)
    bin_value = strcat('00000',dec2bin(sti_trigger));
    bin_value = fliplr(bin_value);
    bin_value = bin_value - '0' ;
    pp(uint8([2 3 4 5 6 7 8 9]), bin_value, 0, uint8(0), uint64(53248));
end

if (7 < sti_trigger)&&(sti_trigger < 16)
    bin_value = strcat('0000',dec2bin(sti_trigger));
    bin_value = fliplr(bin_value);
    bin_value = bin_value - '0' ;
    pp(uint8([2 3 4 5 6 7 8 9]), bin_value, 0, uint8(0), uint64(53248));
end

if (15 < sti_trigger)&&(sti_trigger < 32)
    bin_value = strcat('000',dec2bin(sti_trigger));
    bin_value = fliplr(bin_value);
    bin_value = bin_value - '0' ;
    pp(uint8([2 3 4 5 6 7 8 9]), bin_value, 0, uint8(0), uint64(53248));
end

if (31 < sti_trigger)&&(sti_trigger < 64)
    bin_value = strcat('00',dec2bin(sti_trigger));
    bin_value = fliplr(bin_value);
    bin_value = bin_value - '0' ;
    pp(uint8([2 3 4 5 6 7 8 9]), bin_value, 0, uint8(0), uint64(53248));
end

if (63 < sti_trigger)&&(sti_trigger < 128)
    bin_value = strcat('0',dec2bin(sti_trigger));
    bin_value = fliplr(bin_value);
    bin_value = bin_value - '0' ;
    pp(uint8([2 3 4 5 6 7 8 9]), bin_value, 0, uint8(0), uint64(53248));
end

if sti_trigger > 127
    bin_value = dec2bin(sti_trigger);
    bin_value = fliplr(bin_value);
    bin_value = bin_value - '0' ;
    pp(uint8([2 3 4 5 6 7 8 9]), bin_value, 0, uint8(0), uint64(53248));
end

[update 2/12/2016]

An minor error was found in trigger.m and has been fixed.