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
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.
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.
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
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.
54
64
global g_serialPort g_useIOPort;
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)
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');
76
t = textread(which('CMPreferredPort.txt'), '%s');
70
defPortString = 'usbserial';
74
defPortString = 'USB0';
78
defPortString = 'COM5';
82
82
% Set default the defaults.
121
120
error(['Unsupported OS ' computer]);
124
portNameIn = meterports.in;
123
if (isfield(meterports,'PortString'))
124
portNameIn = FindSerialPort(meterports.PortString, g_useIOPort);
126
portNameIn = meterports.in;
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.');
136
while (isempty(status) || status == -1) & NumTries < DefaultNumberOfTries %#ok<AND2>
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
143
146
evalc(['SerialComm(''close'',' int2str(portNameIn) ');']);
165
168
error(['Unsupported OS ' computer]);
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!');
170
173
% CRS-Colorimeter:
171
174
if exist('CRSColorInit') %#ok<EXIST>
185
189
error(['Unsupported OS ' computer]);
188
portNameIn = meterports.in;
192
if (isfield(meterports,'PortString'))
193
portNameIn = FindSerialPort(meterports.PortString, g_useIOPort);
195
portNameIn = meterports.in;
191
199
if IsWin || IsOSX || IsLinux
200
208
error(['Unsupported OS ' computer]);
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
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);
222
if (isfield(meterports,'PortString'))
223
portNameIn = FindSerialPort(meterports.PortString, g_useIOPort);
225
portNameIn = meterports.in;
229
stat = PR670init(portNameIn);
230
if strcmp(stat, ' REMOTE MODE')
231
disp('Successfully connected to PR-670!');
233
disp('Failed to make contact. If device is connected, try turning it off, type clear all, and then re-trying CMCheckInit.');
236
error(['Unsupported OS ' computer]);
242
if IsWin || IsOSX || IsLinux
243
meterports = LoadCalFile('PR705Ports');
244
if isempty(meterports)
245
portNameIn = FindSerialPort(PortString, g_useIOPort);
247
if (isfield(meterports,'PortString'))
248
portNameIn = FindSerialPort(meterports.PortString, g_useIOPort);
250
portNameIn = meterports.in;
254
stat = PR705init(portNameIn);
255
if strcmp(stat, [' REMOTE MODE' 13 10])
256
disp('Successfully connected to the PR-705!');
258
disp('Failed to make contact. If device is connected, try turning it off, type clear all, and then re-trying CMCheckInit.');
261
error(['Unsupported OS ' computer]);
204
265
error('Unknown meter type');