-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFTC_get.m
More file actions
67 lines (57 loc) · 1.6 KB
/
FTC_get.m
File metadata and controls
67 lines (57 loc) · 1.6 KB
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
64
65
66
67
function val = FTC_get(str)
% val = FTC_get(str)
% str:
% 'power' : [double] power output duty cycle in [-1, 1]
% 'PV' : [double] thermocouple value (Celsius)
% 'SV' : [double] setpoint (Celsius)
% 'DIR': [boolean] hot/cold direction (boolean)
% 'enable' : [string] 'off', 'power', or 'PID'
global FTC;
req = uint8(hex2dec(['01';'03';'00';'03';'00';'00']));
switch str
case 'power'
req(4) = 3; % 00 03
parse = @(x) double(x(5)*256+x(6))/10000;
case 'PV'
req(3) = 16; % 10 00
parse = @(x) double(x(5)*256+x(6))/100;
case 'SV'
req(4) = 0; %00 00
parse = @(x) double(x(5)*256+x(6))/100;
case 'DIR'
req(4) = 12; % 00 0C
parse = @parse_dir;
case 'enable'
req(4) = 4; % 00 04
parse = @parse_enable;
otherwise
error(['Get ' str ' not implemented']);
end
fwrite(FTC.serial_object, req);
res = fread(FTC.serial_object, 6);
% response format should be XX XX 00 02 XX XX
assert(all(res(3:4) == [0; 2]), 'Unexpected response from FTC module');
% first two bytes of response should match request
if ~all(req(1:2)==res(1:2))
error('Unexpected response from FTC module');
end
val = parse(res);
end
function y = parse_dir(x)
switch x(6)
case 9
y = true;
case 10
y = false;
end
end
function y = parse_enable(x)
switch x(6)
case 0
y = 'off';
case 3
y = 'PID';
case 2
y = 'power';
end
end