hvl_ccb.dev.labjack.labjack
A LabJack T-series devices wrapper around the LabJack’s LJM Library; see https://labjack.com/ljm . The wrapper was originally developed and tested for a LabJack T7-PRO device.
Extra installation
To use this LabJack T-series devices wrapper:
install the
hvl_ccb
package with alabjack
extra feature:$ pip install "hvl_ccb[labjack]"
this will install the Python bindings for the library.
install the library - follow instruction in https://labjack.com/support/software/installers/ljm .
- class LabJack(com, dev_config=None)[source]
Bases:
SingleCommDevice
LabJack Device.
This class is tested with a LabJack T7-Pro and should also work with T4 and T7 devices communicating through the LJM Library. Other or older hardware versions and variants of LabJack devices are not supported.
- class AInRange(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
StrEnumBase
An enumeration.
- ONE = 1.0
- ONE_HUNDREDTH = 0.01
- ONE_TENTH = 0.1
- TEN = 10.0
- property value: float
- class BitLimit(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
Maximum integer values for clock settings
- THIRTY_TWO_BIT = 4294967295
- class CalMicroAmpere(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
Enum
Pre-defined microampere (uA) values for calibration current source query.
- TEN = '10uA'
- TWO_HUNDRED = '200uA'
- class CjcType(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
NameEnum
CJC slope and offset
- internal = (1, 0)
- lm34 = (55.56, 255.37)
- class ClockFrequency(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
Available clock frequencies, in Hz
- FIVE_MHZ = 5000000
- FORTY_MHZ = 40000000
- MAXIMUM = 80000000
- MINIMUM = 312500
- TEN_MHZ = 10000000
- TWELVE_HUNDRED_FIFTY_KHZ = 1250000
- TWENTY_FIVE_HUNDRED_KHZ = 2500000
- TWENTY_MHZ = 20000000
- DIOChannel
alias of
TSeriesDIOChannel
- class DIOStatus(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
State of a digital I/O channel.
- HIGH = 1
- LOW = 0
- class DeviceType(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
AutoNumberNameEnum
LabJack device types.
Can be also looked up by ambigious Product ID (p_id) or by instance name:
`python LabJackDeviceType(4) is LabJackDeviceType('T4') `
- ANY = 1
- T4 = 2
- T7 = 3
- T7_PRO = 4
- classmethod get_by_p_id(p_id: int) DeviceType | list[DeviceType]
Get LabJack device type instance via LabJack product ID.
Note: Product ID is not unambiguous for LabJack devices.
- Parameters:
p_id – Product ID of a LabJack device
- Returns:
Instance or list of instances of LabJackDeviceType
- Raises:
ValueError – when Product ID is unknown
- class TemperatureUnit(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
NameEnum
Temperature unit (to be returned)
- C = 1
- F = 2
- K = 0
- class ThermocoupleType(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
NameEnum
Thermocouple type; NONE means disable thermocouple mode.
- C = 30
- E = 20
- J = 21
- K = 22
- NONE = 0
- PT100 = 40
- PT1000 = 42
- PT500 = 41
- R = 23
- S = 25
- T = 24
- config_high_pulse(address: str | TSeriesDIOChannel, t_start: int | float, t_width: int | float, n_pulses: int = 1) None [source]
Configures one FIO channel to send a timed HIGH pulse. Configure multiple channels to send pulses with relative timing accuracy. Times have a maximum resolution of 1e-7 seconds @ 10 MHz. :param address: FIO channel: [T7] FIO0;2;3;4;5. [T4] FIO6;7. :raises LabJackError if address is not supported. :param t_start: pulse start time in seconds. :raises ValueError: if t_start is negative or would exceed the clock period. :param t_width: duration of high pulse, in seconds. :raises ValueError: if t_width is negative or would exceed the clock period. :param n_pulses: number of pulses to be sent; single pulse default. :raises TypeError if n_pulses is not of type int. :raises Value Error if n_pulses is negative or exceeds the 32bit limit.
- static default_com_cls()[source]
Get the class for the default communication protocol used with this device.
- Returns:
the type of the standard communication protocol for this device
- disable_pulses(*addresses: str | TSeriesDIOChannel | None) None [source]
Disable previously configured pulse channels. :param addresses: tuple of FIO addresses. All channels disabled if no argument is passed.
- enable_clock(clock_enabled: bool) None [source]
Enable/disable LabJack clock to configure or send pulses. :param clock_enabled: True -> enable, False -> disable. :raises TypeError: if clock_enabled is not of type bool
- get_ain(*channels: int) float | Sequence[float] [source]
Read currently measured value (voltage, resistance, …) from one or more of analog inputs.
- Parameters:
channels – AIN number or numbers (0..254)
- Returns:
the read value (voltage, resistance, …) as float`or `tuple of them in case multiple channels given
- get_cal_current_source(name: str | CalMicroAmpere) float [source]
This function will return the calibration of the chosen current source, this ist not a measurement!
The value was stored during fabrication.
- Parameters:
name – ‘200uA’ or ‘10uA’ current source
- Returns:
calibration of the chosen current source in ampere
- get_digital_input(address: str | TSeriesDIOChannel) DIOStatus [source]
Get the value of a digital input.
allowed names for T7 (Pro): FIO0 - FIO7, EIO0 - EIO 7, CIO0- CIO3, MIO0 - MIO2 :param address: name of the output -> ‘FIO0’ :return: HIGH when address DIO is high, and LOW when address DIO is low
- get_product_id() int [source]
This function returns the product ID reported by the connected device.
Attention: returns 7 for both T7 and T7-Pro devices!
- Returns:
integer product ID of the device
- get_product_name(force_query_id=False) str [source]
This function will return the product name based on product ID reported by the device.
Attention: returns “T7” for both T7 and T7-Pro devices!
- Parameters:
force_query_id – boolean flag to force get_product_id query to device instead of using cached device type from previous queries.
- Returns:
device name string, compatible with LabJack.DeviceType
- get_product_type(force_query_id: bool = False) DeviceType [source]
This function will return the device type based on reported device type and in case of unambiguity based on configuration of device’s communication protocol (e.g. for “T7” and “T7_PRO” devices), or, if not available first matching.
- Parameters:
force_query_id – boolean flag to force get_product_id query to device instead of using cached device type from previous queries.
- Returns:
DeviceType instance
- Raises:
LabJackIdentifierDIOError – when read Product ID is unknown
- get_sbus_rh(number: int) float [source]
Read the relative humidity value from a serial SBUS sensor.
- Parameters:
number – port number (0..22)
- Returns:
relative humidity in %RH
- get_sbus_temp(number: int) float [source]
Read the temperature value from a serial SBUS sensor.
- Parameters:
number – port number (0..22)
- Returns:
temperature in Kelvin
- get_serial_number() int [source]
Returns the serial number of the connected LabJack.
- Returns:
Serial number.
- read_resistance(channel: int) float [source]
Read resistance from specified channel.
- Parameters:
channel – channel with resistor
- Returns:
resistance value with 2 decimal places
- read_thermocouple(pos_channel: int) float [source]
Read the temperature of a connected thermocouple.
- Parameters:
pos_channel – is the AIN number of the positive pin
- Returns:
temperature in specified unit
- send_pulses(*addresses: str | TSeriesDIOChannel) None [source]
Sends pre-configured pulses for specified addresses. :param addresses: tuple of FIO addresses :raises LabJackError if an address has not been configured.
- set_ain_differential(pos_channel: int, differential: bool) None [source]
Sets an analog input to differential mode or not. T7-specific: For base differential channels, positive must be even channel from 0-12 and negative must be positive+1. For extended channels 16-127, see Mux80 datasheet.
- Parameters:
pos_channel – is the AIN number (0..12)
differential – True or False
- Raises:
LabJackError – if parameters are unsupported
- set_ain_range(channel: int, vrange: Real | AInRange) None [source]
Set the range of an analog input port.
- Parameters:
channel – is the AIN number (0..254)
vrange – is the voltage range to be set
- set_ain_resistance(channel: int, vrange: Real | AInRange, resolution: int) None [source]
Set the specified channel to resistance mode. It utilized the 200uA current source of the LabJack.
- Parameters:
channel – channel that should measure the resistance
vrange – voltage range of the channel
resolution – resolution index of the channel T4: 0-5, T7: 0-8, T7-Pro 0-12
- set_ain_resolution(channel: int, resolution: int) None [source]
Set the resolution index of an analog input port.
- Parameters:
channel – is the AIN number (0..254)
resolution – is the resolution index within 0…`get_product_type().ain_max_resolution` range; 0 will set the resolution index to default value.
- set_ain_thermocouple(pos_channel: int, thermocouple: Union[None, str, ThermocoupleType], cjc_address: int = 60050, cjc_type: Union[str, CjcType] = <CjcType.internal: (1, 0)>, vrange: Union[Real, AInRange] = <AInRange.ONE_HUNDREDTH: '0.01'>, resolution: int = 10, unit: Union[str, TemperatureUnit] = <TemperatureUnit.K: 0>) None [source]
Set the analog input channel to thermocouple mode.
- Parameters:
pos_channel – is the analog input channel of the positive part of the differential pair
thermocouple – None to disable thermocouple mode, or string specifying the thermocouple type
cjc_address – modbus register address to read the CJC temperature
cjc_type – determines cjc slope and offset, ‘internal’ or ‘lm34’
vrange – measurement voltage range
resolution – resolution index (T7-Pro: 0-12)
unit – is the temperature unit to be returned (‘K’, ‘C’ or ‘F’)
- Raises:
LabJackError – if parameters are unsupported
- set_analog_output(channel: int, value: int | float) None [source]
Set the voltage of a analog output port
- Parameters:
channel – DAC channel number 1/0
value – The output voltage value 0-5 Volts int/float
- set_clock(clock_frequency: Number | ClockFrequency = 10000000, clock_period: Number = 1) None [source]
Configure LabJack clock for pulse out feature. :param clock_frequency: clock frequency in Hz; default 10 MHz for base 10. :raises ValueError: if clock_frequency is not allowed (see ClockFrequency). :param clock_period: clock roll time in seconds; default 1s, 0 for max. :raises ValueError: if clock_period exceeds the 32bit tick limit. Clock period determines pulse spacing when using multi-pulse settings. Ensure period exceeds maximum intended pulse end time.
- exception LabJackError[source]
Bases:
DeviceError
General Error for the LabJack device.
- exception LabJackIdentifierDIOError[source]
Bases:
LabJackError
Error indicating a wrong DIO identifier