File: PR650init.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (53 lines) | stat: -rw-r--r-- 1,730 bytes parent folder | download | duplicates (4)
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
function retval = PR650init(portNumber, enableHandshaking)
% retval = PR650init(portNumber, [enableHandshaking])
% 
% Initialize serial port for talking to colorimeter.
% Returns whatever character is sent by colorimeter
%
% 'enableHandshaking' allows you to enable handshaking.  By default,
% handshaking is disabled.  To enable handshaking, set this value to 1 or
% true.
%
% 11/26/07    mpr   added timeout if nothing is returned within 10 seconds.
%
% In my experience, calling this function directly leads to poor performance
% (usually no communication is ever established).  You should find the function
% CMCheckInit in the PsychHardware folder, one folder up the tree from this one
% (which is presumably PR650Toolbox).  Calling this function from CMCheckInit
% should provide more reliable establishment of contact and hints on what to 
% try if contact fails.  -- MPR
 
global g_serialPort;

if nargin == 1
  enableHandshaking = 0;
end

if enableHandshaking
  handshakeCode = 'Lenient DontFlushOnWrite=1 FlowControl=Hardware ';
else
  handshakeCode = 'Lenient DontFlushOnWrite=1 FlowControl=None ';
end

% Only open if we haven't already.
if isempty(g_serialPort)
  oldverbo = IOPort('Verbosity', 2);
  hPort = IOPort('OpenSerialPort', portNumber, handshakeCode);
  IOPort('Close', hPort);
  WaitSecs(0.5);
  hPort = IOPort('OpenSerialPort', portNumber, handshakeCode);
  IOPort('Verbosity', oldverbo);
  g_serialPort = hPort;
end

StartTime = GetSecs;

% Send set backlight command to high level to check
% whether we are talking to the meter.
IOPort('write', g_serialPort, ['b3' char(10)]);

% Make sure the meter responds.
retval = [];
while isempty(retval) && GetSecs-StartTime < 10
  retval = PR650serialread;
end