ynezz / librs232 Goto Github PK
View Code? Open in Web Editor NEWmultiplatform library for serial communications over RS-232 (serial port)
License: MIT License
multiplatform library for serial communications over RS-232 (serial port)
License: MIT License
Tried both 1.0.0 and 1.0.3 release under Lua 5.3.4 and the output is:
> local rs232 = require('luars232')
error loading module 'luars232' from file 'D:\Lua\luars232.dll':
找不到指定的模块。
stack traceback:
[C]: in ?
[C]: in function 'require'
stdin:1: in main chunk
[C]: in ?
Under Lua 5.2 the output is:
> local rs232 = require('luars232')
error loading module 'luars232' from file 'D:\Lua\52\luars232.dll':
%1 不是有效的 Win32 应用程序。
stack traceback:
[C]: in ?
[C]: in function 'require'
stdin:1: in main chunk
[C]: in ?
sudo luarocks install luars232
Password:
Installing https://luarocks.org/luars232-1.0.3-1.src.rock...
Using https://luarocks.org/luars232-1.0.3-1.src.rock... switching to 'build' mode
env MACOSX_DEPLOYMENT_TARGET=10.8 gcc -O2 -fPIC -I/usr/local/include -c src/rs232.c -o src/rs232.o -DLUAROCKS_HACK -std=gnu99 -Iinclude
env MACOSX_DEPLOYMENT_TARGET=10.8 gcc -O2 -fPIC -I/usr/local/include -c src/rs232_posix.c -o src/rs232_posix.o -DLUAROCKS_HACK -std=gnu99 -Iinclude
env MACOSX_DEPLOYMENT_TARGET=10.8 gcc -O2 -fPIC -I/usr/local/include -c bindings/lua/luars232.c -o bindings/lua/luars232.o -DLUAROCKS_HACK -std=gnu99 -Iinclude
bindings/lua/luars232.c:386:8: error: unknown type name 'luaL_reg'; did you mean
'luaL_Reg'?
static luaL_reg port_methods[] = {
^~~~~~~~
luaL_Reg
/usr/local/include/lauxlib.h:26:3: note: 'luaL_Reg' declared here
} luaL_Reg;
^
bindings/lua/luars232.c:426:8: error: unknown type name 'luaL_reg'; did you mean
'luaL_Reg'?
static luaL_reg port_functions[] = {
^~~~~~~~
luaL_Reg
/usr/local/include/lauxlib.h:26:3: note: 'luaL_Reg' declared here
} luaL_Reg;
^
bindings/lua/luars232.c:432:69: error: unknown type name 'luaL_reg'; did you mean
'luaL_Reg'?
static void create_metatables(lua_State *L, const char *name, const luaL_reg *methods)
^~~~~~~~
luaL_Reg
/usr/local/include/lauxlib.h:26:3: note: 'luaL_Reg' declared here
} luaL_Reg;
^
bindings/lua/luars232.c:437:2: warning: implicit declaration of function
'luaL_register' is invalid in C99 [-Wimplicit-function-declaration]
luaL_register(L, NULL, methods);
^
1 warning and 3 errors generated.
Error: Build error: Failed compiling object bindings/lua/luars232.o
I am trying to build lua on arch linux with lua 5.1 installed. My configure looks like this:
./configure --with-lua-inc=/usr/include/lua5.1/ --with-lua-lib=/usr/lib/lua/5.1/
make
Making all in include
make[1]: Entering directory '/home/comotion/code/lua/librs232/include'
Making all in librs232
make[2]: Entering directory '/home/comotion/code/lua/librs232/include/librs232'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/comotion/code/lua/librs232/include/librs232'
make[2]: Entering directory '/home/comotion/code/lua/librs232/include'
make[2]: Nothing to be done for 'all-am'.
make[2]: Leaving directory '/home/comotion/code/lua/librs232/include'
make[1]: Leaving directory '/home/comotion/code/lua/librs232/include'
Making all in src
make[1]: Entering directory '/home/comotion/code/lua/librs232/src'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/comotion/code/lua/librs232/src'
Making all in bindings
make[1]: Entering directory '/home/comotion/code/lua/librs232/bindings'
Making all in lua
make[2]: Entering directory '/home/comotion/code/lua/librs232/bindings/lua'
/bin/sh ../../libtool --tag=CC --mode=compile gcc -DPACKAGE_NAME="librs232" -DPACKAGE_TARNAME="librs232" -DPACKAGE_VERSION="0.0.1" -DPACKAGE_STRING="librs232\ 0.0.1" -DPACKAGE_BUGREPORT="[email protected]" -DPACKAGE_URL="" -DPACKAGE="librs232" -DVERSION="0.0.1" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=".libs/" -DBUILD_LUA=1 -I. -I../../include -Wall -ansi -pedantic -W -Wmissing-prototypes -Wmissing-declarations -Werror -Wno-unused-but-set-variable -std=gnu99 -O2 -g -O2 -MT luars232.lo -MD -MP -MF .deps/luars232.Tpo -c -o luars232.lo luars232.c
libtool: compile: gcc -DPACKAGE_NAME="librs232" -DPACKAGE_TARNAME="librs232" -DPACKAGE_VERSION="0.0.1" "-DPACKAGE_STRING="librs232 0.0.1"" -DPACKAGE_BUGREPORT="[email protected]" -DPACKAGE_URL="" -DPACKAGE="librs232" -DVERSION="0.0.1" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=".libs/" -DBUILD_LUA=1 -I. -I../../include -Wall -ansi -pedantic -W -Wmissing-prototypes -Wmissing-declarations -Werror -Wno-unused-but-set-variable -std=gnu99 -O2 -g -O2 -MT luars232.lo -MD -MP -MF .deps/luars232.Tpo -c luars232.c -fPIC -DPIC -o .libs/luars232.o
luars232.c:389:8: error: unknown type name ‘luaL_reg’
static luaL_reg port_methods[] = {
^
luars232.c:390:2: error: braces around scalar initializer [-Werror]
{ "__tostring", lua_port_tostring },
^
luars232.c:390:2: error: (near initialization for ‘port_methods[0]’) [-Werror]
luars232.c:390:2: error: initialization makes integer from pointer without a cast [-Werror]
luars232.c:390:2: error: (near initialization for ‘port_methods[0]’) [-Werror]
luars232.c:390:2: error: initializer element is not computable at load time
luars232.c:390:2: error: (near initialization for ‘port_methods[0]’)
luars232.c:390:2: error: excess elements in scalar initializer [-Werror]
luars232.c:390:2: error: (near initialization for ‘port_methods[0]’) [-Werror]
luars232.c:391:2: error: braces around scalar initializer [-Werror]
{ "__gc", lua_port_close },
^
[.. snip a lot of similar errors...]
FYI, the routines rs232_read_timeout_forced(), rs232_read_timeout(), and
rs232_write_timeout() in rs232_posix.c assume that timeout is less than a
second. I made the following change to my copy of the previous release to
work around a problem that I encountered while testing:
Please provide step-by-step instructions on how to build for OpenWRT Attitude Adjustment. Currently I am using the ImageBuilder to create my own firmware, and I would like to integrate luci modules which interact with an Arduino connected to the internal serial port.
In current LuaDist the following lines fail under win32 ( tested with Win8, Win7, WinXP ):
local rs232 = require"luars232"
print( rs232.open("COM1"))
It always gives "error 2". When trying the same with e.g. putty, then COM1 can be opened.
After a some research I found that the reason might be a bug in rs232_windows.c lines 390ff:
Line 390: wchar_t *wname = a2w(fix_device_name(p->dev));
^^^ here you change filename to unicode
...
...
wx->fd = CreateFile(wname, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
^^^ but here you call CreateFile() instead of CreateFileW(), meaning you pass Unicode-Devicename to Ansi-Dll Function - which fails every time. At least LuaDist is compiled against Mingw, which seems to default to Ansi-Build, which uses the CreateFileA() call...
没有任何地方调用rs232_end,导致内存泄露
I'm seeing an issue with rs232_test.c
. Looks like rs232_end()
doesn't wait for the transfer to complete before shutting down which can lead to some misbehaviour. See here for a discussion:
https://stackoverflow.com/questions/53804659/serial-port-receives-two-more-bytes-than-sent
[josema@marengo librs232]$ ./autogen.sh
running: autoreconf --force --install --symlink --verbose
./autogen.sh: línea 6: autoreconf: no se encontró la orden
error: while running 'autoreconf --force --install --symlink --verbose'
[josema@marengo librs232]$
"no se encontró la orden" means "command not found" or similar
sudo luarocks-5.1 install luars232
Installing https://rocks.moonscript.org/luars232-1.0.3-1.src.rock...
Using https://rocks.moonscript.org/luars232-1.0.3-1.src.rock... switching to 'build' mode
gcc -O2 -fPIC -I/usr/include/lua5.1 -c src/rs232.c -o src/rs232.o -DLUAROCKS_HACK -std=gnu99 -Iinclude
gcc -O2 -fPIC -I/usr/include/lua5.1 -c src/rs232_posix.c -o src/rs232_posix.o -DLUAROCKS_HACK -std=gnu99 -Iinclude
gcc -O2 -fPIC -I/usr/include/lua5.1 -c bindings/lua/luars232.c -o bindings/lua/luars232.o -DLUAROCKS_HACK -std=gnu99 -Iinclude
gcc -shared -o luars232.so -L/usr/lib src/rs232.o src/rs232_posix.o bindings/lua/luars232.o
Error: Directory 'invalid' not found
/*
* print(port:error_tostring(error))
*/
should be:
/*
* print(rs232.error_tostring(error))
*/
I managed to get librs232 to compile on OS X 10.6.4. The autogen.sh script uses libtoolize and OS X uses glibtoolize. I just changed the line to glibtoolize. I have been able to make other projects compile in OS X and Linux by using the autoreconf script.
I also had to add the O_NDELAY flag to the open() call in rs232_linux.c (line 423). This may not be necessary. If I used the cu.usbserial*** version instead of the tty.usbserial*** version of the device it worked. It may also be possible to use the O_NONBLOCK flag instead and then change the port configuration after the port is opened. This has something to do with the USB/Serial converter drivers and the carrier detect signal.
I have been using the Lua bindings on a little project of mine and so far they seem to work fine on OS X. I haven't tested them much but what I have done has worked well.
The support for serial device file name longer than 30 characters is needed for Linux, where a USB-to-serial device may have a very long name. The actual device name for USB-to-serial device, not the symlink, is used to achieve consistent name after the USB device is unplugged/plugged. An example device name on Ubuntu: /dev/serial/by-id/usb_to_serial_ftdi_FTDIXYZ_port0_0.
I've read the instructions as best I could and did as much research as possible. I'm not a guru, so forgive my ignorance, please. :)
On Mac OSX Lion, I followed your instructions for build, including:
chmod +x autoconf.sh
./autoconf.sh
./configure --prefix=$PWD/dist
and
sudo make install
I also ran it with and without the reported request to re-run glibtoolize after making the two entries that it requested.
The tail of sudo make install is as follows:
rs232_linux.c: In function 'rs232_set_baud':
rs232_linux.c:534: error: 'B460800' undeclared (first use in this function)
rs232_linux.c:534: error: (Each undeclared identifier is reported only once
rs232_linux.c:534: error: for each function it appears in.)
make[1]: *** [rs232_linux.lo] Error 1
make: *** [install-recursive] Error 1
So..... what'd I do?
Environment
Linux vbox 3.2.0-52-generic #78-Ubuntu SMP Fri Jul 26 16:21:44 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Installed lua5.2 libs
liblua5.2-0 - Shared library for the Lua interpreter version 5.2
liblua5.2-0-dbg - Debug symbols for the Lua shared library interpreter
liblua5.2-dev - Development files for the Lua language version 5.2
Even installed some 5.0 libraries
rfg@vbox:~/librs232$ sudo apt-get install liblualib50-dev
sudo: unable to resolve host vbox
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
liblua50 liblua50-dev liblualib50 lua50
The following NEW packages will be installed:
liblua50 liblua50-dev liblualib50 liblualib50-dev lua50
0 upgraded, 5 newly installed, 0 to remove and 3 not upgraded.
checking for Lua headers and librairies with pkg-config...
checking for Lua compiling and linking... no
configure: WARNING:
*** Lua (>=5.0) headers and/or librairies couldn't be found in your system.
*** Try to install liblua, liblualib and liblua-dev with your software package manager.
*** librs232 will be built without Lua bindings library.
luars232.c: In function 'lua_port_open':
luars232.c:112:3: error: implicit declaration of function 'lua_pushinteger' [-Werror=implicit-function-declaration]
luars232.c: In function 'lua_port_read':
luars232.c:169:3: error: implicit declaration of function 'luaL_checkinteger' [-Werror=implicit-function-declaration]
luars232.c: In function 'lua_port_get_strbaud':
luars232.c:381:1: error: implicit declaration of function 'luaL_optinteger' [-Werror=implicit-function-declaration]
luars232.c: In function 'create_metatables':
luars232.c:439:2: error: implicit declaration of function 'lua_setfield' [-Werror=implicit-function-declaration]
luars232.c:440:2: error: implicit declaration of function 'luaL_register' [-Werror=implicit-function-declaration]
cc1: all warnings being treated as errors
make[2]: *** [luars232.lo] Error 1
make[2]: Leaving directory /home/rfg/librs232/bindings/lua' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory
/home/rfg/librs232/bindings'
make: *** [all-recursive] Error 1
Greetings
Rafael
Hi ynezz,
i tried to install luars232 using luarocks today and got an error message on my Mac and on a Linux system, claiming 'Error: Directory 'invalid' not found'.
I took a look into luars232-1.0.3-1.rockspec and found a strange looking entry
copy_directories = {
"invalid"
},
After i had commented out that entry, i was able to build luars232 successfully on both my boxes.
BR
Sergeij
In rs232_windows.c fail.
392 line, char *wname = fix_device_name(p->dev);
wname is a static buffer, not malloced, so
It should not be free at 407 line.
Please check this.
I can not open "COM24" with luars232,but when I change the com port name to "COM4",luars232 open successfully.And I can open "COM24" with HyperTerminal (hypertrm.exe).
I examine the code of luars232,but have not found the reason,and I have not VS2005,so I just submit this issue here.
Thanks.
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.