1
function out = PR705config(varargin)
2
% PR705config - Update the PR-705 configuration.
5
% config_str (string) = PR705config
6
% errcode (scalar) = PR705config('Option1', value1, 'Option2', value2, ...)
9
% A wrapper for setting various options on the PR-705 using the 'S'
10
% command. With no input arguments, the function merely returns the device's
11
% current configuration string. In the multiple input arguments case, here
12
% are the case-insensitive options and the values they take:
13
% Lens ID Number of PRIMARY accessory
14
% Add1 ID Number of 1st ADD ON accessory
15
% Add2 ID Number of 2nd ADD ON accessory
16
% Aperture ID Number of Aperture
19
% ExposureTime 0 - Adaptive
21
% CaptureMode 0 - Single Capture
22
% 1 - Continuous Capture
23
% Cycles 1 .. 99 - Number of Captures to average
26
% TriggerMode 0 - Manual
28
% ViewShutter 0 - Open During Measurement
29
% 1 - Closed During Measurement
30
% CIEObserver 0 - 2 Degree
34
% errcode = PR705config('Lens', 0, 'Units', 1, 'Cycles', 2, 'ViewShutter', 1);
36
% 12/06/12 zlb Wrote it.
41
IOPort('Purge', g_serialPort);
43
out = PR705read(1, 100);
47
values = validate_sort_input(varargin);
49
setup_str = 'S%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d';
50
setup_str = sprintf(setup_str, values{:});
52
if length(setup_str) > 12 % i.e., 'values' had at least 1 non-empty element
53
IOPort('Purge', g_serialPort);
54
PR705write(setup_str);
55
errcode = PR705read(1, 10);
56
out = sscanf(errcode, '%d');
57
else % a noop is trivially successful
61
function sorted_values = validate_sort_input(raw_input)
62
valid_sorted_options = {'Lens' 'Add1' 'Add2' 'Aperture' 'Units' 'ExposureTime' ...
63
'CaptureMode' 'Cycles' 'CalcMode' 'TriggerMode' 'ViewShutter' 'CIEObserver'};
65
sorted_values = cell(size(valid_sorted_options));
66
if mod(numel(raw_input), 2)
67
fprintf('Expecting an even number of arguments (option-value pairs)!\n');
71
options = raw_input(1:2:end);
72
values = raw_input(2:2:end);
73
if ~all(cellfun(@ischar, options)) || ~all(cellfun(@isscalar, values))
74
fprintf('Improper formatting of the option-value pairs!\n');
78
[valid_members,location] = ismember(lower(options), lower(valid_sorted_options));
79
if ~all(valid_members)
80
invalid_options = options(~valid_members);
81
fprintf('The following options aren''t recognized and will be ignored:\n');
82
fprintf('\t%s\n', invalid_options{:});
85
values = values(valid_members);
86
location = location(valid_members);
88
sorted_values(location) = values(:);