etactica / lua-libmodbus Goto Github PK
View Code? Open in Web Editor NEWlua bindings to libmodbus
License: MIT License
lua bindings to libmodbus
License: MIT License
Hi Karlp, et al.
Compiling with MinGW and MSYS. libmodbus compiled successfully. LuaRocks complains:
os.execute: C: & cd "C:\Users\WSMATH~1\AppData\Local\Temp\luarocks_lua-libmodbus-0.4.2-1-2627\lua-libmodbus" & mingw32-gcc -O2 "-c" "-o" "lua-libmodbus.o" "-IC:\Lua\5.1\include" "lua-libmodbus.c" "-I$LIBMODBUS_INCDIR"
lua-libmodbus.c:41:10: fatal error: modbus/modbus.h: No such file or directory
#include <modbus/modbus.h>
^~~~~~~~~~~~~~~~~
compilation terminated.
The command:
luarocks install lua-libmodbus LUAPKG=lua-5.1 LIBMODBUS_DIR=C:\MinGW\msys\1.0\local\bin LIBMODBUS_INCDIR=C:\MinGW\msys\1.0\local\include --verbose
Any ideas?
I already tried MSYS/make. The complaint:
wsmathews@DESKTOP-LO9R9RB /c/Users/wsmathews/Downloads/lua-libmodbus-master
$ make
/bin/sh: pkg-config: command not found
/bin/sh: pkg-config: command not found
/bin/sh: pkg-config: command not found
/bin/sh: pkg-config: command not found
make: pkg-config: Command not found
make: pkg-config: Command not found
make: pkg-config: Command not found
make: pkg-config: Command not found
cc -c -g -fPIC -std=c11 -Wall -pedantic -Os -o lua-libmodbus.o lua-libmodbus.c
make: cc: Command not found
make: *** [lua-libmodbus.o] Error 127
Currently, the helpers to get/set 32/64 bit values from 16bit registers expect to get each register as a parameter.
regs = read_registers(0x2000, 20)
local number = mb.get_s64(regs[10],regs[11], regs[12], regs[13])
when pulling out multiple numbers, it might be nice to support indexing a register table instead? Could automatically attempt to do the right thing based on the type of the first argument?
regs = read_registers(0x2000, 20)
local number = mb.get_s64(regs, 10)
The conversion from the lua table to an array of uint16_t's for libmodbus is truncating badly on openwrt/lnum patched devices at least.
Should make sure that it behaves predictably on both desktop 5.1/5.3 and openwrt patched 5.1
on lua5.1 and 5.3 vanilla, the get_s16(-5) call "correctly" returns -5 as expected
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio (double int32)
> mb=require("libmodbus")
> =mb.get_s16(-5)
0
> =mb.get_s16(5)
5
> =mb.get_s16(0xface)
-1330
>
given the mess with bit libraries on different lua versions, and the different ways of getting 32bit signed/unsigned integers and floats out of modbus registers, add at least the basic helpers into the library directly so you don't have to keep adding this code yourself all over the place.
If you are using the lnum patch, as on, for instance, OpenWrt, the mb.set_s32 functions won't behave properly when passed negative numbers. thanks lnum
Hi Karl,
On the same system, in one application (ZBStudio), the compiled libmodbus.so for lua 5.1 works fine, but in another(Crank Storyboard), when connecting to the same version of lua, when trying to mb = require("libmodbus"), it gives the error I get an error ERROR [0.757] :LUA script failure (entry function: cb_invokeModule ): error loading module 'libmodbus' from file '/usr/local/lib/lua/5.1/libmodbus.so':
/usr/local/lib/lua/5.1/libmodbus.so: undefined symbol: lua_gettop, what could i be wrong, thanks
(Linux 4.4.180-94.147-default (8e3cd9f) x86_64 x86_64 GNU/Linux)
Sergio
Are you planning to release/tag latest changes? Particularly, RS485 mode for serial port feature.
Having tagged release would simplify to push latest feature to upstream Linux distributions, ie. Alpine.
test code:
local mb = require('libmodbus')
local ctx = mb.new_rtu('/dev/ttyO2', 9600, 'N', 8, 1)
ctx:close()
print('bye!')
result:
# ./t.lua
bye!
Segmentation fault
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.