代码拉取完成,页面将自动刷新
#include "home.h"
#include "ui_home.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
start();
}
Widget::~Widget()
{
stop();
delete ui;
}
void Widget::start()
{
if(2==LYP_DEBUG)
{
m_scom = new SerialCom();
m_scom->ScanPort();
m_scom->Connect();
m_icom = m_scom;
}
else
{
m_ucom = new UdpCom();
m_ucom->Connect();
m_icom = m_ucom;
}
if(m_icom->IsConnected())
{
connect(m_icom,SIGNAL(recvMsg()),this,SLOT(msgSwitch()));//msgSwitch()为自定义槽
//QMessageBox::information(NULL, "成功", "连接成功!\n"+m_icom->GetStatus());
m_is->SetInterface(m_icom, ui->tabWidget_home->currentIndex());
m_is->ipfetch();
}
else
{
QMessageBox::critical(NULL, "失败", "连接失败,端口被占用!\n"+m_icom->GetStatus());
QTimer::singleShot(200, this, SLOT(jumpQuit()));
}
}
int Widget::stop() const
{
if(2!=LYP_DEBUG)
{
if (m_ucom != nullptr)
{
m_ucom->Disconnect();
delete m_ucom;
}
}
else
{
if (m_scom != nullptr)
{
m_scom->Disconnect();
delete m_scom;
}
}
return 0;
}
void Widget::msgSwitch()
{
ComMessage msg;
QByteArray datagram;
if (!(m_icom->GetPacket(msg, 15)))
{
QStringList target = msg.m_target.split(':');
if (target.size() == 3)
{
// 获取到包
datagram = msg.getData();
qDebug() << msg.getData().toHex() << "Recv data lenth:" << msg.size();
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。