Upload/start lua code from python interface? | LabJack
 

Upload/start lua code from python interface?

3 posts / 0 new
Last post
mikelwrnc
mikelwrnc's picture
Upload/start lua code from python interface?

Is there a way to upload and start lua code from the python interface? I see that the C interface seems to permit this and I'm hoping it's possible with python too.

LabJack Support
labjack support's picture
Documentation for how to

Documentation for how to upload a Lua Script to a T-Series device can be found at the bottom of the datasheet section titled 25.0 Lua Scripting.  Search for the text "Load Lua Script Manually To Device".  You can perform the same process in python and any other language if you are using the LJM library.  We don't have a pre-made python example that does this for you, however the example code that we have published should show you how to use each of the different LJM function calls.

Let us know if you are having specific issues following the steps outlined in the datasheet and we will do our best to help you troubleshoot your issue.

mikelwrnc
mikelwrnc's picture
For posterity, here's how to

For posterity, here's how to do it from Python 2.7:

import time
from labjack import ljm
handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY")

with open('some_code.lua', 'r') as myfile:
lua_script = myfile.read()

script_length = len(lua_script)

# Disable a running script by writing 0 to LUA_RUN twice
ljm.eWriteName(handle, "LUA_RUN", 0)
# Wait for the Lua VM to shut down (and some T7 firmware versions need
# a longer time to shut down than others):
time.sleep(1)
ljm.eWriteName(handle, "LUA_RUN", 0)

# Write the size and the Lua Script to the device
ljm.eWriteName(handle, "LUA_SOURCE_SIZE", script_length)
ljm.eWriteNameByteArray(handle, "LUA_SOURCE_WRITE", script_length, bytearray(lua_script))

# Start the script with debug output disabled
ljm.eWriteName(handle, "LUA_DEBUG_ENABLE", 1)
ljm.eWriteName(handle, "LUA_DEBUG_ENABLE_DEFAULT", 1)
ljm.eWriteName(handle, "LUA_RUN", 1)

ljm.close(handle)