-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestScript.m
More file actions
79 lines (67 loc) · 2.23 KB
/
testScript.m
File metadata and controls
79 lines (67 loc) · 2.23 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
68
69
70
71
72
73
74
75
76
77
% testScript.m
%
% This demonstrates simultaneous analog and digital input and output using jDAQmx.
% Before you use it, make sure to you have NI DAQmx installed, and that you point
% jDAQmx.m to the location of your .dll (or .so) file and the .h header file.
%
%%
import jDAQmx.*;
sampleRate = 10000; % Hz
trialLength = 10; % Sec
% Create a stimulus, should by a matrix of size (nSamples, nChannels)
stimulus1 = zeros(trialLength*sampleRate,1);
stimulus1(50000:60000) = 5;
stimulus2 = zeros(trialLength*sampleRate,1);
stimulus2(70000:80000) = 5;
stimulus = [stimulus1,stimulus2];
% Make a digital stimulus
% This should also be of size (nSamples, nChannels)
digStim1 = zeros(trialLength*sampleRate,1);
digStim1(60000:65000) = 1;
digStim2 = zeros(trialLength*sampleRate,1);
digStim2(80000:85000) = 1;
digStim = sign([digStim1,digStim2]);
% Setup the input channels - these are the main timebase for all the tasks.
AI = analogInput('/Dev1');
AI.addChannel(0:1);
nSamplesToOutput = trialLength*sampleRate;
AI.setSampleRate(sampleRate,nSamplesToOutput);
% Setup the output channels - these trigger off the AI task.
AO = analogOutput('/Dev1');
AO.addChannel(0:1);
AO.setSampleRate(sampleRate,nSamplesToOutput);
% Put data into the output buffer and start the task. (No samples will
% be output until AI starts, but starting the task is necessary so it
% will respond to the AI trigger.)
AO.putData(stimulus);
AO.start();
% Setup the digital channels. These also trigger off of AI start.
DI = digitalInput('/Dev1');
DI.addChannel(0:1);
DI.setSampleRate(sampleRate,nSamplesToOutput);
% Again, start the task so it will be ready to acquire when AI starts.
DI.start();
% Same drill for digital output.
DO = digitalOutput('/Dev1');
DO.addChannel(2:3);
DO.setSampleRate(sampleRate,nSamplesToOutput);
% Again, put the data there, and start the task.
DO.putData(digStim);
DO.start();
% This also triggers the DI, AO, and DO
AI.start();
disp('Started acquisition waiting...');
AI.wait();
disp('Finished acquisition, getting data...');
dataInAnalog = AI.getData();
dataInDigital = DI.getData();
disp('Data done got got.');
% Stop and clear the tasks to free resources for future use.
AI.stop();
AI.clear();
AO.stop();
AO.clear();
DI.stop();
DI.clear();
DO.stop();
DO.clear();