hvl_ccb.comm.labjack_ljm
Communication protocol for LabJack using the LJM Library. Originally developed and tested for LabJack T7-PRO.
Makes use of the LabJack LJM Library Python wrapper. This wrapper needs an installation of the LJM Library for Windows, Mac OS X or Linux. Go to: https://labjack.com/support/software/installers/ljm and https://labjack.com/support/software/examples/ljm/python
- class LJMCommunication(configuration)[source]
Bases:
CommunicationProtocol
Communication protocol implementing the LabJack LJM Library Python wrapper.
- static config_cls()[source]
Return the default configdataclass class.
- Returns:
a reference to the default configdataclass class
- property is_open: bool
Flag indicating if the communication port is open.
- Returns:
True if the port is open, otherwise False
- read_name(*names: str, return_num_type: type[~numbers.Real] = <class 'float'>) Real | Sequence[Real] [source]
Read one or more input numeric values by name.
- Parameters:
names – one or more names to read out from the LabJack
return_num_type – optional numeric type specification for return values; by default float.
- Returns:
answer of the LabJack, either single number or multiple numbers in a sequence, respectively, when one or multiple names to read were given
- Raises:
TypeError – if read value of type not compatible with return_num_type
- class LJMCommunicationConfig(device_type: str | DeviceType = 'ANY', connection_type: str | ConnectionType = 'ANY', identifier: str = 'ANY')[source]
Bases:
object
Configuration dataclass for
LJMCommunication
.- class ConnectionType(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
AutoNumberNameEnum
LabJack connection type.
- ANY = 1
- ETHERNET = 4
- TCP = 3
- USB = 2
- WIFI = 5
- 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
- connection_type: str | ConnectionType = 'ANY'
Can be either string or of enum
ConnectionType
.
- device_type: str | DeviceType = 'ANY'
Can be either string ‘ANY’, ‘T7_PRO’, ‘T7’, ‘T4’, or of enum
DeviceType
.
- force_value(fieldname, value)
Forces a value to a dataclass field despite the class being frozen.
NOTE: you can define post_force_value method with same signature as this method to do extra processing after value has been forced on fieldname.
- Parameters:
fieldname – name of the field
value – value to assign
- identifier: str = 'ANY'
The identifier specifies information for the connection to be used. This can be an IP address, serial number, or device name. See the LabJack docs ( https://labjack.com/support/software/api/ljm/function-reference/ljmopens/identifier-parameter) for more information.
- is_configdataclass = True
- classmethod keys() Sequence[str]
Returns a list of all configdataclass fields key-names.
- Returns:
a list of strings containing all keys.
- classmethod optional_defaults() dict[str, object]
Returns a list of all configdataclass fields, that have a default value assigned and may be optionally specified on instantiation.
- Returns:
a list of strings containing all optional keys.
- classmethod required_keys() Sequence[str]
Returns a list of all configdataclass fields, that have no default value assigned and need to be specified on instantiation.
- Returns:
a list of strings containing all required keys.
- exception LJMCommunicationError[source]
Bases:
CommunicationError
Errors coming from LJMCommunication.