~ubuntu-branches/ubuntu/trusty/psychtoolbox-3/trusty-proposed

« back to all changes in this revision

Viewing changes to Psychtoolbox/PsychHardware/CMCheckInit.m

  • Committer: Package Import Robot
  • Author(s): Yaroslav Halchenko
  • Date: 2013-11-19 23:34:50 UTC
  • mfrom: (3.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20131119233450-f7nf92vb8qavjmk8
Tags: 3.0.11.20131017.dfsg1-3
Upload to unsable since fresh glew has arrived to sid!

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
% meterType 2 is the CVI (need CVIToolbox) - Not yet implemented!
14
14
% meterType 3 is the CRS Colorimeter
15
15
% meterType 4 is the PR655
 
16
% meterType 5 is the PR670
 
17
% meterType 6 is the PR705
16
18
%
17
19
% For the PR-series colorimeters, 'PortString' is the optional name of a
18
20
% device string for the serial port or Serial-over-USB port to which the
20
22
% and built-in defaults to try to find the proper port: If there is a file
21
23
% 'CMPreferredPort.txt' in the search path of Matlab/Octave, it will parse
22
24
% that file for a PortString to use. Else it will use a hard-coded default
23
 
% inside this routine. If a calibration file with name 'PR650Ports' for the
24
 
% PR-650 colorimeter or 'PR655Ports' for the PR-655 colorimeter exists
25
 
% inside the PsychCalData folder, it will use the portname from that file.
 
25
% inside this routine.
 
26
%
 
27
% If a calibration file with name 'PRXXXPorts' for the PR-XXX exists,
 
28
% it will override what is in CMPrefferedPort.txt.  There are two
 
29
% possible formats for the structure in this file.
 
30
%   If the structure has a PortString field, this is passed to
 
31
%   routine FindSerialPort to get the actual port.  Otherwise,
 
32
%   if the structure has a .in field, this string is used directly.
26
33
%
27
34
% Other Colorimeters, e.g., CRS ColorCal, have their own specific setup
28
35
% methods and this routine just calls their setup code with default
29
36
% settings.
30
37
%
31
 
 
32
 
%
33
38
% 9/15/93 dhb           Modified to use new CMInit properly.
34
39
% 1/18/94 jms           Added gHardware switch
35
40
% 1/24/94 dhb           Changed sign of gHardware switch.
50
55
% 2/07/09  mk       Add experimental setup code for use of IOPort instead of SerialComm.
51
56
% 2/11/09  cgb,mk   Small fixes: Now we use IOPort instead of SerialComm --
52
57
%                   by default. Verified to work for both PR650 and PR655 toolboxes.
 
58
% 7/16/12  dhb      Choose right global default for 64-bit Matlab.  Hope I
 
59
%                   did this in a way that doesn't break anything else.
 
60
% 7/20/12  dhb      Undid 7/16/12 change.  Error was due to a stale IOPort on my path
 
61
% 12/04/12 zlb      Adding PR-705 support.
 
62
% 4/10/13  dhb      More flexible behavior supported via PRXXXPorts calibration file.
53
63
 
54
64
global g_serialPort g_useIOPort;
55
65
 
56
 
% If g_useIOPort == 1 the IOPort driver shall be used instead of SerialComm:
 
66
% Default method of serial communication
57
67
if isempty(g_useIOPort)
58
68
    g_useIOPort = 1;
59
69
end
63
73
 
64
74
% Read the local preferred serial port file if it exists.
65
75
if exist(which('CMPreferredPort.txt'), 'file')
66
 
        t = textread(which('CMPreferredPort.txt'), '%s');
67
 
        defPortString = t{1};
 
76
    t = textread(which('CMPreferredPort.txt'), '%s');
 
77
    defPortString = t{1};
68
78
else
69
 
    if IsOSX
70
 
        defPortString = 'usbserial';
71
 
    end
72
 
    
73
 
    if IsLinux
74
 
        defPortString = 'USB0';
75
 
    end
76
 
    
77
 
    if IsWin
78
 
        defPortString = 'COM5';
79
 
    end
 
79
    defPortString = '';
80
80
end
81
81
 
82
82
% Set default the defaults.
107
107
% function in lieu of meterports=LoadCalFile.  I am not intrepid enough to
108
108
% take that step.  -- MPR 11/21/07
109
109
 
110
 
 
111
110
switch meterType
112
111
    case 1,
113
112
        % PR-650
121
120
                error(['Unsupported OS ' computer]);
122
121
            end
123
122
        else
124
 
            portNameIn = meterports.in;
 
123
            if (isfield(meterports,'PortString'))
 
124
                portNameIn = FindSerialPort(meterports.PortString, g_useIOPort);
 
125
            else
 
126
                portNameIn = meterports.in;
 
127
            end
125
128
        end
126
 
 
 
129
        
127
130
        if IsWin || IsOSX || IsLinux
128
131
            stat = PR650init(portNameIn);
129
132
            status = sscanf(stat,'%f');
132
135
                disp('If colorimeter is off, turn it on; if it is on, turn it off and then on.');
133
136
            end
134
137
            NumTries = 0;
135
 
 
136
 
            while (isempty(status) || status == -1) & NumTries < DefaultNumberOfTries %#ok<AND2>
 
138
            
 
139
            while (isempty(status) || status == -1) && NumTries < DefaultNumberOfTries
137
140
                stat = PR650init(portNameIn);
138
141
                status = sscanf(stat,'%f');
139
142
                NumTries = NumTries+1;
140
 
                if (isempty(status) || status == -1) & NumTries >= 3 %#ok<AND2>
 
143
                if (isempty(status) || status == -1) && NumTries >= 3
141
144
                    if IsOSX
142
145
                        if ~g_useIOPort
143
146
                            evalc(['SerialComm(''close'',' int2str(portNameIn) ');']);
165
168
            error(['Unsupported OS ' computer]);
166
169
        end
167
170
    case 2,
168
 
        error('Support for CVI colormeter not yet implemented in PTB-3, sorry!');        
 
171
        error('Support for CVI colormeter not yet implemented in PTB-3, sorry!');
169
172
    case 3,
170
173
        % CRS-Colorimeter:
171
174
        if exist('CRSColorInit') %#ok<EXIST>
173
176
        else
174
177
            error('CRSColorInit command is missing on your path. Is the CRS color calibration toolbox set up properly?');
175
178
        end
 
179
        
176
180
    case 4,
177
181
        % PR-655:
178
182
        % Look for port information in "calibration" file.  If
185
189
                error(['Unsupported OS ' computer]);
186
190
            end
187
191
        else
188
 
            portNameIn = meterports.in;
 
192
            if (isfield(meterports,'PortString'))
 
193
                portNameIn = FindSerialPort(meterports.PortString, g_useIOPort);
 
194
            else
 
195
                portNameIn = meterports.in;
 
196
            end
189
197
        end
190
198
        
191
199
        if IsWin || IsOSX || IsLinux
200
208
            error(['Unsupported OS ' computer]);
201
209
        end
202
210
        
 
211
        % PR-670 - Functionality should be very similar to the PR-655, though
 
212
        %          it looks like there are a few more commands available for
 
213
        %          the 670.
 
214
    case 5
 
215
        if IsWin || IsOSX || IsLinux
 
216
            % Look for port information in "calibration" file.  If
 
217
            % no special information present, then use defaults.
 
218
            meterports = LoadCalFile('PR670Ports');
 
219
            if isempty(meterports)
 
220
                portNameIn = FindSerialPort(PortString, g_useIOPort);
 
221
            else
 
222
                if (isfield(meterports,'PortString'))
 
223
                    portNameIn = FindSerialPort(meterports.PortString, g_useIOPort);
 
224
                else
 
225
                    portNameIn = meterports.in;
 
226
                end
 
227
            end
 
228
            
 
229
            stat = PR670init(portNameIn);
 
230
            if strcmp(stat, ' REMOTE MODE')
 
231
                disp('Successfully connected to PR-670!');
 
232
            else
 
233
                disp('Failed to make contact.  If device is connected, try turning it off, type clear all, and then re-trying CMCheckInit.');
 
234
            end
 
235
        else
 
236
            error(['Unsupported OS ' computer]);
 
237
        end
 
238
        
 
239
        
 
240
        % PR-705
 
241
    case 6,
 
242
        if IsWin || IsOSX || IsLinux
 
243
            meterports = LoadCalFile('PR705Ports');
 
244
            if isempty(meterports)
 
245
                portNameIn = FindSerialPort(PortString, g_useIOPort);
 
246
            else
 
247
                if (isfield(meterports,'PortString'))
 
248
                    portNameIn = FindSerialPort(meterports.PortString, g_useIOPort);
 
249
                else
 
250
                    portNameIn = meterports.in;
 
251
                end
 
252
            end
 
253
            
 
254
            stat = PR705init(portNameIn);
 
255
            if strcmp(stat, [' REMOTE MODE' 13 10])
 
256
                disp('Successfully connected to the PR-705!');
 
257
            else
 
258
                disp('Failed to make contact.  If device is connected, try turning it off, type clear all, and then re-trying CMCheckInit.');
 
259
            end
 
260
        else
 
261
            error(['Unsupported OS ' computer]);
 
262
        end
 
263
        
203
264
    otherwise,
204
265
        error('Unknown meter type');
205
266
end