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 Devices
30 {
31 class LabJackScaffold;
32 
33 SURGSIM_STATIC_REGISTRATION(LabJackDevice);
34 
35 namespace LabJack
36 {
40 enum TIMER
41 {
48 };
49 
51 {
60 };
61 
63 {
64  EIO0 = 8,
72 };
73 
75 {
76  CIO0 = 16,
80 };
81 
83 {
84  MIO0 = 20,
87 };
88 
89 enum AIN
90 {
107 };
108 
109 enum DAC
110 {
113 };
115 
117 enum Model
118 {
121  MODEL_U3 = 3,
123 };
124 
127 {
133 };
134 
139 {
155 };
156 
161 {
162  TIMERMODE_PWM_16BIT = 0, // 16 bit PWM
163  TIMERMODE_PWM_8BIT = 1, // 8 bit PWM
164  TIMERMODE_RISING_EDGES_32BIT = 2, // 32-bit rising to rising edge measurement
165  TIMERMODE_FALLING_EDGES_32BIT = 3, // 32-bit falling to falling edge measurement
166  TIMERMODE_DUTY_CYCLE = 4, // duty cycle measurement
167  TIMERMODE_FIRMWARE_COUNTER = 5, // firmware based rising edge counter
168  TIMERMODE_FIRMWARE_COUNTER_DEBOUNCED = 6, // firmware counter with debounce
169  TIMERMODE_FREQUENCY_OUTPUT = 7, // frequency output
170  TIMERMODE_QUADRATURE = 8, // Quadrature
171  TIMERMODE_TIMER_STOP = 9, // stops another timer after n pulses
172  TIMERMODE_SYSTEM_TIMER_LOWER_32BITS = 10, // read lower 32-bits of system timer
173  TIMERMODE_SYSTEM_TIMER_UPPR_32BITS = 11, // read upper 32-bits of system timer
174  TIMERMODE_RISING_EDGES_16BIT = 12, // 16-bit rising to rising edge measurement
175  TIMERMODE_FALLING_EDGES_16BIT = 13, // 16-bit falling to falling edge measurement
176  TIMERMODE_LINE_TO_LINE = 14 // Line to Line measurement
177 };
178 
181 {
185  bool operator==(const TimerSettings& other) const
186  {
187  return (mode == other.mode) && (initialValue == other.initialValue);
188  }
189 
192 
195 };
196 
198 enum Range
199 {
200  RANGE_20 = 1, // -20V to +20V, LJ_rgBIP20V
201  RANGE_10 = 2, // -10V to +10V, LJ_rgBIP10V
202  RANGE_5 = 3, // -5V to +5V, LJ_rgBIP5V
203  RANGE_4 = 4, // -4V to +4V, LJ_rgBIP4V
204  RANGE_2_POINT_5 = 5, // -2.5V to +2.5V, LJ_rgBIP2P5V
205  RANGE_2 = 6, // -2V to +2V, LJ_rgBIP2V
206  RANGE_1_POINT_25 = 7, // -1.25V to +1.25V, LJ_rgBIP1P25V
207  RANGE_1 = 8, // -1V to +1V, LJ_rgBIP1V
208  RANGE_0_POINT_625 = 9, // -0.625V to +0.625V, LJ_rgBIPP625V
209  RANGE_0_POINT_1 = 10, // -0.1V to +0.1V, LJ_rgBIPP1V
210  RANGE_0_POINT_01 = 11 // -0.01V to +0.01V, LJ_rgBIPP01V
211 };
212 
215 {
219  bool operator==(const AnalogInputSettings& other) const
220  {
221  return (negativeChannel == other.negativeChannel) && (range == other.range);
222  }
223 
226 
229 };
230 };
231 
275 {
276 public:
279  explicit LabJackDevice(const std::string& uniqueName);
280 
282 
284  virtual ~LabJackDevice();
285 
286  bool initialize() override;
287 
288  bool isInitialized() const override;
289 
293  void setModel(LabJack::Model model);
294 
296  LabJack::Model getModel() const;
297 
301  void setConnection(LabJack::Connection connection);
302 
304  LabJack::Connection getConnection() const;
305 
310  void setAddress(std::string address);
311 
313  const std::string& getAddress() const;
314 
324  void setResetOnDestruct(bool reset);
325 
328  bool getResetOnDestruct() const;
329 
333  void enableDigitalInput(int channel);
334 
338  void setDigitalInputs(const std::unordered_set<int>& digitalInputChannels);
339 
341  const std::unordered_set<int>& getDigitalInputs() const;
342 
346  void enableDigitalOutput(int channel);
347 
351  void setDigitalOutputs(const std::unordered_set<int>& digitalOutputChannels);
352 
354  const std::unordered_set<int>& getDigitalOutputs() const;
355 
360  void setTimerBase(LabJack::TimerBase base);
361 
363  LabJack::TimerBase getTimerBase() const;
364 
369  void setTimerClockDivisor(int divisor);
370 
372  int getTimerClockDivisor() const;
373 
377  void setTimerCounterPinOffset(int offset);
378 
380  int getTimerCounterPinOffset() const;
381 
389  void enableTimer(int index, LabJack::TimerMode mode);
390 
400  void enableTimer(int index, LabJack::TimerMode mode, int initialValue);
401 
406  void setTimers(const std::unordered_map<int, LabJack::TimerSettings>& timers);
407 
409  const std::unordered_map<int, LabJack::TimerSettings>& getTimers() const;
410 
414  void setMaximumUpdateRate(double rate);
415 
417  double getMaximumUpdateRate() const;
418 
425  void enableAnalogInput(int positiveChannel, LabJack::Range range, int negativeChannel);
426 
431  void enableAnalogInput(int channel, LabJack::Range range);
432 
438  void setAnalogInputs(const std::unordered_map<int, LabJack::AnalogInputSettings>& analogInputs);
439 
441  const std::unordered_map<int, LabJack::AnalogInputSettings>& getAnalogInputs() const;
442 
446  void enableAnalogOutput(int channel);
447 
452  void setAnalogOutputs(const std::unordered_set<int>& analogOutputChannels);
453 
455  const std::unordered_set<int>& getAnalogOutputs() const;
456 
462  void setAnalogInputResolution(int resolution);
463 
465  int getAnalogInputResolution() const;
466 
472  void setAnalogInputSettling(int settling);
473 
475  int getAnalogInputSettling() const;
476 
477 private:
478  friend class LabJackScaffold;
479 
480  bool finalize() override;
481 
483  std::shared_ptr<LabJackScaffold> m_scaffold;
484 
487 
490 
492  std::string m_address;
493 
495  bool m_reset;
496 
498  std::unordered_set<int> m_digitalInputChannels;
499 
501  std::unordered_map<int, LabJack::AnalogInputSettings> m_analogInputs;
502 
504  std::unordered_set<int> m_digitalOutputChannels;
505 
507  std::unordered_set<int> m_analogOutputChannels;
508 
513 
516 
519 
521  std::unordered_map<int, LabJack::TimerSettings> m_timers;
522 
524  double m_threadRate;
525 
528 
531 };
532 
533 }; // namespace Devices
534 }; // namespace SurgSim
535 
536 #endif // SURGSIM_DEVICES_LABJACK_LABJACKDEVICE_H
Definition: LabJackDevice.h:52
Definition: LabJackDevice.h:45
Definition: LabJackDevice.h:152
Definition: LabJackDevice.h:42
Definition: LabJackDevice.h:58
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:521
Definition: LabJackDevice.h:162
Definition: CompoundShapeToGraphics.cpp:29
Definition: LabJackDevice.h:85
Definition: LabJackDevice.h:57
Definition: LabJackDevice.h:206
Definition: LabJackDevice.h:76
SurgSim::DataStructures::OptionalValue< int > negativeChannel
The negative channel.
Definition: LabJackDevice.h:228
A struct holding the data to be associated with the positive channel for an analog input...
Definition: LabJackDevice.h:214
Definition: LabJackDevice.h:77
Definition: LabJackDevice.h:147
Definition: LabJackDevice.h:128
Connection
The connection (i.e., communication media) for LabJacks. Numbers come from LabJackUD.h.
Definition: LabJackDevice.h:126
Definition: LabJackDevice.h:112
Definition: LabJackDevice.h:130
Definition: LabJackDevice.h:210
Definition: LabJackDevice.h:66
std::shared_ptr< LabJackScaffold > m_scaffold
The single scaffold object that handles communications with all instances of LabJackDevice.
Definition: LabJackDevice.h:483
Definition: LabJackDevice.h:103
Definition: LabJackDevice.h:121
DAC
Definition: LabJackDevice.h:109
TimerMode
The timer modes.
Definition: LabJackDevice.h:160
LabJack::Model m_model
The model, e.g., U6.
Definition: LabJackDevice.h:486
Definition: LabJackDevice.h:120
Definition: LabJackDevice.h:122
int m_timerClockDivisor
The timer clock&#39;s divisor, see m_timerBase.
Definition: LabJackDevice.h:515
Definition: LabJackDevice.h:140
Definition: LabJackDevice.h:43
Definition: LabJackDevice.h:102
int m_analogInputResolution
The resolution for all the analog inputs.
Definition: LabJackDevice.h:527
Definition: LabJackDevice.h:86
Definition: LabJackDevice.h:145
Definition: LabJackDevice.h:91
int m_timerCounterPinOffset
The number of the lowest FIO pin that is a timer or counter.
Definition: LabJackDevice.h:518
Definition: LabJackDevice.h:202
Model
The models of LabJack devices. Numbers come from LabJackUD.h.
Definition: LabJackDevice.h:117
Definition: LabJackDevice.h:95
Definition: LabJackDevice.h:46
Definition: LabJackDevice.h:100
Definition: LabJackDevice.h:143
Definition: LabJackDevice.h:47
Definition: LabJackDevice.h:151
Definition: LabJackDevice.h:205
A class implementing the communication with a LabJack data acquisition (DAQ) device.
Definition: LabJackDevice.h:274
Definition: LabJackDevice.h:153
#define SURGSIM_CLASSNAME(ClassName)
Declare the class name of a class with the appropriate function header, do not use quotes...
Definition: Macros.h:21
Definition: LabJackDevice.h:94
Definition: LabJackDevice.h:209
Definition: LabJackDevice.h:93
TimerBase
The timer base frequencies for LabJacks.
Definition: LabJackDevice.h:138
Definition: LabJackDevice.h:101
Definition: LabJackDevice.h:55
Definition: LabJackDevice.h:142
AIN
Definition: LabJackDevice.h:89
Definition: LabJackDevice.h:129
MIO_LINE
Definition: LabJackDevice.h:82
EIO_LINE
Definition: LabJackDevice.h:62
Definition: LabJackDevice.h:70
Definition: LabJackDevice.h:96
Definition: LabJackDevice.h:104
Definition: LabJackDevice.h:149
Definition: LabJackDevice.h:201
A class that implements the behavior of LabJackDevice objects.
Definition: LabJackScaffold.h:41
Definition: LabJackDevice.h:208
bool operator==(const AnalogInputSettings &other) const
Equality comparison.
Definition: LabJackDevice.h:219
int m_analogInputSettling
The settling time for all the analog inputs.
Definition: LabJackDevice.h:530
Definition: LabJackDevice.h:53
Definition: LabJackDevice.h:119
Definition: LabJackDevice.h:79
Definition: LabJackDevice.h:106
Definition: LabJackDevice.h:67
Definition: LabJackDevice.h:163
Definition: LabJackDevice.h:92
Definition: LabJackDevice.h:111
Definition: LabJackDevice.h:97
Definition: LabJackDevice.h:44
double m_threadRate
The maximum update rate for the LabJackThread.
Definition: LabJackDevice.h:524
Definition: LabJackDevice.h:150
Definition: LabJackDevice.h:203
Range range
The range.
Definition: LabJackDevice.h:225
LabJack::TimerBase m_timerBase
The timer base, which is the frequency of all the output timers unless it ends in "_DIV"...
Definition: LabJackDevice.h:512
Definition: LabJackDevice.h:78
A class that implements some common management code on top of the DeviceInterface.
Definition: CommonDevice.h:35
FIO_LINE
Definition: LabJackDevice.h:50
Definition: LabJackDevice.h:141
CIO_LINE
Definition: LabJackDevice.h:74
Definition: LabJackDevice.h:69
Definition: LabJackDevice.h:144
Definition: LabJackDevice.h:105
Definition: LabJackDevice.h:204
Definition: LabJackDevice.h:99
TIMER
Definition: LabJackDevice.h:40
Definition: LabJackDevice.h:64
std::unordered_set< int > m_digitalInputChannels
The line numbers for the digital inputs.
Definition: LabJackDevice.h:498
std::unordered_map< int, LabJack::AnalogInputSettings > m_analogInputs
The analog inputs. The key is the positive channel.
Definition: LabJackDevice.h:501
std::unordered_set< int > m_analogOutputChannels
The line numbers for the analog outputs.
Definition: LabJackDevice.h:507
Definition: LabJackDevice.h:59
A struct holding the data to be associated with a Timer.
Definition: LabJackDevice.h:180
TimerMode mode
The mode.
Definition: LabJackDevice.h:191
SurgSim::DataStructures::OptionalValue< int > initialValue
The initial value.
Definition: LabJackDevice.h:194
LabJack::Connection m_connection
The type of communication connection, e.g., USB.
Definition: LabJackDevice.h:489
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:492
bool operator==(const TimerSettings &other) const
Equality comparison.
Definition: LabJackDevice.h:185
std::unordered_set< int > m_digitalOutputChannels
The line numbers for the digital outputs.
Definition: LabJackDevice.h:504
Definition: LabJackDevice.h:200
Definition: LabJackDevice.h:207
Definition: LabJackDevice.h:154
Definition: LabJackDevice.h:65
Definition: LabJackDevice.h:146
Definition: LabJackDevice.h:98
bool m_reset
Whether or not the hardware should reset when this object destructs.
Definition: LabJackDevice.h:495
Range
The analog input ranges. Equivalent to gain. Ignored for Linux scaffold, which auto-ranges.
Definition: LabJackDevice.h:198
Definition: LabJackDevice.h:54
Definition: LabJackDevice.h:84
Definition: LabJackDevice.h:71
Definition: LabJackDevice.h:68
Definition: LabJackDevice.h:56
Definition: LabJackDevice.h:148