My overall program goal is to create a better 3D printer calibration GUI using Lua and I luckily have the GUI part already working. I am trying to read and write to a COM port on my Windows 10 computer to the printer's Arduino. However, I am stumped by the serial communication. Currently, I have two FTDI cables wired together and can communicate between them using RealTerm (a terminal program) for testing, so I do know the wiring is correct. I am using ZeroBrane Studio for development but am not yet comfortable installing libraries.
So far, I have tried the following solutions:
- Attempt: Embed a powershell script to open the serial port
Result: No data comes out the port, but no errors are generated
- Attempt: Use srdgame/librs232 library
Result: require "rs232" fails in the code as it can't find the file. I installed the contents of SRC into the same directory as my Lua code, however it is probable that is not the right way to do it.
- Attempt: Use native io function in Lua
Result: I was able to send data using this method which is great news. However, I do not see a way to adjust the baud rate of the port. Going into device manager and mucking with the settings had no effect. It defaults to 115200bps.
Code:
file = io.open("COM5","wb")
io.output(file)
io.write("Hello world!")
Other options: I have installed luarocks, but cannot get it to install any libraries in Command Prompt. "Error: Could not find expected file ffi.lib, or ffi.dll, or libffi.dll for FFI -- you may have to install FFI in your system and/or set the FFI_DIR variable"
If any solutions require libraries, I would love some guidance on what files go where.
Thank you in advance!
PS: Here are some further references I investigated.
posix appears to only be for linux
lua-user.org Serial Communication wiki. I did not understand the instructions and their recommended library is out of data..
io.open("COM5:","wb")
would be more correct on Windows – Egor Skriptunoffos.execute[[mode COM5: baud=9600 parity=N data=8 stop=1]]
– Egor Skriptunofffile=io.popen("program args", "rb"); s=file:read"*a"; file:close()
– Egor SkriptunofffileIn = io.open("COM2:","rb"); io.input(fileIn); print(io.read("*line"));
– Ryan Friedman