Package: labjack-unified
labjack-unifiedClasses with unified methods to interact withLabJacks U3, U6 and T7.labjack-unifiedis implemented uponLabJackPythonandlabjack-ljm-pythonand provides classes to interact with any of theLabJackdevices listed above, through a set of methods that are device-independent.labjack-unifiedwas developed for the MS Windows platform.Classes & MethodsThree classes are available (LabJackU3,LabJackU6, andLabJackT7) which have the common methods listed below. These should cover the majority of LabJack applications. There are also device specific methods as well.MethodDescriptioncloseCloses the LabJack devicedisplay_infoDisplays summary info about the deviceset_digitalWrites digital value to specified port(s)get_digitalReads digital value from specified port(s)set_analogWrites analog value to specified port(s)get_analogReads analog value from specified port(s)get_labjacktempGets ambient temperature from internal sensorset_streamSets LabJack configuration for data streamingget_streamGets streaming datastop_streamStops data streamingset_PWMSets LabJack configuration for PWM outputset_dutycycleSets duty cycle of PWM output (-100 to 100)set_quadratureSets LabJack configuration for encoder A-B-Z inputget_counterGets edge count from encoder A-B signalsreset_counterResets edge counterInstallpy -m pip install labjack-unifiedInstallinglabjack-unifiedwill install its dependencies:LabJackPythonandlabjack-ljm.Plotlywill also be installed so graphs can be displayed when running the examples.DocumentationComprehensive documentation forlabjack-unifiedis availablehere.ExamplesNine examples are available in the documentation, with four of them requiring only
a pair of wires to be executed successfully. Below is the code forlj_io_analog.py:""" lj_io_analog.pyUses analog input and output channels.This example shows how to use analog inputs and outputs in a data acquisitionloop. Accurate time execution of output events can be achieved by the use of atimer logic in the loop. The voltage measurements are executed as fast aspossible. The main latency source is the LabJack I/O times.Setup:Connect DAC0 to AIN0Connect DAC1 to AIN1The LabJack unified methods in this example are:set_analog ....... Writes analog value to specified port(s)get_analog ....... Reads analog value from specified port(s)close ............ Closes the LabJack device"""importtimeimportnumpyasnpfromlabjack_unified.utilsimportplot_linefromlabjack_unified.devicesimportLabJackU3,LabJackU6,LabJackT7# To use a LabJack U6 or a T7, change the device name# from LabJackU3 below to either LabJackU6 or LabJackT7lj=LabJackU3()# Assigning parameterststep=0.5# Interval between step changes (s)t=[]# Output time arrayv1=[]# Output sampled voltage 1 arrayv2=[]# Output sampled voltage 2 array# Initializing timers and starting main clocktprev=0tcurr=0tstart=time.perf_counter()# Executing acquisition loopprint('Running code for 5 seconds ...')whiletcurr<=5:# Updating analog output every `tstep` seconds# with random voltages between 0 and 5 Vif(np.floor(tcurr/tstep)-np.floor(tprev/tstep))==1:lj.set_analog('DAC0',5*np.random.rand())lj.set_analog('DAC1',5*np.random.rand())# Updating previous time and getting current time (s)tprev=tcurrtcurr=time.perf_counter()-tstart# Acquiring analog data as fast as possible# and appending values to output arrayst.append(tcurr)v1.append(lj.get_analog('AIN0'))v2.append(lj.get_analog('AIN1'))print('Done.')# Closing the devicelj.close()dellj# Plotting resultsplot_line([t]*2,[v1,v2],yname=['AIN0','AIN1'],axes='multi',marker=True)plot_line([t[1::]],[np.diff(t)],yname=['Sampling Period (s)'])