-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendData.m
More file actions
62 lines (52 loc) · 1.41 KB
/
sendData.m
File metadata and controls
62 lines (52 loc) · 1.41 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
function sendable = sendData(datafile,rate)
%Start up the Daq
s = daq.createSession('digilent')
s.DurationInSeconds =120;
%This is W1.
ch = addAnalogOutputChannel(s,'AD1', 1, 'Voltage')
%Get the rate
s.Rate = rate;
%define header
header = [1 0 1 0 1 0 1 0];
%length without header
packetlen = 128;
%For now, just read in all at once.
data = csvread(datafile);
%Scale appropriately
data = 10*data-5;
%Number of packets
numpackets = ceil(length(data)/packetlen);
%% Transmit once
% for i = 1:numpackets
% startind = packetlen*(i -1) + 1;
% if (i == numpackets)
% datatotransmit = horzcat(header,data(startind:end))';
% else
% endind = startind + (packetlen - 1);
% datatotransmit = horzcat(header,data(startind:endind))';
% end
%
% queueOutputData(s,datatotransmit);
% s.startForeground;
%
% end
%% Transmit Continuously
% iteration = 0;
% while true
% iteration = iteration +1;
% i = mod(iteration, numpackets) + 1;
% startind = packetlen*(i -1) + 1;
% if (i == numpackets)
% datatotransmit = horzcat(header,data(startind:end))';
% else
% endind = startind + (packetlen - 1);
% datatotransmit = horzcat(header,data(startind:endind))';
% end
%
% queueOutputData(s,datatotransmit);
% s.startForeground;
%
% end
%% Return on completion
sendable = 1;
end