【用VS2019+Qt5.12+lua写了一个电子常用的调试测试数据采集软件,数据采集测试项,采用csv编写测试脚本,函数采用lua编写】

用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

欢迎小伙伴们一起交流学习,谢谢!

需要源码的小伙伴们,请联系!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值