Example to run SPI code | LabJack
 

Example to run SPI code

3 posts / 0 new
Last post
TLIN
TLIN's picture
Example to run SPI code

I am running the Lua Script example to run the SPI code for the Labjack T4. I have changed it a little bit and I get the error lua: [string "--[[..."]:56.000000: bad argument #1.000000 to 'getn' (table expected, got number). It looks like that needs a table but I don't know why.

Do you know why is this happening?

File Attachment: 
LabJack Support
LabJack Support's picture
Hello,

Hello,

You need to use the NameArray functions for SPI_DATA registers since these can (and often) return more than one value (a table). I think your problem stems mainly from this fact.

Any time we use the NameArray calls in our examples it is due to either the register expecting/returning a table or sometimes the ReadNameArray function is used to avoid truncation errors when dealing with 32-bit registers.

See this page for more information about truncation:

https://labjack.com/support/datasheets/t-series/lua-scripting/lua-warnings

TLIN
TLIN's picture
Fixed, thanks.

Fixed, thanks.