Hello,
I've been trying for the past few days to create a Lua library that uses QSerialPort.
It works, but I've run into the following problem. Every time I call QSerialPort::write, I get the following warning:
QObject::startTimer: Timers can only be used with threads started with
QThread
QObject::startTimer: Timers can only be used with threads started with QThread
To copy to clipboard, switch view to plain text mode
My guess is that Lua uses its own threads, so I don't really know how to fix that.
For reference, here is a sample of what the code looks like:
class SerialIO {
public:
SerialIO(std::string deviceName);
~SerialIO();
public:
virtual bool open();
virtual void close();
virtual std::string read(int len);
virtual std::string readLine();
virtual bool write(std::string data);
private:
QSerialPort m_port;
};
class SerialIO {
public:
SerialIO(std::string deviceName);
~SerialIO();
public:
virtual bool open();
virtual void close();
virtual std::string read(int len);
virtual std::string readLine();
virtual bool write(std::string data);
private:
QSerialPort m_port;
};
To copy to clipboard, switch view to plain text mode
bool SerialIO::write(std::string data) {
if (m_port.isOpen()) {
return m_port.write(data.c_str(), data.length()) == data.length();
}
return false;
}
bool SerialIO::write(std::string data) {
if (m_port.isOpen()) {
return m_port.write(data.c_str(), data.length()) == data.length();
}
return false;
}
To copy to clipboard, switch view to plain text mode
The class is then registered into a Lua state, so that I can use it as a Lua module:
require "siema_cnx"
port = cnx.Serial("COM4")
port:open()
port:write(":RDREG 0\r\n")
answer = port:readLine()
print(answer)
port:close()
require "siema_cnx"
port = cnx.Serial("COM4")
port:open()
port:write(":RDREG 0\r\n")
answer = port:readLine()
print(answer)
port:close()
To copy to clipboard, switch view to plain text mode
The code works fine and I get the expected results, but Qt prints a warning I have no idea of how to get rid of.
Bookmarks