#include "sharedata.h" #include #include #include ShareData::ShareData(QObject *parent) : QObject(parent), mView(nullptr) { mSerialController = new SerialController(nullptr); QFile file("Test.lua"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return; QTextStream in(&file); mLuaScript = in.readAll(); qDebug()<< mLuaScript; mLua.DoString(mLuaScript); } int ShareData::SetQuickView(QQuickView *view) { QStringList comList; const auto infos = QSerialPortInfo::availablePorts(); for (const QSerialPortInfo &info : infos) { comList<mView = view; QObject *qmlObject = view->findChild("SerialSelect", Qt::FindChildOption::FindChildrenRecursively); if(nullptr != qmlObject) qmlObject->setProperty("comlist",comList); mProtoDebug = view->findChild("ProtoDebug", Qt::FindChildOption::FindChildrenRecursively); if(nullptr != mProtoDebug) mProtoDebug->setProperty("lua_script_text",mLuaScript); } int ShareData::OnDataRecv(QByteArray arr) { // qDebug()<OpenSerial(port,baudRate,dataBits,stopBits,flow) == 0){ mSerialController->SetListener(this); return 0; } qDebug()<<"openserial failed"; return -1; } int ShareData::CloseSerial() { if(mSerialController->CloseSerial() == 0){ qDebug()<<"close serial ok"; return 0; } qDebug()<<"cloase serial failed"; return -1; } int ShareData::TestLua() { mLua.OnDataRecv("ss"); } int ShareData::TestShowData() { if(nullptr != mProtoDebug){ QMetaObject::invokeMethod(mProtoDebug, "addString",Q_ARG(QVariant, QString("test\r\n"))); } return 0; }