用VS2019+Qt5.12写了一个电子常用的调试测试数据采集软件,数据采集测试项,采用csv编写测试脚本,函数采用lua编写
支持串口、USB、TCPIP、GPIB 等……
视频链接:https://www.bilibili.com/video/BV1Vr421t7FP/?vd_source=0c434acccb950d1e5a3b1d5250fde4b8
测试界面图
配置文件
注册lua函数
int mcu_send(lua_State* L)
{
if (bMCUOpen == false)
{
return 0;
}
QString strSend = lua_tostring(L, -1);
strSend = strSend + "\r\n";
mcu_serialPort->write(strSend.toUtf8().constData()); //这句是真正的给单片机发数据 用到的是QIODevice::write 具体可以看文档
return 0;
}
int mcu_read(lua_State* L)
{
if (bMCUOpen == false)
{
return 0;
}
QString strread;
while (mcu_serialPort->waitForReadyRead(mcu_tmo))
{
strread = mcu_serialPort->readLine();
break;
}
lua_pushstring(L, strread.toUtf8().data());
return 1;
}
static const luaL_Reg lua_reg_mcu_funcs[] = {
{ "send", mcu_send },
{ "read", mcu_read },
{ NULL, NULL },
};
int luaopen_global_libs(lua_State* L)
{
// 创建一张新的表,并把列表的函数注册进去
luaL_newlib(L, lua_reg_global_funcs);
return 1;
}
int luaopen_dmm_libs(lua_State* L)
{
// 创建一张新的表,并把列表的函数注册进去
luaL_newlib(L, lua_reg_dmm_funcs);
return 1;
}
int luaopen_mcu_libs(lua_State* L)
{
// 创建一张新的表,并把列表的函数注册进去
luaL_newlib(L, lua_reg_mcu_funcs);
return 1;
}
static const luaL_Reg lua_reg_libs[] = {
{ "base", luaopen_base }, //系统模块
{ "Global", luaopen_global_libs},
{ "Dmm", luaopen_dmm_libs},
{ "MCU", luaopen_mcu_libs},
{ NULL, NULL }
};
调用lua 函数
QString doFun(QString str)
{
QString funRet = "";
QByteArray array = str.toLatin1();
const char* func = array.data();
lua_getglobal(L, func);
lua_pcall(L, 0, 1, 0);
funRet = lua_tostring(L, -1);
lua_pop(L, 1);
return funRet;
}
编译好的资源下载链接:
https://download.csdn.net/download/weixin_43645564/89080945
欢迎小伙伴们一起交流学习,谢谢!
需要源码的小伙伴们,请联系!