Git Product home page Git Product logo

labjack-ljm-python's People

Contributors

bobjacobsen avatar davelopez01 avatar labjackadmin avatar rolsen avatar ryker-labjack avatar sjarman28 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

labjack-ljm-python's Issues

Problem running on Ubuntu 20.04 Focal (x86_64)

I ran the labjack installation script from the website and am now attempting to access the labjack via ljm in Python – using a T7-Pro over USB. All works well in Windows, but on Ubuntu I get the following error message when attempting to set up PeriodicStreamOut

AttributeError: /usr/local/lib/libLabJackM.so: undefined symbol: LJM_PeriodicStreamOut

The code is pretty simple, happy to post if that would help debug this.

M1 mac support

Looks like the compiled libraries are not build against arm64. After pip installing I get the following error when importing ljm

<class 'labjack.ljm.ljm.LJMError'>: Cannot load the LJM library /usr/local/lib/libLabJackM.dylib. dlopen(libLabJackM.dylib, 0x0006): tried: '/Users/jeffreymarkowitz/miniconda3/envs/labjack-test/lib/python3.10/lib-dynload/../../libLabJackM.dylib' (no such file), '/Users/jeffreymarkowitz/miniconda3/envs/labjack-test/bin/../lib/libLabJackM.dylib' (no such file), 'libLabJackM.dylib' (no such file), '/usr/local/lib/libLabJackM.dylib' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))), '/usr/lib/libLabJackM.dylib' (no such file), '/Users/jeffreymarkowitz/libLabJackM.dylib' (no such file)

Are there plans to update for supporting M1 macs?

how can I setup UART on T7?

Hi I just purchased an T7 Pro. I need to use UART.
Is it possible to control UART TX and RX on T7 via python?

If not, what else can I do?

Getting bad voltage readings with ljm.eReadName until I open ljStream

When I first start my python IDE and run my code the voltage reading on my thermocouple is ~1.7 volts. If I close my program, start ljstream (without loading anything), wait for the voltage readings come in then close out ljstream I get ~ 8e-05 volts. The second value is the expected voltage as my thermal couple is close to room temp. Is there some initializing I need to do in my code? Here is the relevant code:

class labControl:
    
    def __init__(self):
        self.handle = ljm.openS("T7", "ANY","ANY")
        
        info = ljm.getHandleInfo(self.handle)
        print("\nOpened a LabJack with Device type: %i, Connection type: %i,\n"
              "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" %
              (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5]))
    
    def thermo(self,channel,cj,cal_data):
        volts = ljm.eReadName(self.handle, channel)
        # Sometimes this reading is way off and I dont know why. Opening and starting then closing lj-stream seems to clear it
        print(volts)
        mV = volts * float(1000)

WSL support?

Now attempting to use this library with the Windows Subsytem for Linux (specifically Ubuntu 20.04 LTS). Everything installs fine, and I'm able to get access to the Labjack over USB via https://learn.microsoft.com/en-us/windows/wsl/connect-usb .

I'm trying to run this example program as a sanity check

https://github.com/labjack/labjack-ljm-python/blob/master/Examples/More/Stream/periodic_stream_out.py

Running it results in the following error. If WSL is unsupported or out of scope feel free to close this issue, but it would be nice to support if possible.

Beginning...

Error calling ljm.open(deviceType=0, connectionType=0, identifier=ANY)
Traceback (most recent call last):
  File "/home/jmarkow/dev/labjack_test.py", line 116, in <module>
    main()
  File "/home/jmarkow/dev/labjack_test.py", line 95, in main
    handle = openLJMDevice(ljm.constants.dtANY, ljm.constants.ctANY, "ANY")
  File "/home/jmarkow/dev/labjack_test.py", line 52, in openLJMDevice
    handle = ljm.open(deviceType, connectionType, identifier)
  File "/home/jmarkow/miniconda3/envs/dearpygui-test/lib/python3.10/site-packages/labjack/ljm/ljm.py", line 382, in open
    raise LJMError(error)
labjack.ljm.ljm.LJMError: LJM library error code 1230 LJME_DEVICE_CURRENTLY_CLAIMED_BY_ANOTHER_PROCESS

CORE_TIMER read via streaming rolls over at 2^16

First, thanks so much for this library, developing for the Labjack is mostly a breeze!

We're running a program where we read in AIN0, AIN1 and FIO_STATE while using eReadStream. At the same time we're sending out TTL pulses via periodicStreamOut. To collect timestamps for our data reads we're also collecting CORE_TIMER – analog inputs are collected first, then FIO_STATE, then CORE_TIMER in the scan list. Even though the modbus map lists CORE_TIMER as a uint32, the returned values roll over at 2^16 rather than 2^32 as expected. Not sure if there's something in our configuration that would result in this happening.

LJMError should be moved into its own exception module

by defining the same LJMError class in the module where it is used, there exists a chicken/egg problem where the LJMError cannot be used to catch exception when importing LJM library.

For example:

try:
    from labjack import ljm
except labjack.ljm.ljm.LJMError as exception:
    raise LabjackLibraryNotInstalled from exception

cannot work because the LJMError is defined in the same module. A better practice is to seperate the exception class into it's own module that only depends on Python standard library, this ensures Labjack package exceptions can be used for module imports that wrap library code, just as labjack-ljm-python wraps the LJM library that is required to be installed.

Another issue is that the _loadLibrary() function catches the LJMError exception, prints the error, then returns None. Why? If the python package doesn't work without the LJM library, then it shouldn't handle the exception, it should just raise it and let the calling module handle the exception.

Please remove from _loadLibrary():

    except LJMError:
        ljme = sys.exc_info()[1]
        print(str(type(ljme)) + ": " + str(ljme))
        return None

lua script loading fails on some file lengths

Using the example code for loading a lua script, some scripts fail with this message (file with 1804 bytes)
lua: [string "--[[..."]:70.000000: unexpected symbol near 'char(5.000000)'

where the line number is the last line of the program, and char() changes, sometimes its a printable ascii character.

The failure is inconsistent, as it seems to depend on what bad bytes follow the loaded program in python. In all of my tests, the scripts can randomly succeed, and all lua has been verified in the kipling debugger.

The problem can be fixed two ways:

  1. Adding a null terminator to the loaded script file as in:
script = file.read()
script += '\0'
  1. By adding characters to the lua script, as in replacing MB.W(6000, 1, 0) with MB.W(6000.00, 1, 0)

It's not clear what the root cause is, but it sure looks like a string length problem. This test was performed on Win64 machine.

The loading code is:

        with open(self.filepath, mode="r", encoding="utf-8") as file:
            script = file.read()
            # script = script + '\0'
            scriptLen = len(script)

            ljm.eWriteName(self.handle, "LUA_SOURCE_SIZE", scriptLen)
            ljm.eWriteNameByteArray(self.handle, "LUA_SOURCE_WRITE", scriptLen, script)
            ljm.eWriteName(self.handle, "LUA_DEBUG_ENABLE", 1)
            ljm.eWriteName(self.handle, "LUA_DEBUG_ENABLE_DEFAULT", 1)
            print(f'Script {self.filepath} ({scriptLen} bytes) loaded')

My starting script (without any length manipulation) is

--[[
    Cystal Monitor Test Fixture Lua for Labjack
    
    DUT PS Power Regulator
--]]

MB.writeName("LUA_NO_WARN_TRUNCATION", 1)

-- print("Starting dut ps script")

local DATA_READY_REG = "USER_RAM0_U16"        -- will be 1 when the data is ready

local MV_SETTING_REG = "USER_RAM1_U16"

------------------------
-- Common I2C Configuration and Misc Utilities
------------------------

local I2C_SCL_REG = 3-- FIO4
local I2C_SDA_REG = 4 -- FIO3
local I2C_SPEED = 65516 -- 0,65536 = 450Khz, 1=40Hz, 65516=100kHz
local I2C_OPTIONS = 3 -- resetAtStart*1+noStopAtStarting*2
local I2C_SLAVE_ADDRESS_REG = 5104 -- uint16

function config_i2c_bus(address)
    -- print("Configuring i2c bus")
    I2C.config(I2C_SDA_REG, I2C_SCL_REG, I2C_SPEED, I2C_OPTIONS, address)
end

function sleep_ms(inteval_ms)
    local CheckInterval = LJ.CheckInterval
    LJ.IntervalConfig(1, inteval_ms)
    while not CheckInterval(1) do
    end
end

----------------------------
-- DUT PS
----------------------------
MB.writeName(DATA_READY_REG, 0)

function dut_ps_set_voltage()
    local DUT_PS_REGULATOR_I2C_ADDR = 0x0D
    local DUT_PS_DEFAULT_MV = 4500 -- 750 to 4800
    local DUT_MAX_MV = 4800 -- depends on jig
    local DUT_MIN_MV = 750

    local in_mv = MB.readName(MV_SETTING_REG)
    -- print(string.format("setting dut_ps to %d mv", in_mv))

    local data = (DUT_MAX_MV - in_mv)
    if data > 4095 then data = 4095
    elseif data < 0 then data = 0
    end

    b1 = bit.rshift(bit.band(data, 0xff00), 8)
    b0 = bit.band(data, 0xff)

    -- print(string.format("setting regulator to %02X %02X", b1, b0))

    config_i2c_bus(DUT_PS_REGULATOR_I2C_ADDR)
    I2C.write({b1, b0})

    -- Common Ending Code
    MB.writeName(DATA_READY_REG, 1)
end

dut_ps_set_voltage()
-- print("Stopping script")
MB.W(6000, 1, 0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.