Driver for the Labjack U12 data acquisition device. http://labjack.com/support/u12/users-guide For details about the commands, refer to the users guide.
| 36 | |
| 37 | |
| 38 | class U12(Driver): |
| 39 | """ |
| 40 | Driver for the Labjack U12 data acquisition device. |
| 41 | http://labjack.com/support/u12/users-guide |
| 42 | For details about the commands, refer to the users guide. |
| 43 | """ |
| 44 | def __init__(self, board_id): |
| 45 | super().__init__() |
| 46 | self._internal = _u12.U12(board_id) |
| 47 | |
| 48 | def initialize(self): |
| 49 | super().initialize() |
| 50 | self._internal.open() |
| 51 | |
| 52 | def finalize(self): |
| 53 | self._internal.close() |
| 54 | |
| 55 | |
| 56 | # ANALOG INPUT METHODS |
| 57 | ''' |
| 58 | The LabJack U12 has 8 screw terminals for analog input signals (AI0-7). These can be configured individually and on-the-fly as 8 single- |
| 59 | ended channels, 4 differential channels, or combinations in between. Each input has a 12-bit resolution and an input bias current of |
| 60 | ±90 μA. |
| 61 | ''' |
| 62 | |
| 63 | ''' |
| 64 | EAnalogIn is a simplified (E is for easy) function that returns a single reading from 1 analog input channel. Execution time is up to |
| 65 | 20 ms. |
| 66 | ''' |
| 67 | @DictFeat(units='volts', keys=list(range(0,8))) |
| 68 | def analog_in(self, key): |
| 69 | return self._internal.eAnalogIn(channel=key)['voltage'] |
| 70 | |
| 71 | @DictFeat(units='volts', keys=list(range(0,4))) |
| 72 | def analog_dif_in(self, key, gain = 1): |
| 73 | ''' |
| 74 | Differential channels can make use of the low noise precision PGA to provide gains up to 20. In differential mode, the voltage of each AI with respect to ground must be between +20 and -10 volts, but the range of voltage difference between the 2 AI is a function of gain (G) as follows: |
| 75 | G=1 ±20 volts |
| 76 | G=2 ±10 volts |
| 77 | G=4 ±5 volts |
| 78 | G=5 ±4 volts |
| 79 | G=8 ±2.5 volts |
| 80 | G=10 ±2 volts |
| 81 | G=16 ±1.25 volts |
| 82 | G=20 ±1 volt |
| 83 | The reason the range is ±20 volts at G=1 is that, for example, AI0 could be +10 volts and AI1 could be -10 volts giving a difference of +20 volts, or AI0 could be -10 volts and AI1 could be +10 volts giving a difference of -20 volts. The PGA (programmable gain amplifier, available on differential channels only) amplifies the AI voltage before it is digitized by the A/D converter. The high level drivers then divide the reading by the gain and return the actual measured voltage. |
| 84 | ''' |
| 85 | gain_list = [1,2,4,5,8,10,16,20] |
| 86 | gain_value = gain |
| 87 | if gain_value not in gain_list: |
| 88 | raise InstrumentError('Gain value not permitted, check driver code or Labjack user guide') |
| 89 | else: |
| 90 | return self._internal.eAnalogIn(channel = key + 8, gain = gain_value)['voltage'] |
| 91 | |
| 92 | # ANALOG OUTPUT METHOD |
| 93 | analog_out = DictFeat(units = 'volts', keys=list(range(0,2))) |
| 94 | @analog_out.setter |
| 95 | def analog_out(self, key, value): |