javalikescript / luaserial

5 stars 1 forks source link

im on windows and keep getting this error:"lua54: main.lua:10: bad argument #1 to 'flush' (number expected, got nil) stack traceback: [C]: in function 'serial.flush' main.lua:10: in main chunk [C]: in ?" #1

Open Swift-mamba opened 9 months ago

Swift-mamba commented 9 months ago

here is my code:

local serialLib = require('serial')
local baudRate = 9600
local dataBits = 8
local stopBits = 1
local parity = 0
local portName = '\\\\.\\COM4'
local fd = io.open(portName, 'r+')
serialLib.flush(fd)
serialLib.setSerial(fd, baudRate, dataBits, stopBits, parity)
fd:read(1)
fd:close()
javalikescript commented 9 months ago

Hello,

I suggest you to check the return values of io.open so you may have more information regarding the issue.

local fd = assert(io.open(portName, 'r+'))

The io.open function could fail, see below on my computer where I do not have anything in COM4

> lua -e "print(io.open('\\\\.\\COM4', 'r+'))"
nil     \\.\COM4: No such file or directory     2

Hope it helps and have a good day, Samuel