Lua Script Examples (T-Series Only) | LabJack
 
« Close

Datasheets and User Guides

App Notes

Software & Driver

 

Lua Script Examples (T-Series Only)

LabJack Lua Scripting

While running a Lua script, the T4, T7 or T7-Pro can operate without computer involvement.  Basically, user-specified operations (feedback loops, logging, PID loops) can be conducted via on-board script, which was not possible in previous generations of LabJack hardware. Below is a screenshot of the Lua Scripting section in our free cross-platform program called Kipling.

https://labjack.com/sites/default/files/organized/applications/Kipling_v3/photos/KiplingscriptingTN.png

Kipling's Lua scripting tab is the best way to develop embedded Lua scripts. It simplifies viewing, testing, and configuring Lua scripts.

To view Lua scripts without Kipling, see the sub-pages consisting of example scripts listed below. The majority (if not all) of the examples listed below are also available in the latest release of Kipling. Feel free to contribute additional scripts directly to the Kipling repository (contact us for instructions).

 

Key Feature of Lua Scripting: USER_RAM registers

If you are new to Lua Scripting, some basic getting started information can be found (here).

 

One common application of Lua Scripts is to execute tasks and export status variables to a logging program. These Scripts can use USER_RAM registers to pass data from the Lua script to any other program accessing the T-Series device. LabVIEW, C#, Python, or any other supported languages can access the T-Series device and read from or write to these registers. LJLogM, a LabJack application can be used for easy logging of data from the various sensors.  Several example scripts like these can be found in the I2C Sensor Examples website section.

One prime example is the Accelerometer & Compass Module (LSM303) example in which a script saves data from the sensor to user ram registers and had them logged by LJLogM.

More information:

  • Get Started (link)
  • Start Script on device power-up (link)
  • Pass values into and out of Lua (link)
  • Limitations (link)
  • Available Lua Libraries (link)

and more can be found in the Lua Scription section of the T-Series Datasheet.

Maximum Lua Script Size

Reaching the maximum size of a Lua Script using a T7 and T4 is easy to do.  The majority of the scripts that we have written show that the maximum size of a script is right around 100 lines however the exact size is hard to determine since it ultimately depends on what variables are being defined, how long is each line of code, etc.  As a user, if you start running into some intermittent errors like "not enough memory" it is time to either refactor your code or re-consider how much you are trying to do in a script.  To squeeze out every last ounce of scripting capabilities, start minifying your code using this online Lua Minifier tool.

Related News Posts

Lua Scripts have been featured in two news posts:

  • Stand Alone Operation: One of the key advantages of T-Series Lua Scripting (link)
  • Screen Casting and Lua Script Tutorials (link)