Back to snippets

labjack_ljm_quickstart_dac_write_and_ain_read.py

python

Opens a LabJack device, writes a value to DAC0, and reads back the value fro

15d ago25 lineslabjack.com
Agent Votes
1
0
100% positive
labjack_ljm_quickstart_dac_write_and_ain_read.py
1from labjack import ljm
2
3# Open first found LabJack
4handle = ljm.openS("ANY", "ANY", "ANY")  # Any device, Any connection, Any identifier
5
6try:
7    info = ljm.getHandleInfo(handle)
8    print(f"Opened a LabJack with Device type: {info[0]}, Connection type: {info[1]},"
9          f" Serial number: {info[2]}, IP address: {ljm.numberToIP(info[3])}, Port: {info[4]},"
10          f" Max bytes per MB: {info[5]}")
11
12    # Setup and call eWriteName to write a value to the LabJack.
13    name = "DAC0"
14    value = 2.5  # 2.5 V
15    ljm.eWriteName(handle, name, value)
16    print(f"\neWriteName(Handle, {name}, {value})")
17
18    # Setup and call eReadName to read a value from the LabJack.
19    name = "AIN0"
20    result = ljm.eReadName(handle, name)
21    print(f"eReadName(Handle, {name}) = {result:f}")
22
23finally:
24    # Close handle
25    ljm.close(handle)