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: sourceCode


trigger.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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.