我又来水博客了,哈哈哈,上一篇中大致介绍了一下实时网卡,那么这一篇中就来水水怎么用吧,在后期实际开发中会在Qt中使用。那么就看看再Qt中怎么使用。

引言

其实呢,在哪里用其实都差不多,无非就是包LIB库路径,include 头文件,运行的时候记得吧dll库带上,这基本就完成了。


1.保证环境没有问题

Qt可以是傻瓜式的安装就行,GE的驱动里面有exe,直接点击安装即可,完了记得到安装路径把“.h”“.liib”和“.dll”文件拷贝出来,如下

反射内存卡-2_GE5565


2.在Qt里面做好基本工作

主要就是修改pro文件,在pro中添加头文件路径和lib库路径。

INCLUDEPATH += C:\Users\WorkStation\Desktop\GE5565\GECore\Inc
LIBS += -LC:\Users\WorkStation\Desktop\GE5565\GECore\Lib -lrfm2gdll_stdc_32

在调用文件中include头文件

#include "rfm2g_windows.h"
#include "rfm2g_api.h"

剩下的就是基本的open read write close 了。


//open
void MainWindow::onpushbuttonopen()
{
RFM2G_STATUS result;
QString strpath = "\\\\.\\rfm2g";
strpath += ui->lineEdit_num->text();
QByteArray ba = strpath.toLatin1();
char *device = ba.data();
result = RFM2gOpen( device, &m_Handle);
if(result != RFM2G_SUCCESS)
{
qDebug() << device;
return;
}
m_timer->start(100);
}
//send
void MainWindow::onpushbuttonSend()
{
RFM2G_STATUS result;
QString strWrite = ui->lineEdit_write->text();
ui->lineEdit_write->clear();
QByteArray ba = strWrite.toLatin1();
char* data = ba.data();
result = RFM2gWrite(m_Handle,OFFSET,data,BUFFERSIZE);
}


//read
void MainWindow::onTimerOut()
{
RFM2G_STATUS result;
char buff[BUFFERSIZE];
result = RFM2gRead(m_Handle,OFFSET,buff,BUFFERSIZE);
QString strtext(buff);
if(strtext != m_strLast)
{
ui->textEdit_read->setText(strtext);
m_strLast = strtext;
}
}


//close
MainWindow::~MainWindow()
{
delete ui;
if(m_Handle)
{
RFM2gClose(&m_Handle);
}
}


Demo 连接