-
Notifications
You must be signed in to change notification settings - Fork 0
/
gaussMeterBytesAvailable.m
74 lines (53 loc) · 1.8 KB
/
gaussMeterBytesAvailable.m
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
68
69
70
71
72
73
74
function gaussMeterBytesAvailable(obj,event)
initByte = fread(obj, 1);
commandHex = dec2hex(fread(obj, 1));
x = fread(obj, 1, 'int16');
y = fread(obj, 1, 'int16');
z = fread(obj, 1, 'int16');
date = fread(obj, 1, 'int16');
year = 2000 + binaryVectorToDecimal(bitget(date, 10:16));
month = binaryVectorToDecimal(bitget(date, 6:9));
day = binaryVectorToDecimal(bitget(date, 1:5));
time = fread(obj, 1, 'int16');
status = fread(obj, 1);
hour = binaryVectorToDecimal([bitget(time, 13:16), bitget(status, 1)]);
minute = binaryVectorToDecimal(bitget(time, 7:12));
second = binaryVectorToDecimal(bitget(time, 1:6));
unit = bitget(status, 2);
if (unit == 1)
strUnit = 'micro Tesla';
else
strUnit = 'mG'
end
xRank = 20 * 10^binaryVectorToDecimal(bitget(status, 3:4));
yRank = 20 * 10^binaryVectorToDecimal(bitget(status, 5:6));
zRank = 20 * 10^binaryVectorToDecimal(bitget(status, 7:8));
CRC = fread(obj, 1);
m = sqrt(x^2 + y^2 + z^2);
%for display
disp([num2str(m),' ', strUnit,' --- ', num2str(hour), ':', num2str(minute), ':',num2str(second), ' - ', num2str(day), '/', num2str(month), '/', num2str(year)]);
% data(dataII).X = x;
% data(dataII).Y = y;
% data(dataII).Z = z;
% data(dataII).Year = year;
% data(dataII).Month = month;
% data(dataII).Day = day;
% data(dataII).Hour = hour;
% data(dataII).Minute = minute;
% data(dataII).Second = second;
% data(dataII).Unit = unit;
% data(dataII).XRank = xRank;
% data(dataII).YRank = yRank;
% data(dataII).ZRank = zRank;
%dataII = dataII + 1;
%M = [x,y,z,year,month,day,hour,minute,second,unit,xRank,yRank,zRank];
%dlmwrite('data.csv',M,'-append')
global hLine;
global iii;
X = get(hLine, 'XData');
Y = get(hLine, 'YData');
X = [X now];
Y = [Y m];
set(hLine, 'XData', X, 'YData', Y);
drawnow
end