LabJackDevice.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_DEVICES_LABJACK_LABJACKDEVICE_H
17 #define SURGSIM_DEVICES_LABJACK_LABJACKDEVICE_H
18 
19 #include <memory>
20 #include <string>
21 #include <unordered_map>
22 #include <unordered_set>
23 
26 
27 namespace SurgSim
28 {
29 namespace Device
30 {
31 class LabJackScaffold;
32 
33 namespace LabJack
34 {
38 enum TIMER
39 {
46 };
47 
49 {
58 };
59 
61 {
62  EIO0 = 8,
70 };
71 
73 {
74  CIO0 = 16,
78 };
79 
81 {
82  MIO0 = 20,
85 };
86 
87 enum AIN
88 {
105 };
106 
107 enum DAC
108 {
111 };
113 
115 enum Model
116 {
119  MODEL_U3 = 3,
121 };
122 
125 {
131 };
132 
137 {
153 };
154 
159 {
160  TIMERMODE_PWM_16BIT = 0, // 16 bit PWM
161  TIMERMODE_PWM_8BIT = 1, // 8 bit PWM
162  TIMERMODE_RISING_EDGES_32BIT = 2, // 32-bit rising to rising edge measurement
163  TIMERMODE_FALLING_EDGES_32BIT = 3, // 32-bit falling to falling edge measurement
164  TIMERMODE_DUTY_CYCLE = 4, // duty cycle measurement
165  TIMERMODE_FIRMWARE_COUNTER = 5, // firmware based rising edge counter
166  TIMERMODE_FIRMWARE_COUNTER_DEBOUNCED = 6, // firmware counter with debounce
167  TIMERMODE_FREQUENCY_OUTPUT = 7, // frequency output
168  TIMERMODE_QUADRATURE = 8, // Quadrature
169  TIMERMODE_TIMER_STOP = 9, // stops another timer after n pulses
170  TIMERMODE_SYSTEM_TIMER_LOWER_32BITS = 10, // read lower 32-bits of system timer
171  TIMERMODE_SYSTEM_TIMER_UPPR_32BITS = 11, // read upper 32-bits of system timer
172  TIMERMODE_RISING_EDGES_16BIT = 12, // 16-bit rising to rising edge measurement
173  TIMERMODE_FALLING_EDGES_16BIT = 13, // 16-bit falling to falling edge measurement
174  TIMERMODE_LINE_TO_LINE = 14 // Line to Line measurement
175 };
176 
179 {
183  bool operator==(const TimerSettings& other) const
184  {
185  return (mode == other.mode) && (initialValue == other.initialValue);
186  }
187 
190 
193 };
194 
196 enum Range
197 {
198  RANGE_20 = 1, // -20V to +20V, LJ_rgBIP20V
199  RANGE_10 = 2, // -10V to +10V, LJ_rgBIP10V
200  RANGE_5 = 3, // -5V to +5V, LJ_rgBIP5V
201  RANGE_4 = 4, // -4V to +4V, LJ_rgBIP4V
202  RANGE_2_POINT_5 = 5, // -2.5V to +2.5V, LJ_rgBIP2P5V
203  RANGE_2 = 6, // -2V to +2V, LJ_rgBIP2V
204  RANGE_1_POINT_25 = 7, // -1.25V to +1.25V, LJ_rgBIP1P25V
205  RANGE_1 = 8, // -1V to +1V, LJ_rgBIP1V
206  RANGE_0_POINT_625 = 9, // -0.625V to +0.625V, LJ_rgBIPP625V
207  RANGE_0_POINT_1 = 10, // -0.1V to +0.1V, LJ_rgBIPP1V
208  RANGE_0_POINT_01 = 11 // -0.01V to +0.01V, LJ_rgBIPP01V
209 };
210 
213 {
217  bool operator==(const AnalogInputSettings& other) const
218  {
219  return (negativeChannel == other.negativeChannel) && (range == other.range);
220  }
221 
224 
227 };
228 };
229 
273 {
274 public:
277  explicit LabJackDevice(const std::string& uniqueName);
278 
280  virtual ~LabJackDevice();
281 
287  virtual bool initialize() override;
288 
290  bool isInitialized() const;
291 
295  void setModel(LabJack::Model model);
296 
298  LabJack::Model getModel() const;
299 
303  void setConnection(LabJack::Connection connection);
304 
306  LabJack::Connection getConnection() const;
307 
312  void setAddress(std::string address);
313 
315  const std::string& getAddress() const;
316 
320  void enableDigitalInput(int channel);
321 
325  void setDigitalInputs(const std::unordered_set<int>& digitalInputChannels);
326 
328  const std::unordered_set<int>& getDigitalInputs() const;
329 
333  void enableDigitalOutput(int channel);
334 
338  void setDigitalOutputs(const std::unordered_set<int>& digitalOutputChannels);
339 
341  const std::unordered_set<int>& getDigitalOutputs() const;
342 
347  void setTimerBase(LabJack::TimerBase base);
348 
350  LabJack::TimerBase getTimerBase() const;
351 
356  void setTimerClockDivisor(int divisor);
357 
359  int getTimerClockDivisor() const;
360 
364  void setTimerCounterPinOffset(int offset);
365 
367  int getTimerCounterPinOffset() const;
368 
376  void enableTimer(int index, LabJack::TimerMode mode);
377 
387  void enableTimer(int index, LabJack::TimerMode mode, int initialValue);
388 
393  void setTimers(const std::unordered_map<int, LabJack::TimerSettings>& timers);
394 
396  const std::unordered_map<int, LabJack::TimerSettings>& getTimers() const;
397 
401  void setMaximumUpdateRate(double rate);
402 
404  double getMaximumUpdateRate() const;
405 
412  void enableAnalogInput(int positiveChannel, LabJack::Range range, int negativeChannel);
413 
418  void enableAnalogInput(int channel, LabJack::Range range);
419 
425  void setAnalogInputs(const std::unordered_map<int, LabJack::AnalogInputSettings>& analogInputs);
426 
428  const std::unordered_map<int, LabJack::AnalogInputSettings>& getAnalogInputs() const;
429 
433  void enableAnalogOutput(int channel);
434 
439  void setAnalogOutputs(const std::unordered_set<int>& analogOutputChannels);
440 
442  const std::unordered_set<int>& getAnalogOutputs() const;
443 
449  void setAnalogInputResolution(int resolution);
450 
452  int getAnalogInputResolution() const;
453 
459  void setAnalogInputSettling(int settling);
460 
462  int getAnalogInputSettling() const;
463 
464 private:
468  virtual bool finalize() override;
469 
470  friend class LabJackScaffold;
471 
473  std::shared_ptr<LabJackScaffold> m_scaffold;
474 
477 
480 
483 
485  std::unordered_set<int> m_digitalInputChannels;
486 
488  std::unordered_map<int, LabJack::AnalogInputSettings> m_analogInputs;
489 
491  std::unordered_set<int> m_digitalOutputChannels;
492 
494  std::unordered_set<int> m_analogOutputChannels;
495 
500 
503 
506 
508  std::unordered_map<int, LabJack::TimerSettings> m_timers;
509 
511  double m_threadRate;
512 
515 
518 };
519 
520 }; // namespace Device
521 }; // namespace SurgSim
522 
523 #endif // SURGSIM_DEVICES_LABJACK_LABJACKDEVICE_H
Definition: LabJackDevice.h:82
Definition: DriveElementFromInputBehavior.cpp:27
Definition: LabJackDevice.h:99
AIN
Definition: LabJackDevice.h:87
Definition: LabJackDevice.h:198
Definition: LabJackDevice.h:119
CIO_LINE
Definition: LabJackDevice.h:72
Definition: LabJackDevice.h:147
int m_analogInputSettling
The settling time for all the analog inputs.
Definition: LabJackDevice.h:517
Definition: LabJackDevice.h:63
Definition: LabJackDevice.h:142
Definition: LabJackDevice.h:64
Definition: LabJackDevice.h:160
std::unordered_set< int > m_digitalOutputChannels
The line numbers for the digital outputs.
Definition: LabJackDevice.h:491
Definition: LabJackDevice.h:42
DAC
Definition: LabJackDevice.h:107
Definition: LabJackDevice.h:208
Definition: LabJackDevice.h:90
Definition: LabJackDevice.h:56
Definition: LabJackDevice.h:149
Definition: LabJackDevice.h:152
Definition: LabJackDevice.h:50
Definition: LabJackDevice.h:84
EIO_LINE
Definition: LabJackDevice.h:60
Definition: LabJackDevice.h:168
Definition: LabJackDevice.h:40
LabJack::Connection m_connection
The type of communication connection, e.g., USB.
Definition: LabJackDevice.h:479
Definition: LabJackDevice.h:169
Model
The models of LabJack devices. Numbers come from LabJackUD.h.
Definition: LabJackDevice.h:115
Definition: LabJackDevice.h:204
Definition: LabJackDevice.h:69
std::string m_address
The address, or a zero-length string to indicate the first-found device of this type on this connecti...
Definition: LabJackDevice.h:482
Definition: LabJackDevice.h:104
Definition: LabJackDevice.h:75
Definition: LabJackDevice.h:100
SurgSim::DataStructures::OptionalValue< int > negativeChannel
The negative channel.
Definition: LabJackDevice.h:226
int m_timerCounterPinOffset
The number of the lowest FIO pin that is a timer or counter.
Definition: LabJackDevice.h:505
Definition: LabJackDevice.h:52
Definition: LabJackDevice.h:93
Definition: LabJackDevice.h:97
Definition: LabJackDevice.h:67
Definition: LabJackDevice.h:109
Definition: LabJackDevice.h:164
Definition: LabJackDevice.h:120
Definition: LabJackDevice.h:95
string(TOUPPER ${DEVICE}DEVICE_UPPER_CASE) option(BUILD_DEVICE_ $
Definition: CMakeLists.txt:35
Definition: LabJackDevice.h:43
Definition: LabJackDevice.h:141
Definition: LabJackDevice.h:200
Definition: LabJackDevice.h:54
bool operator==(const AnalogInputSettings &other) const
Equality comparison.
Definition: LabJackDevice.h:217
TimerMode mode
The mode.
Definition: LabJackDevice.h:189
Definition: LabJackDevice.h:96
Definition: LabJackDevice.h:206
Definition: LabJackDevice.h:65
Definition: LabJackDevice.h:91
Definition: LabJackDevice.h:66
Definition: LabJackDevice.h:207
Range
The analog input ranges. Equivalent to gain. Ignored for Linux scaffold, which auto-ranges.
Definition: LabJackDevice.h:196
LabJack::TimerBase m_timerBase
The timer base, which is the frequency of all the output timers unless it ends in "_DIV"...
Definition: LabJackDevice.h:499
Definition: LabJackDevice.h:51
Definition: LabJackDevice.h:145
Definition: LabJackDevice.h:117
double m_threadRate
The maximum update rate for the LabJackThread.
Definition: LabJackDevice.h:511
Definition: LabJackDevice.h:101
Range range
The range.
Definition: LabJackDevice.h:223
Definition: LabJackDevice.h:126
TimerMode
The timer modes.
Definition: LabJackDevice.h:158
Definition: LabJackDevice.h:138
Definition: LabJackDevice.h:140
Definition: LabJackDevice.h:161
Definition: LabJackDevice.h:144
FIO_LINE
Definition: LabJackDevice.h:48
TimerBase
The timer base frequencies for LabJacks.
Definition: LabJackDevice.h:136
Definition: LabJackDevice.h:53
MIO_LINE
Definition: LabJackDevice.h:80
Definition: LabJackDevice.h:94
A class that implements some common management code on top of the DeviceInterface.
Definition: CommonDevice.h:34
Definition: LabJackDevice.h:103
A struct holding the data to be associated with a Timer.
Definition: LabJackDevice.h:178
Definition: LabJackDevice.h:146
bool operator==(const TimerSettings &other) const
Equality comparison.
Definition: LabJackDevice.h:183
Definition: LabJackDevice.h:139
Definition: LabJackDevice.h:62
Definition: LabJackDevice.h:57
Definition: LabJackDevice.h:151
Definition: LabJackDevice.h:76
Connection
The connection (i.e., communication media) for LabJacks. Numbers come from LabJackUD.h.
Definition: LabJackDevice.h:124
std::unordered_set< int > m_digitalInputChannels
The line numbers for the digital inputs.
Definition: LabJackDevice.h:485
std::unordered_set< int > m_analogOutputChannels
The line numbers for the analog outputs.
Definition: LabJackDevice.h:494
SurgSim::DataStructures::OptionalValue< int > initialValue
The initial value.
Definition: LabJackDevice.h:192
int m_analogInputResolution
The resolution for all the analog inputs.
Definition: LabJackDevice.h:514
Definition: LabJackDevice.h:203
std::unordered_map< int, LabJack::AnalogInputSettings > m_analogInputs
The analog inputs. The key is the positive channel.
Definition: LabJackDevice.h:488
Definition: LabJackDevice.h:127
Definition: LabJackDevice.h:150
Definition: LabJackDevice.h:45
Definition: LabJackDevice.h:118
Definition: LabJackDevice.h:89
int m_timerClockDivisor
The timer clock&#39;s divisor, see m_timerBase.
Definition: LabJackDevice.h:502
Definition: LabJackDevice.h:199
Definition: LabJackDevice.h:74
A class implementing the communication with a LabJack data acquisition (DAQ) device.
Definition: LabJackDevice.h:272
LabJack::Model m_model
The model, e.g., U6.
Definition: LabJackDevice.h:476
Definition: LabJackDevice.h:143
Definition: LabJackDevice.h:202
TIMER
Definition: LabJackDevice.h:38
Definition: LabJackDevice.h:44
Definition: LabJackDevice.h:205
A struct holding the data to be associated with the positive channel for an analog input...
Definition: LabJackDevice.h:212
Definition: LabJackDevice.h:110
Definition: LabJackDevice.h:128
Definition: LabJackDevice.h:68
Definition: LabJackDevice.h:98
A class that implements the behavior of LabJackDevice objects.
Definition: LabJackScaffold.h:41
Definition: LabJackDevice.h:102
Definition: LabJackDevice.h:41
Definition: LabJackDevice.h:55
std::unordered_map< int, LabJack::TimerSettings > m_timers
A map from the timers&#39; line numbers to their mode and optional initial value.
Definition: LabJackDevice.h:508
Definition: LabJackDevice.h:83
Definition: LabJackDevice.h:92
Definition: LabJackDevice.h:201
Definition: LabJackDevice.h:77
Definition: LabJackDevice.h:148
std::shared_ptr< LabJackScaffold > m_scaffold
The single scaffold object that handles communications with all instances of LabJackDevice.
Definition: LabJackDevice.h:473