forked from nigelrogasch/MAGIC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bistim.m
149 lines (130 loc) · 6.81 KB
/
bistim.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
classdef bistim < magstim & handle
properties (SetAccess = private)
highRes = 0; %Bistim High Resolution Time Setting Mode
end
methods
function self = bistim(PortID)
self = self@magstim(PortID);
end
end
methods
function [errorOrSuccess, deviceResponse] = setAmplitudeB(self, power, varargin)
% Inputs:
% power<double> : is the desired power amplitude for stimulator B
% varargin<bool> refers to getResponse<bool> that can be True (1) or False (0)
% indicating whether a response from device is required or not.
% The default value is set to false.
% Outputs:
% deviceResponse: is the response that is sent back by the
% device to the port indicating current information about the device
% errorOrSuccess: is a boolean value indicating success = 0 or error = 1
% in performing the desired task
%% Check Input Validity:
narginchk(2, 3);
getResponse = magstim.checkForResponseRequest(varargin);
magstim.checkIntegerInput('Power', power, 0, 100);
%% Create Control Command
[errorOrSuccess, deviceResponse] = self.processCommand(['A' sprintf('%03s',num2str(power))], getResponse, 3);
end
function [errorOrSuccess, deviceResponse] = setPulseInterval(self, ipi, varargin)
% Inputs:
% ipi<double> : is the desired interpulse interval
% varargin<bool>: refers to getResponse<bool> that can be True (1) or False (0)
% indicating whether a response from device is required or not.
% The default value is set to false.
% Outputs:
% deviceResponse: is the response that is sent back by the
% device to the port indicating current information about the device
% errorOrSuccess: is a boolean value indicating success = 0 or error = 1
% in performing the desired task
%% Check Input Validity:
narginchk(2, 3);
getResponse = magstim.checkForResponseRequest(varargin);
if self.highRes % Device already set to highRes Mode
magstim.checkNumericInput('IPI', ipi, 0, 99.9);
ipi = round(ipi * 10);
else % Assume not in highRes mode
magstim.checkIntegerInput('IPI', ipi, 0, 999);
end
%% Create Control Command
[errorOrSuccess, deviceResponse] = self.processCommand(['C' sprintf('%03s', num2str(ipi))], getResponse, 3);
end
function [errorOrSuccess, deviceResponse] = highResolutionMode(self, enable, varargin)
% Inputs:
% enable<boolean> is a boolean that can be True(1) to
% enable and False(0) to disable the High Resolution Time Setting Mode
% varargin<bool> refers to getResponse<bool> that can be True (1) or False (0)
% indicating whether a response from device is required or not.
% The default value is set to false.
% Outputs:
% DeviceResponse: is the response that is sent back by the
% device to the port indicating current information about the device
% errorOrSuccess: is a boolean value indicating success = 0 or error = 1
% in performing the desired task
%% Check Input Validity
narginchk(2, 3);
getResponse = magstim.checkForResponseRequest(varargin);
if ~ismember(enable, [0 1])
error('enable Must Be A Boolean');
end
%% Create Control Command
if enable %Enable
commandString = 'Y@';
else %Disable
commandString = 'Z@';
end
[errorOrSuccess, deviceResponse] = self.processCommand(commandString, getResponse, 3);
if ~errorOrSuccess
self.highRes = enable;
end
end
function [errorOrSuccess, deviceResponse] = getParameters(self)
% Outputs:
% DeviceResponse: is the response that is sent back by the
% device to the port indicating current information about the device
% errorOrSuccess: is a boolean value indicating success = 0 or error = 1
% in performing the desired task
%% Check Input Validity
narginchk(1,1);
%% Create Control Command
[errorOrSuccess, deviceResponse] = self.processCommand('J@', true, 12);
if self.highRes
deviceResponse.IPI = deviceResponse.IPI / 10;
end
end
end
methods (Access = 'protected')
%%
function info = parseResponse(~, command, readData)
%% Getting Instrument Status (always returned)
statusCode = bitget(double(readData(1)),1:8);
info = struct('InstrumentStatus',struct('Standby', statusCode(1),...
'Armed', statusCode(2),...
'Ready', statusCode(3),...
'CoilPresent', statusCode(4),...
'ReplaceCoil', statusCode(5),...
'ErrorPresent', statusCode(6),...
'ErrorType', statusCode(7),...
'RemoteControlStatus', statusCode(8)));
%% Getting All Information
%Get commands
if command == 'J' %getParameters
info.PowerA = str2double(char(readData(2:4)));
info.PowerB = str2double(char(readData(5:7)));
info.IPI = str2double(char(readData(8:10)));
elseif command == 'F' %getTemperature
info.CoilTemp1 = str2double(char(readData(2:4))) / 10;
info.CoilTemp2 = str2double(char(readData(5:7))) / 10;
end
end
end
end