labjack-ljm-python icon indicating copy to clipboard operation
labjack-ljm-python copied to clipboard

T7 eRead Command Triggers Disabled State

Open bhathawayML opened this issue 11 months ago • 5 comments

I am communicating with a T7 LabJack device. I want to simply read the state of a pin, but while doing so this triggers the state of said pin. In the example below, I set pin MIO0 to True (validated with a vacuum line), then read the state using ljm.eReadName (same behavior with ljm.eReadAddress). This returns TRUE, however I can hear the vacuum line being disabled. When I call this same function again, it returns False and the vacuum remains disabled.

I hope I am not missing something obvious here. Any help/advice is much appreciated!

Versions: PyCharm 2023.3.7, Python 3.10, labjack-ljm 1.23.0

from labjack import ljm

device_sn = "470031969"
pin_name = "MIO0"

# Open device
try:
    device = ljm.openS("ANY", "ANY", device_sn)
except ljm.ljm.LJMError:
    raise Exception("No device detected!")

# Set pin status
ljm.eWriteName(device, pin_name, True)

# Get pin status
state = ljm.eReadName(device, pin_name)
print(bool(state))  # True

# Get pin status again
state = ljm.eReadName(device, pin_name)
print(bool(state))   # False

# Close device
ljm.close(device)

bhathawayML avatar Dec 18 '24 22:12 bhathawayML

Hello,

The registers which interact with a single IO will automatically set the direction. So reading from "FIO3", "DIO3", EIO3, "DIO11" etc. will set the corresponding IO to input. When writing, it will set the IO to output.

In your program. During the first read, the IO gets set to input. It reads high because the line needs some time to transition to low. When the second read occurs, the line has transitioned low and reads as such.

You can use DIO_STATE to get the states of the lines without affecting direction. Another option is to only read from input lines and only write to output lines.

For full details see the DIO section of the docs: https://support.labjack.com/docs/13-0-digital-i-o-t-series-datasheet

Kind regards, Steve

LabJack Support @.***

LabJack Corporation 6900 W JEFFERSON AVE STE 110 LAKEWOOD CO 80235-2335 V:(303)942-0228

How did we do? Great / Okay / Not Good https://docs.google.com/forms/d/e/1FAIpQLSfkvhb7q6YtG-fovIkV9xUABP6f4kfsZQpTetmHzw-yHLu3cA/viewform

On Wed, Dec 18, 2024 at 3:51 PM Brooke @.***> wrote:

I am communicating with a T7 LabJack device. I want to simply read the state of a pin, but while doing so this triggers the state of said pin. In the example below, I set pin MIO0 to True (validated with a vacuum line), then read the state using ljm.eReadName (same behavior with ljm.eReadAddress). This returns TRUE, however I can hear the vacuum line being disabled. When I call this same function again, it returns False and the vacuum remains disabled.

I hope I am not missing something obvious here. Any help/advice is much appreciated!

Versions: PyCharm 2023.3.7, Python 3.10, labjack-ljm 1.23.0

from labjack import ljm

device_sn = "470031969" pin_name = "MIO0"

Open device

try: device = ljm.openS("ANY", "ANY", device_sn) except ljm.ljm.LJMError: raise Exception("No device detected!")

Set pin status

ljm.eWriteName(device, pin_name, True)

Get pin status

state = ljm.eReadName(device, pin_name) print(bool(state)) # True

Get pin status again

state = ljm.eReadName(device, pin_name) print(bool(state)) # False

Close device

ljm.close(device)

— Reply to this email directly, view it on GitHub https://github.com/labjack/labjack-ljm-python/issues/24, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACHTFXXUQPRW733ZFOBP5AD2GH4ATAVCNFSM6AAAAABT3WSZPSVHI2DSMVQWIX3LMV43ASLTON2WKOZSG42DQOBZGM4TSNA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

ljrob avatar Dec 18 '24 23:12 ljrob

If my understanding is correct then The pin is set as an output line. Then it is converted to input when read is happening. And at the first read it is high because of the delay in converting the write pin to read. But then once the conversion has occurred then we are simply reading the value it is connected to (from outside).This should mean that the value from outside is low.

Also can the delay issue be solved by adding a sleep in the command.

KL-Mithunvel avatar Feb 03 '25 03:02 KL-Mithunvel

Your explanation is correct.

  • Also can the delay issue be solved by adding a sleep in the command. * Yes, a delay will allow time for the signal's level to change. The easy solution is to just leave it set to input. Do you have an application that requires the direction to change?

On Sun, Feb 2, 2025 at 8:13 PM kl mithunvel @.***> wrote:

If my understanding is correct then The pin is set as an output line. Then it is converted to input when read is happening. And at the first read it is high because of the delay in converting the write pin to read. But then once the conversion has occurred then we are simply reading the value it is connected to (from outside).This should mean that the value from outside is low.

Also can the delay issue be solved by adding a sleep in the command.

— Reply to this email directly, view it on GitHub https://github.com/labjack/labjack-ljm-python/issues/24#issuecomment-2629799055, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACHTFXTRGFXGDJUY2DHWIJD2N3NE7AVCNFSM6AAAAABT3WSZPSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMRZG44TSMBVGU . You are receiving this because you commented.Message ID: @.***>

ljrob avatar Feb 03 '25 19:02 ljrob

no, i was just interested in it. i am using labjack t7 pro for my project tho. i am making a furnace control system with it. it does not have no pin change based need so far.

also is there some api system that u would recommend for this, where i have a gui and backend with labjack. currently i am programming them all on my own.

KL-Mithunvel avatar Feb 03 '25 19:02 KL-Mithunvel

Most languages which can call a .dll can work with the T7. I have created GUIs in C#, LabVIEW and DAQFactory. I have not had the chance to play around with Python GUI libraries, but I hear good things.

LabVIEW and DAQFactory are among the easier programs to create a GUI with.

On Mon, Feb 3, 2025 at 12:45 PM kl mithunvel @.***> wrote:

no, i was just interested in it. i am using labjack t7 pro for my project tho. i am making a furnace control system with it. it does not have no pin change based need so far.

also is there some api system that u would recommend for this, where i have a gui and backend with labjack. currently i am programming them all on my own.

— Reply to this email directly, view it on GitHub https://github.com/labjack/labjack-ljm-python/issues/24#issuecomment-2631917436, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACHTFXUNSSSZW2XE44U35BT2N7BLXAVCNFSM6AAAAABT3WSZPSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMZRHEYTONBTGY . You are receiving this because you commented.Message ID: @.***>

ljrob avatar Feb 03 '25 23:02 ljrob