1.按照上一篇文章<QT如何调用外部LIB>将CH341的lib添加到工程中
2.直接上main.cpp代码
#include <QCoreApplication>
#include <windows.h>
#include <CH341DLL.H>
#include <qdebug.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
ULONG iIndex=0; // 指定CH341设备序号
UCHAR iDevice=87; // 低7位指定I2C设备地址
UCHAR iAddr=0; // 指定数据单元的地址
UCHAR oByte;
qDebug()<<CH341OpenDevice(iIndex); // 打开CH341设备,返回句柄,出错则无效
qDebug()<<CH341WriteI2C(iIndex,iDevice,iAddr,255);
qDebug()<<CH341ReadI2C(iIndex,iDevice,iAddr,&oByte);
qDebug()<<oByte;
CH341CloseDevice(0);// 关闭CH341设备
return a.exec();
}
3.Pro文件内容
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINE