@@ -0,0 +1,50 @@ | |||
#------------------------------------------------- | |||
# | |||
# Project created by QtCreator 2021-12-19T08:09:36 | |||
# | |||
#------------------------------------------------- | |||
QT += core gui | |||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | |||
TARGET = MotorControll_Project | |||
TEMPLATE = app | |||
DEFINES += QT_DEPRECATED_WARNINGS | |||
win32 | |||
{ | |||
CONFIG(debug,debug|release) | |||
{ | |||
LIBS+=$$PWD/xnet/lib/debug/libX_Net.a | |||
} | |||
CONFIG(release,debug|release) | |||
{ | |||
LIBS+=$$PWD/xnet/lib/release/libX_Net.a | |||
} | |||
INCLUDEPATH+=\ | |||
$$PWD/xnet/include/ \ | |||
$$PWD/motionctrl/include/ | |||
} | |||
SOURCES += main.cpp\ | |||
motorcontroll.cpp \ | |||
base.cpp \ | |||
xnetconnect.cpp \ | |||
addpar.cpp \ | |||
moretypemovement.cpp | |||
HEADERS += motorcontroll.h \ | |||
base.h \ | |||
xnet/include/x_net.h \ | |||
xnet/include/xnetclient.h \ | |||
xnetconnect.h \ | |||
addpar.h \ | |||
moretypemovement.h | |||
FORMS += motorcontroll.ui \ | |||
xnetconnect.ui \ | |||
addpar.ui \ | |||
moretypemovement.ui |
@@ -0,0 +1,312 @@ | |||
/******************************addpar.cpp文件说明********************************** | |||
* Descript :源文件,包含C运动参数配置窗口的函数实现 | |||
* Author :caitiancheng | |||
* Date :2021_12_19 | |||
*******************************************************************************/ | |||
/***********************************头文件****************************************/ | |||
#include "addpar.h" | |||
#include "ui_addpar.h" | |||
#include <QCloseEvent> | |||
#include <QMessageBox> | |||
/***********************************类的声明和继承****************************************/ | |||
AddPar::AddPar(QWidget *parent) : | |||
QWidget(parent), | |||
ui(new Ui::AddPar) | |||
{ | |||
ui->setupUi(this); | |||
//初始化配置 | |||
InitTree(); | |||
//设置窗口标题 | |||
setWindowTitle("C运动参数配置"); | |||
} | |||
/****************************closeEvent函数********************************* | |||
Function :窗口关闭事件函数 | |||
Output : | |||
*********************************************************************/ | |||
void AddPar::closeEvent(QCloseEvent *event) | |||
{ | |||
QMessageBox::StandardButton Value=QMessageBox::question(this,QStringLiteral("退出提示"),QStringLiteral("确认数据已经同步到设备?")); | |||
if(Value==QMessageBox::Yes) | |||
{ | |||
emit CloseWin(); | |||
event->accept(); | |||
}else | |||
{ | |||
event->ignore(); | |||
} | |||
} | |||
/****************************showEvent函数********************************* | |||
Function :如果从站连接上,更新数据 | |||
Output : | |||
*********************************************************************/ | |||
void AddPar::showEvent(QShowEvent *event) | |||
{ | |||
if(ConStatus()) | |||
{ | |||
event->accept(); | |||
Updata(); | |||
} | |||
} | |||
/****************************ReadArgRunCrl函数********************************* | |||
Function :读取从站数据 | |||
Output : | |||
*********************************************************************/ | |||
void AddPar::ReadArgRunCrl(QStandardItem *Item,int Addr,int Row) | |||
{ | |||
int Value; | |||
Value=ReadSFDInt(Addr); | |||
Item->child(Row,2)->setText(QString::number(Value)); | |||
} | |||
/****************************FreeQList函数********************************* | |||
Function :删除列表参数 | |||
Output : | |||
*********************************************************************/ | |||
void AddPar::FreeQList(QList<QStandardItem *> *Item) | |||
{ | |||
for(int i=0;i<Item->length();i++) | |||
{ | |||
delete Item->at(i); | |||
} | |||
} | |||
/****************************InitTree函数********************************* | |||
Function :初始化函数 | |||
Output : | |||
*********************************************************************/ | |||
void AddPar::InitTree() | |||
{ | |||
//定义数据行对象 | |||
QStringList QStrListTemp; | |||
//初始化模型 | |||
Model=new QStandardItemModel(); | |||
//配置分类选择信号 | |||
connect(Model,SIGNAL(itemChanged(QStandardItem*)),this,SLOT(TreeItemChanged(QStandardItem*))); | |||
//建立列名 | |||
TreeHead.push_back(QStringLiteral("名称")); | |||
TreeHead.push_back(QStringLiteral("离线值")); | |||
TreeHead.push_back(QStringLiteral("在线值")); | |||
TreeHead.push_back(QStringLiteral("单位")); | |||
TreeHead.push_back(QStringLiteral("备注")); | |||
Model->setHorizontalHeaderLabels(TreeHead); | |||
//建立行分类 | |||
BaseClass=new QStandardItem(QStringLiteral("基础参数")); | |||
RunCtrlClass=new QStandardItem(QStringLiteral("运动限制")); | |||
//建立分类可选择 | |||
BaseClass->setCheckable(true); | |||
BaseClass->setEditable(false); | |||
RunCtrlClass->setCheckable(true); | |||
RunCtrlClass->setEditable(false); | |||
//分类加入模型 | |||
Model->appendRow(BaseClass); | |||
Model->appendRow(RunCtrlClass); | |||
//建立数据行 | |||
//编码器的旋转计数 | |||
QStrListTemp.clear(); | |||
QStrListTemp.push_back(QStringLiteral("单圈脉冲")); | |||
QStrListTemp.push_back("0"); | |||
QStrListTemp.push_back("0"); | |||
QStrListTemp.push_back(""); | |||
QStrListTemp.push_back("编码器旋转一圈的计数值,根据电机编码器设定,如果17位,设置成131072"); | |||
NewChildLine(BaseClass,&BaseOtp,QStrListTemp); | |||
//每圈移动量 | |||
QStrListTemp.clear(); | |||
QStrListTemp.push_back(QStringLiteral("移动量")); | |||
QStrListTemp.push_back("0"); | |||
QStrListTemp.push_back("0"); | |||
QStrListTemp.push_back("脉冲"); | |||
QStrListTemp.push_back("每圈移动需要的脉冲"); | |||
NewChildLine(BaseClass,&BaseMnum,QStrListTemp); | |||
//最高速度 | |||
QStrListTemp.clear(); | |||
QStrListTemp.push_back(QStringLiteral("最大速度")); | |||
QStrListTemp.push_back("0"); | |||
QStrListTemp.push_back("0"); | |||
QStrListTemp.push_back("脉冲/秒"); | |||
QStrListTemp.push_back("电机可以运行的最大速度"); | |||
NewChildLine(RunCtrlClass,&RunSpeed,QStrListTemp); | |||
//最快加速度 | |||
QStrListTemp.clear(); | |||
QStrListTemp.push_back(QStringLiteral("最快加速度时间")); | |||
QStrListTemp.push_back("0"); | |||
QStrListTemp.push_back("0"); | |||
QStrListTemp.push_back("毫秒"); | |||
QStrListTemp.push_back("最快加速时间,根据该时间,系统自动计算对应加速相关参数"); | |||
NewChildLine(RunCtrlClass,&RunAddSpeed,QStrListTemp); | |||
//最快减速度 | |||
QStrListTemp.clear(); | |||
QStrListTemp.push_back(QStringLiteral("最快减速度时间")); | |||
QStrListTemp.push_back("0"); | |||
QStrListTemp.push_back("0"); | |||
QStrListTemp.push_back("毫秒"); | |||
QStrListTemp.push_back("最快减速时间,根据该时间,系统自动计算对应减速相关参数"); | |||
NewChildLine(RunCtrlClass,&RunSubSpeed,QStrListTemp); | |||
//加载模型到树 | |||
ui->ArgDataTreeView->setModel(Model); | |||
ui->ArgDataTreeView->expandAll(); | |||
} | |||
/****************************TreeItemChanged函数********************************* | |||
Function :模型数参数改变 | |||
Output : | |||
*********************************************************************/ | |||
void AddPar::TreeItemChanged(QStandardItem *Item) | |||
{ | |||
if (Item->isCheckable()&&Item->hasChildren()) | |||
{ | |||
Qt::CheckState status = Item->checkState (); | |||
for(int i = 0;i<Item->rowCount();++i) | |||
{ | |||
QStandardItem* ItemChild = Item->child(i); | |||
ItemChild->setCheckState(status); | |||
} | |||
} | |||
} | |||
/****************************NewChildLine函数********************************* | |||
Function :新子行建立 | |||
Output : | |||
*********************************************************************/ | |||
void AddPar::NewChildLine(QStandardItem *Item,QList<QStandardItem *> *ItemList,QStringList Data) | |||
{ | |||
int RowCount; | |||
ItemList->clear(); | |||
for(int i=0;i<Data.length();i++) | |||
{ | |||
ItemList->push_back(new QStandardItem(Data.at(i))); | |||
if(i!=1) | |||
{ | |||
ItemList->at(i)->setEditable(false); | |||
} | |||
} | |||
RowCount=Item->rowCount(); | |||
ItemList->at(0)->setCheckable(true); | |||
Item->appendRow(ItemList->at(0)); | |||
for(int i=1;i<Data.length();i++) | |||
{ | |||
Item->setChild(RowCount,i,ItemList->at(i)); | |||
} | |||
} | |||
/****************************DownLoadData函数********************************* | |||
Function :下载从站数据 | |||
Output : | |||
*********************************************************************/ | |||
int AddPar::DownLoadData(QStandardItem *Item,QString Name,int Addr,int Row) | |||
{ | |||
bool ok=true; | |||
int Value=0; | |||
if(Item->child(Row)->checkState()==Qt::Checked) | |||
{ | |||
Value=Item->child(Row,1)->text().toInt(&ok); | |||
if(!ok) | |||
{ | |||
QMessageBox::information(this,Name,QStringLiteral("写入失败")); | |||
return ReFild; | |||
} | |||
WriteSFDInt(Addr,Value); | |||
return ReSuess; | |||
} | |||
return ReUncheck; | |||
} | |||
/****************************下载按钮槽函数********************************* | |||
Function :点击下载按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void AddPar::on_DownloadBtn_clicked() | |||
{ | |||
int count=0; | |||
int value=0; | |||
if(!ConStatus()) | |||
{ | |||
QMessageBox::information(this,QStringLiteral("连接提示"),QStringLiteral("当前处于未连接状态")); | |||
} | |||
else | |||
{ | |||
value=DownLoadData(BaseClass,"单圈脉冲",3002,0); | |||
count+=value==1?1:0; | |||
value=DownLoadData(BaseClass,"移动量",3004,1); | |||
count+=value==1?1:0; | |||
value=DownLoadData(RunCtrlClass,"最大速度",3018,0); | |||
count+=value==1?1:0; | |||
value=DownLoadData(RunCtrlClass,"最快加速度时间",3020,1); | |||
count+=value==1?1:0; | |||
value=DownLoadData(RunCtrlClass,"最快减速度时间",3022,2); | |||
count+=value==1?1:0; | |||
QMessageBox::information(this,QStringLiteral("下载提示"),QStringLiteral("写入成功:")+QString::number(count)); | |||
} | |||
} | |||
/****************************Updata函数********************************* | |||
Function :更新数据的函数 | |||
Output : | |||
*********************************************************************/ | |||
void AddPar::Updata() | |||
{ | |||
ReadArgRunCrl(BaseClass,3002,0); | |||
ReadArgRunCrl(BaseClass,3004,1); | |||
ReadArgRunCrl(RunCtrlClass,3018,0); | |||
ReadArgRunCrl(RunCtrlClass,3020,1); | |||
ReadArgRunCrl(RunCtrlClass,3022,2); | |||
} | |||
/****************************上载参数按钮槽函数********************************* | |||
Function :点击上载参数按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void AddPar::on_UploadBtn_clicked() | |||
{ | |||
if(!ConStatus()) | |||
{ | |||
QMessageBox::information(this,QStringLiteral("连接提示"),QStringLiteral("当前处于未连接状态")); | |||
} | |||
else | |||
{ | |||
Updata(); | |||
} | |||
} | |||
/******************************************************析构函数*****************************************************/ | |||
AddPar::~AddPar() | |||
{ | |||
delete Model; | |||
delete BaseClass; | |||
FreeQList(&BaseOtp); | |||
FreeQList(&BaseMnum); | |||
delete RunCtrlClass; | |||
FreeQList(&RunSpeed); | |||
FreeQList(&RunAddSpeed); | |||
FreeQList(&RunSubSpeed); | |||
delete ui; | |||
} | |||
@@ -0,0 +1,71 @@ | |||
/******************************addpar.h文件说明********************************** | |||
* Descript :头文件,包含C运动参数配置窗口的头文件引用,以及宏定义 | |||
* Author :caitiancheng | |||
* Date :2021_12_19 | |||
*******************************************************************************/ | |||
#ifndef ADDPAR_H | |||
#define ADDPAR_H | |||
/***********************************头文件****************************************/ | |||
#include <QWidget> | |||
#include <QStandardItemModel> | |||
#include <Base.h> | |||
/***********************************类的声明和继承****************************************/ | |||
namespace Ui { | |||
class AddPar; | |||
} | |||
class AddPar : public QWidget,public Base | |||
{ | |||
Q_OBJECT | |||
public: | |||
explicit AddPar(QWidget *parent = 0); | |||
~AddPar(); | |||
signals: | |||
void CloseWin(); | |||
protected: | |||
void closeEvent(QCloseEvent *event=NULL); | |||
void showEvent(QShowEvent *event=NULL); | |||
private slots: | |||
void TreeItemChanged(QStandardItem *Item); | |||
void on_DownloadBtn_clicked(); | |||
void on_UploadBtn_clicked(); | |||
private: | |||
typedef enum {ReFild,ReSuess,ReUncheck}ReturnFlag; | |||
Ui::AddPar *ui; | |||
void InitTree(); | |||
QStringList TreeHead; | |||
QStandardItemModel *Model; | |||
//基础参数 | |||
QStandardItem *BaseClass; | |||
//一圈脉冲 | |||
QList<QStandardItem *> BaseOtp; | |||
//移动量 | |||
QList<QStandardItem *> BaseMnum; | |||
//运动限制 | |||
QStandardItem *RunCtrlClass; | |||
//最高速度 | |||
QList<QStandardItem *> RunSpeed; | |||
//最快加速度 | |||
QList<QStandardItem *> RunAddSpeed; | |||
//最快减速度 | |||
QList<QStandardItem *> RunSubSpeed; | |||
int DownLoadData(QStandardItem *Item,QString Name,int Addr,int Row); | |||
void Updata(); | |||
void NewChildLine(QStandardItem *Item,QList<QStandardItem *> *ItemList,QStringList Data); | |||
void ReadArgRunCrl(QStandardItem *Item,int Addr,int Row); | |||
void FreeQList(QList<QStandardItem *> *Item); | |||
}; | |||
#endif // ADDPAR_H |
@@ -0,0 +1,71 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<ui version="4.0"> | |||
<class>AddPar</class> | |||
<widget class="QWidget" name="AddPar"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>0</x> | |||
<y>0</y> | |||
<width>535</width> | |||
<height>300</height> | |||
</rect> | |||
</property> | |||
<property name="windowTitle"> | |||
<string>Form</string> | |||
</property> | |||
<widget class="QTreeView" name="ArgDataTreeView"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>11</x> | |||
<y>11</y> | |||
<width>513</width> | |||
<height>241</height> | |||
</rect> | |||
</property> | |||
<attribute name="headerCascadingSectionResizes"> | |||
<bool>true</bool> | |||
</attribute> | |||
</widget> | |||
<widget class="QWidget" name="layoutWidget"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>10</x> | |||
<y>260</y> | |||
<width>511</width> | |||
<height>30</height> | |||
</rect> | |||
</property> | |||
<layout class="QGridLayout" name="gridLayout"> | |||
<item row="0" column="0"> | |||
<spacer name="horizontalSpacer"> | |||
<property name="orientation"> | |||
<enum>Qt::Horizontal</enum> | |||
</property> | |||
<property name="sizeHint" stdset="0"> | |||
<size> | |||
<width>40</width> | |||
<height>20</height> | |||
</size> | |||
</property> | |||
</spacer> | |||
</item> | |||
<item row="0" column="2"> | |||
<widget class="QPushButton" name="DownloadBtn"> | |||
<property name="text"> | |||
<string>下载参数</string> | |||
</property> | |||
</widget> | |||
</item> | |||
<item row="0" column="1"> | |||
<widget class="QPushButton" name="UploadBtn"> | |||
<property name="text"> | |||
<string>上载参数</string> | |||
</property> | |||
</widget> | |||
</item> | |||
</layout> | |||
</widget> | |||
</widget> | |||
<resources/> | |||
<connections/> | |||
</ui> |
@@ -0,0 +1,132 @@ | |||
/******************************base.cpp文件说明********************************** | |||
* Descript :源文件,包含项目所需要使用的Xnet函数的实现 | |||
* Author :caitiancheng | |||
* Date :2021_12_19 | |||
*******************************************************************************/ | |||
/******************************************头文件***********************************************/ | |||
#include "base.h" | |||
/****************************ConStatus函数********************************* | |||
Function :读从站连接状态 | |||
Output :从站连接状态 | |||
*********************************************************************/ | |||
bool Base::ConStatus() | |||
{ | |||
bool Ok=true; | |||
short Res; | |||
Read_Short(XNet_SD,8020,1,&Res); | |||
if(Res==1) | |||
{ | |||
Ok=true; | |||
}else | |||
{ | |||
Ok=false; | |||
} | |||
return Ok; | |||
} | |||
/****************************SalveStatus函数********************************* | |||
Function :读从站状态 | |||
Output :返回读出的值 | |||
*********************************************************************/ | |||
int Base::SalveStatus() | |||
{ | |||
short Res; | |||
Read_Short(XNet_SD,8021,1,&Res); | |||
return Res; | |||
} | |||
/****************************WriteMBool函数********************************* | |||
Function :写M寄存器的值 | |||
Output : | |||
*********************************************************************/ | |||
void Base::WriteMBool(int start,bool ok) | |||
{ | |||
Write_Bool(XNet_M,start,1,ok); | |||
} | |||
/****************************WriteDShort函数********************************* | |||
Function :写D寄存器short型(单字)的值 | |||
Output : | |||
*********************************************************************/ | |||
void Base::WriteDShort(int start,short value) | |||
{ | |||
Write_Short(XNet_D,start,1,value); | |||
} | |||
/****************************WriteDInt函数********************************* | |||
Function :写D寄存器int型(双字)的值 | |||
Output : | |||
*********************************************************************/ | |||
void Base::WriteDInt(int start,int value) | |||
{ | |||
Write_Int(XNet_D,start,2,value); | |||
} | |||
/****************************WriteSDShort函数********************************* | |||
Function :写SD寄存器short型的值 | |||
Output : | |||
*********************************************************************/ | |||
void Base::WriteSDShort(int start,int value) | |||
{ | |||
Write_Short(XNet_SD,start,2,value); | |||
} | |||
/****************************WriteSFDInt函数********************************* | |||
Function :写SFD寄存器int型的值 | |||
Output : | |||
*********************************************************************/ | |||
void Base::WriteSFDInt(int start,int value) | |||
{ | |||
Write_Int(XNet_SFD,start,2,value); | |||
} | |||
/****************************ReadSFDInt函数********************************* | |||
Function :读SFD寄存器int型的值 | |||
Output :返回读出的值 | |||
*********************************************************************/ | |||
int Base::ReadSFDInt(int Addr) | |||
{ | |||
int ResValue; | |||
Read_Int(XNet_SFD,Addr,2,&ResValue); | |||
return ResValue; | |||
} | |||
/****************************ReadSMBool函数********************************* | |||
Function :读SM寄存器的值 | |||
Output :返回读出的值 | |||
*********************************************************************/ | |||
bool Base::ReadSMBool(int Addr) | |||
{ | |||
bool ResValue; | |||
Read_Bool(XNet_SM,Addr,1,&ResValue); | |||
return ResValue; | |||
} | |||
/****************************ReadSDShort函数********************************* | |||
Function :读SD寄存器的值 | |||
Output :返回读出的值 | |||
*********************************************************************/ | |||
short Base::ReadSDShort(int Addr) | |||
{ | |||
short ResValue; | |||
Read_Short(XNet_SD,Addr,1,&ResValue); | |||
return ResValue; | |||
} | |||
@@ -0,0 +1,45 @@ | |||
/******************************base.h文件说明********************************** | |||
* Descript :头文件,包含项目需要调用的Xnet函数的头文件引用,以及宏定义 | |||
* Author :caitiancheng | |||
* Date :2021_12_19 | |||
*******************************************************************************/ | |||
#ifndef BASE_H | |||
#define BASE_H | |||
/***********************************头文件****************************************/ | |||
#include <x_net.h> | |||
#include <QString> | |||
/***********************************类的声明和继承****************************************/ | |||
class Base | |||
{ | |||
public: | |||
//判断连接状态的函数 | |||
bool ConStatus(); | |||
//从从站状态函数 | |||
int SalveStatus(); | |||
//M寄存器写值函数 | |||
void WriteMBool(int start,bool ok); | |||
//D寄存器写short型值函数 | |||
void WriteDShort(int start,short value); | |||
//SD寄存器写short型值函数 | |||
void WriteSDShort(int start,int value); | |||
//D寄存器写int型值函数 | |||
void WriteDInt(int start,int value); | |||
//SFD寄存器写int型值函数 | |||
void WriteSFDInt(int start,int value); | |||
//读SM寄存器的值 | |||
bool ReadSMBool(int Addr); | |||
//读SFD寄存器的值 | |||
int ReadSFDInt(int Addr); | |||
//读SD寄存器的值 | |||
short ReadSDShort(int Addr); | |||
}; | |||
#endif // BASE_H |
@@ -0,0 +1,22 @@ | |||
/******************************main.cpp文件说明********************************** | |||
* Descript :.cpp文件,包含main函数的程序入口 | |||
* Author :caitiancheng | |||
* Date :2021_12_18 | |||
*******************************************************************************/ | |||
/***********************************头文件****************************************/ | |||
#include "motorcontroll.h" | |||
#include <QApplication> | |||
/***********************************主函数****************************************/ | |||
int main(int argc, char *argv[]) | |||
{ | |||
QApplication a(argc, argv); | |||
MotorControll w; | |||
w.show(); | |||
return a.exec(); | |||
} |
@@ -0,0 +1,270 @@ | |||
/******************************moretypemovement.cpp文件说明********************************** | |||
* Descript :.源文件,包含多段运动添加数据窗口的函数实现 | |||
* Author :caitiancheng | |||
* Date :2021_12_18 | |||
*******************************************************************************/ | |||
/******************************************头文件***********************************************/ | |||
#include "moretypemovement.h" | |||
#include "ui_moretypemovement.h" | |||
#include <QMessageBox> | |||
#include <QCloseEvent> | |||
/***********************************类的声明和继承****************************************/ | |||
MoreTypeMovement::MoreTypeMovement(QWidget *parent) : | |||
QWidget(parent), | |||
ui(new Ui::MoreTypeMovement) | |||
{ | |||
ui->setupUi(this); | |||
InitDataTable(); | |||
} | |||
/****************************InitDataTable函数********************************* | |||
Function :初始化数据窗口函数 | |||
Output : | |||
*********************************************************************/ | |||
void MoreTypeMovement::InitDataTable() | |||
{ | |||
QStringList TableHeadTitle; | |||
int TableHeadTitleLength; | |||
TableHeadTitle.push_back(QStringLiteral("位置")); | |||
TableHeadTitle.push_back(QStringLiteral("速度")); | |||
TableHeadTitleLength=TableHeadTitle.length(); | |||
ui->RunDataTWidget->setColumnCount(TableHeadTitleLength); | |||
for(int i=0;i<TableHeadTitleLength;i++) | |||
{ | |||
TableHeadItem.push_back(new QTableWidgetItem(TableHeadTitle[i])); | |||
ui->RunDataTWidget->setHorizontalHeaderItem(i,TableHeadItem[i]); | |||
} | |||
ui->RunDataTWidget->horizontalHeader()->setStretchLastSection(true); | |||
ui->DelRowDataBtn->setEnabled(false); | |||
ui->DownRowDataBtn->setEnabled(false); | |||
ui->UpRowDataBtn->setEnabled(false); | |||
ui->WriteRowDataBtn->setEnabled(false); | |||
} | |||
/****************************CopyTableRow函数********************************* | |||
Function :复制数据表排函数 | |||
Output : | |||
*********************************************************************/ | |||
void MoreTypeMovement::CopyTableRow(int AtRow,int ToRow) | |||
{ | |||
int ColumnCountLog = ui->RunDataTWidget->columnCount(); | |||
for(int i=0; i<ColumnCountLog; i++){ | |||
QString TableItemValue = ui->RunDataTWidget->item(AtRow, i)->text(); | |||
QTableWidgetItem *TableItemdm = new QTableWidgetItem; | |||
TableItemdm->setText(TableItemValue); | |||
ui->RunDataTWidget->setItem(ToRow, i, TableItemdm); | |||
} | |||
} | |||
/****************************MoveTableRow函数********************************* | |||
Function :移动数据表排函数 | |||
Output : | |||
*********************************************************************/ | |||
void MoreTypeMovement::MoveTableRow(int AtRow,int ToRow) | |||
{ | |||
int RowSum=ui->RunDataTWidget->rowCount(); | |||
int RowTarget=0; | |||
bool direction=AtRow<ToRow?true:false; | |||
if(direction&&ToRow>RowSum-1) | |||
{ | |||
return; | |||
} | |||
if(!direction&&ToRow<0) | |||
{ | |||
return; | |||
} | |||
int SelectColumn=-1; | |||
QTableWidgetItem *SelectItem= ui->RunDataTWidget->currentItem(); | |||
if(SelectItem!=NULL) | |||
{ | |||
SelectColumn=SelectItem->column(); | |||
} | |||
if(direction) | |||
{ | |||
RowTarget=ToRow+1; | |||
ui->RunDataTWidget->insertRow(RowTarget); | |||
CopyTableRow(AtRow,RowTarget); | |||
ui->RunDataTWidget->removeRow(AtRow); | |||
}else | |||
{ | |||
RowTarget=ToRow; | |||
ui->RunDataTWidget->insertRow(RowTarget); | |||
CopyTableRow(AtRow+1,RowTarget); | |||
ui->RunDataTWidget->removeRow(AtRow+1); | |||
} | |||
ui->RunDataTWidget->selectRow(ToRow); | |||
if(SelectColumn>-1) | |||
{ | |||
ui->RunDataTWidget->setCurrentCell(ToRow,SelectColumn); | |||
} | |||
} | |||
/****************************GetTableNum函数********************************* | |||
Function :获取列表行数 | |||
Output : | |||
*********************************************************************/ | |||
int MoreTypeMovement::GetTableNum(QString &Str,bool *ok) | |||
{ | |||
int ResNum=0; | |||
int Slen=0; | |||
if(ok==NULL) | |||
{ | |||
bool BoolTemp; | |||
ok=&BoolTemp; | |||
} | |||
*ok=false; | |||
if(Str.isEmpty()) | |||
{ | |||
return ResNum; | |||
} | |||
Slen=Str.length(); | |||
for(int i=0;i<Slen;i++) | |||
{ | |||
if(Str.at(i)>='0'&&Str.at(i)<='9') | |||
{ | |||
ResNum=ResNum*10+Str.at(i).toLatin1()-'0'; | |||
}else | |||
{ | |||
return 0; | |||
} | |||
} | |||
*ok=true; | |||
return ResNum; | |||
} | |||
/****************************closeEvent函数********************************* | |||
Function :关闭窗口事件函数 | |||
Output : | |||
*********************************************************************/ | |||
void MoreTypeMovement::closeEvent(QCloseEvent *event) | |||
{ | |||
QMessageBox::StandardButton Value=QMessageBox::question(this,QStringLiteral("退出提示"),QStringLiteral("确认数据已经同步到设备?")); | |||
if(Value==QMessageBox::Yes) | |||
{ | |||
emit CloseWin(); | |||
event->accept(); | |||
}else | |||
{ | |||
event->ignore(); | |||
} | |||
} | |||
/******************************************************析构函数*****************************************************/ | |||
MoreTypeMovement::~MoreTypeMovement() | |||
{ | |||
delete ui; | |||
} | |||
/****************************************************槽函数*****************************************************/ | |||
/****************************添加按钮槽函数********************************* | |||
Function :点击添加按钮,触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MoreTypeMovement::on_AddRowDataBtn_clicked() | |||
{ | |||
int Row=ui->RunDataTWidget->rowCount(); | |||
if(Row>14) | |||
{ | |||
QMessageBox::information(this,QStringLiteral("添加数据"),QStringLiteral("最多只能添加15段运动")); | |||
return; | |||
} | |||
ui->RunDataTWidget->insertRow(Row); | |||
ui->DelRowDataBtn->setEnabled(true); | |||
ui->DownRowDataBtn->setEnabled(true); | |||
ui->UpRowDataBtn->setEnabled(true); | |||
ui->WriteRowDataBtn->setEnabled(true); | |||
} | |||
/****************************删除按钮槽函数********************************* | |||
Function :点击删除按钮,触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MoreTypeMovement::on_DelRowDataBtn_clicked() | |||
{ | |||
int Row=ui->RunDataTWidget->currentRow(); | |||
if(Row!=-1) | |||
{ | |||
ui->RunDataTWidget->removeRow(Row); | |||
} | |||
} | |||
/****************************上移按钮槽函数********************************* | |||
Function :点击上移按钮,触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MoreTypeMovement::on_UpRowDataBtn_clicked() | |||
{ | |||
int Row=ui->RunDataTWidget->currentRow(); | |||
MoveTableRow(Row,Row-1); | |||
} | |||
/****************************下移按钮槽函数********************************* | |||
Function :点击上移按钮,触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MoreTypeMovement::on_DownRowDataBtn_clicked() | |||
{ | |||
int Row=ui->RunDataTWidget->currentRow(); | |||
MoveTableRow(Row,Row+1); | |||
} | |||
/****************************写入按钮槽函数********************************* | |||
Function :点击写入按钮,触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MoreTypeMovement::on_WriteRowDataBtn_clicked() | |||
{ | |||
int Row=ui->RunDataTWidget->rowCount(); | |||
QString PlaceTemp; | |||
QString SpeedTemp; | |||
int WriteCount=0; | |||
int RegAddr=250; | |||
bool ok1,ok2; | |||
int iPlaceTemp; | |||
int iSpeedTemp; | |||
for(int i=0;i<Row;i++) | |||
{ | |||
PlaceTemp=ui->RunDataTWidget->item(i,0)->text(); | |||
SpeedTemp=ui->RunDataTWidget->item(i,1)->text(); | |||
iPlaceTemp=GetTableNum(PlaceTemp,&ok1); | |||
iSpeedTemp=GetTableNum(SpeedTemp,&ok2); | |||
if(ok1&&ok2) | |||
{ | |||
WriteDInt(RegAddr,iPlaceTemp); | |||
WriteDInt(RegAddr+2,iSpeedTemp); | |||
RegAddr+=10; | |||
WriteCount++; | |||
} | |||
} | |||
WriteDInt(402,WriteCount); | |||
QMessageBox::information(this,QStringLiteral("写入提示"),QStringLiteral("总共写入:")+QString::number(WriteCount)+QStringLiteral("段")); | |||
} |
@@ -0,0 +1,59 @@ | |||
/******************************moretypemovement.h文件说明********************************** | |||
* Descript :头文件,包含多段运动添加数据窗口的函数声明、头文件引用,以及宏定义 | |||
* Author :caitiancheng | |||
* Date :2021_12_19 | |||
*******************************************************************************/ | |||
#ifndef MORETYPEMOVEMENT_H | |||
#define MORETYPEMOVEMENT_H | |||
/***********************************头文件****************************************/ | |||
#include <QWidget> | |||
#include<QTableWidgetItem> | |||
#include<QMessageBox> | |||
#include<Base.h> | |||
/***********************************类的声明和继承****************************************/ | |||
namespace Ui { | |||
class MoreTypeMovement; | |||
} | |||
class MoreTypeMovement : public QWidget,public Base | |||
{ | |||
Q_OBJECT | |||
public: | |||
explicit MoreTypeMovement(QWidget *parent = 0); | |||
~MoreTypeMovement(); | |||
signals: | |||
void CloseWin(); | |||
protected: | |||
void closeEvent(QCloseEvent *event=NULL); | |||
private slots: | |||
void on_AddRowDataBtn_clicked(); | |||
void on_DelRowDataBtn_clicked(); | |||
void on_UpRowDataBtn_clicked(); | |||
void on_DownRowDataBtn_clicked(); | |||
void on_WriteRowDataBtn_clicked(); | |||
private: | |||
Ui::MoreTypeMovement *ui; | |||
QList<QTableWidgetItem *> TableHeadItem; | |||
void InitDataTable(); | |||
void CopyTableRow(int AtRow,int ToRow); | |||
void MoveTableRow(int AtRow,int ToRow); | |||
int GetTableNum(QString &Str,bool *ok=NULL); | |||
}; | |||
#endif // MORETYPEMOVEMENT_H |
@@ -0,0 +1,142 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<ui version="4.0"> | |||
<class>MoreTypeMovement</class> | |||
<widget class="QWidget" name="MoreTypeMovement"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>0</x> | |||
<y>0</y> | |||
<width>662</width> | |||
<height>367</height> | |||
</rect> | |||
</property> | |||
<property name="windowTitle"> | |||
<string>Form</string> | |||
</property> | |||
<widget class="QTableWidget" name="RunDataTWidget"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>30</x> | |||
<y>10</y> | |||
<width>598</width> | |||
<height>290</height> | |||
</rect> | |||
</property> | |||
<property name="showGrid"> | |||
<bool>true</bool> | |||
</property> | |||
<property name="sortingEnabled"> | |||
<bool>false</bool> | |||
</property> | |||
<property name="wordWrap"> | |||
<bool>true</bool> | |||
</property> | |||
<property name="cornerButtonEnabled"> | |||
<bool>true</bool> | |||
</property> | |||
<attribute name="horizontalHeaderVisible"> | |||
<bool>true</bool> | |||
</attribute> | |||
<attribute name="horizontalHeaderCascadingSectionResizes"> | |||
<bool>true</bool> | |||
</attribute> | |||
<attribute name="horizontalHeaderDefaultSectionSize"> | |||
<number>131</number> | |||
</attribute> | |||
<attribute name="horizontalHeaderHighlightSections"> | |||
<bool>false</bool> | |||
</attribute> | |||
<attribute name="horizontalHeaderMinimumSectionSize"> | |||
<number>30</number> | |||
</attribute> | |||
<attribute name="horizontalHeaderShowSortIndicator" stdset="0"> | |||
<bool>false</bool> | |||
</attribute> | |||
<attribute name="horizontalHeaderStretchLastSection"> | |||
<bool>true</bool> | |||
</attribute> | |||
<attribute name="verticalHeaderVisible"> | |||
<bool>false</bool> | |||
</attribute> | |||
<attribute name="verticalHeaderCascadingSectionResizes"> | |||
<bool>false</bool> | |||
</attribute> | |||
<attribute name="verticalHeaderHighlightSections"> | |||
<bool>true</bool> | |||
</attribute> | |||
<attribute name="verticalHeaderShowSortIndicator" stdset="0"> | |||
<bool>false</bool> | |||
</attribute> | |||
<attribute name="verticalHeaderStretchLastSection"> | |||
<bool>false</bool> | |||
</attribute> | |||
</widget> | |||
<widget class="QPushButton" name="AddRowDataBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>30</x> | |||
<y>320</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>添加</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="DelRowDataBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>150</x> | |||
<y>320</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>删除</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="UpRowDataBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>270</x> | |||
<y>320</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>上移</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="DownRowDataBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>390</x> | |||
<y>320</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>下移</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="WriteRowDataBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>520</x> | |||
<y>320</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>写入</string> | |||
</property> | |||
</widget> | |||
</widget> | |||
<resources/> | |||
<connections/> | |||
</ui> |
@@ -0,0 +1,693 @@ | |||
/******************************motorcontroll.cpp文件说明********************************** | |||
* Descript :源文件,包含主窗口的页面设计、函数的实现、信号的连接 | |||
* Author :caitiancheng | |||
* Date :2021_12_19 | |||
*******************************************************************************/ | |||
/***********************************头文件****************************************/ | |||
#include "motorcontroll.h" | |||
#include "ui_motorcontroll.h" | |||
#include<QDateTime> | |||
#include <QCloseEvent> | |||
/***********************************类的声明和继承****************************************/ | |||
MotorControll::MotorControll(QWidget *parent) : | |||
QMainWindow(parent), | |||
ui(new Ui::MotorControll) | |||
{ | |||
ui->setupUi(this); | |||
//从站连接状态定时器 | |||
StatuTimer=new QTimer; | |||
//时间显示定时器 | |||
TimeShow=new QTimer; | |||
//监视栏定时器 | |||
Monitor=new QTimer; | |||
//控件连接的信号和槽函数 | |||
InitConnect(); | |||
//状态栏界面设置初始化函数 | |||
InitBarStatus(); | |||
//监视栏舒适化函数 | |||
InitMonitor(); | |||
//未进行通信连接时设置按钮不可按 | |||
//基础配置的按钮(3个) | |||
ui->pushButton_2->setEnabled(false); | |||
ui->pushButton_3->setEnabled(false); | |||
ui->pushButton_4->setEnabled(false); | |||
//点动的按钮(6个) | |||
ui->DotKeepRunBtn->setEnabled(false); | |||
ui->DotPositiveBtn->setEnabled(false); | |||
ui->DotReverseBtn->setEnabled(false); | |||
ui->DotSpeedUpdataBtn->setEnabled(false); | |||
ui->DotStepUpdataBtn->setEnabled(false); | |||
ui->DotStopRunBtn->setEnabled(false); | |||
//基础运动的按钮(8个) | |||
ui->RunKeepBtn->setEnabled(false); | |||
ui->RunPlaceUpdataBtn->setEnabled(false); | |||
ui->RunSpeedUpdataBtn->setEnabled(false); | |||
ui->RunStartAbsolutBtn->setEnabled(false); | |||
ui->RunStartPlaceModifyBtn->setEnabled(false); | |||
ui->RunStartRelativeBtn->setEnabled(false); | |||
ui->RunStopBtn->setEnabled(false); | |||
ui->RunTimeUpdataBtn->setEnabled(false); | |||
//多段运动的按钮(5个)+1个多选框 | |||
ui->RunMoreAddRunBtn->setEnabled(false); | |||
ui->RunMoreDataUpdataBtn->setEnabled(false); | |||
ui->RunMoreKeepBtn->setEnabled(false); | |||
ui->RunMoreModelBox->setEnabled(false); | |||
ui->RunMoreStartBtn->setEnabled(false); | |||
ui->RunMoreStopBtn->setEnabled(false); | |||
} | |||
/******************************************************析构函数*****************************************************/ | |||
MotorControll::~MotorControll() | |||
{ | |||
//销毁状态栏显示相关 | |||
delete ConStatusText; | |||
delete ConStatusImg; | |||
delete SalveStatusText; | |||
delete SalveStatusShow; | |||
//销毁定时器 | |||
delete StatuTimer; | |||
delete TimeShow; | |||
delete Monitor; | |||
//销毁监视栏的监视对象 | |||
int MonitorLogsLen=MonitorLogs.length(); | |||
for(int i=0;i<MonitorLogsLen;i++) | |||
{ | |||
delete MonitorLogs.at(i); | |||
} | |||
delete MonitorSM2001; | |||
delete MonitorSM2010; | |||
delete MonitorSM2011; | |||
delete MonitorSM2012; | |||
delete MonitorSD2042; | |||
delete MonitorSD2040; | |||
delete MonitorSD2001; | |||
delete MonitorSD2010; | |||
delete MonitorSD2008; | |||
delete MonitorSD2030; | |||
delete MonitorSD2032; | |||
delete MonitorSD2034; | |||
delete MonitorSD2036; | |||
delete ui; | |||
} | |||
/****************************InitBarStatus函数********************************* | |||
Function :初始化界面状态栏,进行相应的设置 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::InitBarStatus() | |||
{ | |||
ui->statusBar->setStyleSheet(QString("QStatusBar::item{border:0px}")); | |||
ConStatusText=new QLabel; | |||
ConStatusText->setAlignment(Qt::AlignRight | Qt::AlignVCenter); | |||
ConStatusText->setText(QStringLiteral("通信状态:")); | |||
ui->statusBar->addPermanentWidget(ConStatusText); | |||
ConStatusImg=new QLabel; | |||
ConStatusImg->setStyleSheet(m_red_SheetStyle); | |||
ConStatusImg->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); | |||
ui->statusBar->addPermanentWidget(ConStatusImg); | |||
SalveStatusText=new QLabel; | |||
SalveStatusText->setMinimumWidth(100); | |||
SalveStatusText->setAlignment(Qt::AlignRight | Qt::AlignVCenter); | |||
SalveStatusText->setText(QStringLiteral("从站状态:")); | |||
ui->statusBar->addPermanentWidget(SalveStatusText); | |||
SalveStatusShow=new QLabel; | |||
SalveStatusShow->setMinimumWidth(60); | |||
SalveStatusShow->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); | |||
SalveStatusShow->setText(QStringLiteral("其它")); | |||
ui->statusBar->addPermanentWidget(SalveStatusShow); | |||
} | |||
/****************************InitConnect函数********************************* | |||
Function :主窗口界面涉及的槽函数和信号的连接 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::InitConnect() | |||
{ | |||
connect(&Xcon,SIGNAL(CloseWin()),this,SLOT(Slot_ShowWin())); | |||
connect(&Apar,SIGNAL(CloseWin()),this,SLOT(Slot_ShowWin())); | |||
connect(&Movement,SIGNAL(CloseWin()),this,SLOT(Slot_ShowWin())); | |||
connect(StatuTimer,SIGNAL(timeout()),this,SLOT(Slot_Status())); | |||
connect(Monitor,SIGNAL(timeout()),this,SLOT(Slot_Monitor())); | |||
//开启从站连接状态定时器 | |||
StatuTimer->start(1000); | |||
//开启监视栏定时器 | |||
Monitor->start(500); | |||
//开启时间显示定时器 | |||
TimeShow->start(1000); | |||
//连接定时器和timeout信号 | |||
connect(TimeShow,&QTimer::timeout,[=](){ | |||
ui->statusBar->showMessage(QDateTime::currentDateTime().toString( "yyyy年MM月dd日 hh:mm:ss")); | |||
}); | |||
//多段运动启动与停止绑定 | |||
connect(ui->RunMoreStopBtn,SIGNAL(clicked()),this,SLOT(on_RunStopBtn_clicked())); | |||
connect(ui->RunMoreKeepBtn,SIGNAL(clicked()),this,SLOT(on_RunKeepBtn_clicked())); | |||
} | |||
/****************************Slot_Status函数********************************* | |||
Function :从站状态显示函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::Slot_Status() | |||
{ | |||
//如果从站连接成功,变为绿色,开启按钮;否则是红色,关闭按钮 | |||
if(ConStatus()) | |||
{ | |||
ConStatusImg->setStyleSheet(m_green_SheetStyle); | |||
//基础配置的按钮(3个) | |||
ui->pushButton_2->setEnabled(true); | |||
ui->pushButton_3->setEnabled(true); | |||
ui->pushButton_4->setEnabled(true); | |||
//点动的按钮(6个) | |||
ui->DotKeepRunBtn->setEnabled(true); | |||
ui->DotPositiveBtn->setEnabled(true); | |||
ui->DotReverseBtn->setEnabled(true); | |||
ui->DotSpeedUpdataBtn->setEnabled(true); | |||
ui->DotStepUpdataBtn->setEnabled(true); | |||
ui->DotStopRunBtn->setEnabled(true); | |||
//基础运动的按钮(8个) | |||
ui->RunKeepBtn->setEnabled(true); | |||
ui->RunPlaceUpdataBtn->setEnabled(true); | |||
ui->RunSpeedUpdataBtn->setEnabled(true); | |||
ui->RunStartAbsolutBtn->setEnabled(true); | |||
ui->RunStartPlaceModifyBtn->setEnabled(true); | |||
ui->RunStartRelativeBtn->setEnabled(true); | |||
ui->RunStopBtn->setEnabled(true); | |||
ui->RunTimeUpdataBtn->setEnabled(true); | |||
//多段运动的按钮(5个)+1个多选框 | |||
ui->RunMoreAddRunBtn->setEnabled(true); | |||
ui->RunMoreDataUpdataBtn->setEnabled(true); | |||
ui->RunMoreKeepBtn->setEnabled(true); | |||
ui->RunMoreModelBox->setEnabled(true); | |||
ui->RunMoreStartBtn->setEnabled(true); | |||
ui->RunMoreStopBtn->setEnabled(true); | |||
} | |||
else | |||
{ | |||
ConStatusImg->setStyleSheet(m_red_SheetStyle); | |||
//基础配置的按钮(3个) | |||
ui->pushButton_2->setEnabled(false); | |||
ui->pushButton_3->setEnabled(false); | |||
ui->pushButton_4->setEnabled(false); | |||
//点动的按钮(6个) | |||
ui->DotKeepRunBtn->setEnabled(false); | |||
ui->DotPositiveBtn->setEnabled(false); | |||
ui->DotReverseBtn->setEnabled(false); | |||
ui->DotSpeedUpdataBtn->setEnabled(false); | |||
ui->DotStepUpdataBtn->setEnabled(false); | |||
ui->DotStopRunBtn->setEnabled(false); | |||
//基础运动的按钮(8个) | |||
ui->RunKeepBtn->setEnabled(false); | |||
ui->RunPlaceUpdataBtn->setEnabled(false); | |||
ui->RunSpeedUpdataBtn->setEnabled(false); | |||
ui->RunStartAbsolutBtn->setEnabled(false); | |||
ui->RunStartPlaceModifyBtn->setEnabled(false); | |||
ui->RunStartRelativeBtn->setEnabled(false); | |||
ui->RunStopBtn->setEnabled(false); | |||
ui->RunTimeUpdataBtn->setEnabled(false); | |||
//多段运动的按钮(5个)+1个多选框 | |||
ui->RunMoreAddRunBtn->setEnabled(false); | |||
ui->RunMoreDataUpdataBtn->setEnabled(false); | |||
ui->RunMoreKeepBtn->setEnabled(false); | |||
ui->RunMoreModelBox->setEnabled(false); | |||
ui->RunMoreStartBtn->setEnabled(false); | |||
ui->RunMoreStopBtn->setEnabled(false); | |||
} | |||
//显示对应的从站状态 | |||
switch (SalveStatus()) { | |||
case 1: | |||
{ | |||
SalveStatusShow->setText(QStringLiteral("INIT")); | |||
break; | |||
} | |||
case 2: | |||
{ | |||
SalveStatusShow->setText(QStringLiteral("PreOP")); | |||
break; | |||
} | |||
case 4: | |||
{ | |||
SalveStatusShow->setText(QStringLiteral("SafeOP")); | |||
break; | |||
} | |||
case 8: | |||
{ | |||
SalveStatusShow->setText(QStringLiteral("OP")); | |||
break; | |||
} | |||
default: | |||
SalveStatusShow->setText(QStringLiteral("其它")); | |||
break; | |||
} | |||
} | |||
/****************************Slot_ShowWin函数********************************* | |||
Function :设置对话框为模态窗口 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::Slot_ShowWin() | |||
{ | |||
this->setWindowModality(Qt::ApplicationModal); | |||
} | |||
/****************************InitMonitor函数********************************* | |||
Function :初始化监视窗口的函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::InitMonitor() | |||
{ | |||
//添加表头 | |||
QStringList TableHeadTitle; | |||
int TableHeadTitleLength; | |||
TableHeadTitle.push_back(QStringLiteral("寄存器")); | |||
TableHeadTitle.push_back(QStringLiteral("监控值")); | |||
TableHeadTitle.push_back(QStringLiteral("备注")); | |||
TableHeadTitleLength=TableHeadTitle.length(); | |||
ui->DataMonitorTableWidget->setColumnCount(TableHeadTitleLength); | |||
ui->DataMonitorTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); | |||
for(int i=0;i<TableHeadTitleLength;i++) | |||
{ | |||
TableHeadItem.push_back(new QTableWidgetItem(TableHeadTitle[i])); | |||
ui->DataMonitorTableWidget->setHorizontalHeaderItem(i,TableHeadItem[i]); | |||
} | |||
//添加监控值初始数据 | |||
AddMonitorVal(&MonitorSM2001,"false","SM2001","轴运动标识"); | |||
AddMonitorVal(&MonitorSM2010,"false","SM2010","使能标识"); | |||
AddMonitorVal(&MonitorSM2011,"false","SM2011","正向点动标识"); | |||
AddMonitorVal(&MonitorSM2012,"false","SM2012","反向点动标识"); | |||
AddMonitorVal(&MonitorSD2042,"0","SD2042","点动速度"); | |||
AddMonitorVal(&MonitorSD2040,"0","SD2040","点动步长"); | |||
AddMonitorVal(&MonitorSD2001,"0","SD2001","运行模式"); | |||
AddMonitorVal(&MonitorSD2010,"0","SD2010","当前运行速度"); | |||
AddMonitorVal(&MonitorSD2008,"0","SD2008","当前位置"); | |||
AddMonitorVal(&MonitorSD2030,"0","SD2030","设定位置"); | |||
AddMonitorVal(&MonitorSD2032,"0","SD2032","设定速度"); | |||
AddMonitorVal(&MonitorSD2034,"0","SD2034","设定加速时间"); | |||
AddMonitorVal(&MonitorSD2036,"0","SD2036","设定减速时间"); | |||
} | |||
/****************************AddMonitorVal函数********************************* | |||
Function :添加监视栏数据 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::AddMonitorVal(QTableWidgetItem **Item,QString Value,QString QStrName,QString QStrVal) | |||
{ | |||
int Row=ui->DataMonitorTableWidget->rowCount(); | |||
ui->DataMonitorTableWidget->insertRow(Row); | |||
MonitorLogs.push_back(new QTableWidgetItem(QStrName)); | |||
MonitorLogs.at(MonitorLogs.length()-1)->setTextAlignment(Qt::AlignCenter); | |||
ui->DataMonitorTableWidget->setItem(Row,0,MonitorLogs.at(MonitorLogs.length()-1)); | |||
(*Item)=new QTableWidgetItem(Value); | |||
(*Item)->setTextAlignment(Qt::AlignCenter); | |||
ui->DataMonitorTableWidget->setItem(Row,1,*Item); | |||
MonitorLogs.push_back(new QTableWidgetItem(QStrVal)); | |||
MonitorLogs.at(MonitorLogs.length()-1)->setTextAlignment(Qt::AlignCenter); | |||
ui->DataMonitorTableWidget->setItem(Row,2,MonitorLogs.at(MonitorLogs.length()-1)); | |||
} | |||
/****************************SetMonitorVal函数********************************* | |||
Function :将需要监控的对象加入到监视表中 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::SetMonitorVal(QTableWidgetItem *Item,bool Type,int addr) | |||
{ | |||
if(Type) | |||
{ | |||
Item->setText(QString::number(ReadSDShort(addr))); | |||
}else | |||
{ | |||
if(ReadSMBool(addr)) | |||
{ | |||
Item->setText("true"); | |||
}else | |||
{ | |||
Item->setText("false"); | |||
} | |||
} | |||
} | |||
/****************************Slot_Monitor函数********************************* | |||
Function :信号,当触发该信号时,将需要监视的对象设置到监视表中 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::Slot_Monitor() | |||
{ | |||
SetMonitorVal(MonitorSM2001,false,2001); | |||
SetMonitorVal(MonitorSM2010,false,2010); | |||
SetMonitorVal(MonitorSM2011,false,2011); | |||
SetMonitorVal(MonitorSM2012,false,2012); | |||
SetMonitorVal(MonitorSD2042,true,2042); | |||
SetMonitorVal(MonitorSD2040,true,2040); | |||
SetMonitorVal(MonitorSD2001,true,2001); | |||
SetMonitorVal(MonitorSD2010,true,2010); | |||
SetMonitorVal(MonitorSD2008,true,2008); | |||
SetMonitorVal(MonitorSD2030,true,2030); | |||
SetMonitorVal(MonitorSD2032,true,2032); | |||
SetMonitorVal(MonitorSD2034,true,2034); | |||
SetMonitorVal(MonitorSD2036,true,2036); | |||
} | |||
/****************************通信连接按钮的槽函数函数********************************* | |||
Function :点击通信连接按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_pushButton_clicked() | |||
{ | |||
Xcon.setWindowFlags(Qt::Dialog|Qt::WindowCloseButtonHint); | |||
Xcon.setWindowModality(Qt::ApplicationModal); | |||
Xcon.show(); | |||
} | |||
/****************************C运动相关参数配置的槽函数********************************* | |||
Function :点击C运动参数配置按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_pushButton_2_clicked() | |||
{ | |||
Apar.setWindowFlags(Qt::Dialog|Qt::WindowCloseButtonHint|Qt::WindowMaximizeButtonHint); | |||
Apar.setWindowModality(Qt::ApplicationModal); | |||
Apar.show(); | |||
} | |||
/****************************************************点动模块*****************************************************/ | |||
/****************************开启电机的槽函数********************************* | |||
Function :点击开启电机按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_pushButton_3_clicked() | |||
{ | |||
//关闭 | |||
WriteMBool(5,false); | |||
WriteMBool(10,false); | |||
WriteMBool(15,false); | |||
WriteMBool(20,false); | |||
WriteMBool(25,false); | |||
WriteMBool(30,false); | |||
WriteMBool(35,false); | |||
//使能 | |||
WriteMBool(0,true); | |||
} | |||
/****************************关闭电机的槽函数********************************* | |||
Function :点击关闭电机按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_pushButton_4_clicked() | |||
{ | |||
//关闭 | |||
WriteMBool(5,false); | |||
WriteMBool(10,false); | |||
WriteMBool(15,false); | |||
WriteMBool(20,false); | |||
WriteMBool(25,false); | |||
WriteMBool(30,false); | |||
WriteMBool(35,false); | |||
WriteMBool(0,false); | |||
} | |||
/****************************更新步长的槽函数********************************* | |||
Function :点击更新步长按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_DotStepUpdataBtn_clicked() | |||
{ | |||
short value=ui->DotStepLedit->text().toShort(); | |||
WriteDShort(0,value); | |||
} | |||
/****************************更新点动速度的槽函数********************************* | |||
Function :点击更新点动速度按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_DotSpeedUpdataBtn_clicked() | |||
{ | |||
short value=ui->DotSpeedLedit->text().toShort(); | |||
WriteDShort(50,value); | |||
} | |||
/****************************正向点动的槽函数********************************* | |||
Function :点击正向点动按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_DotPositiveBtn_clicked() | |||
{ | |||
WriteMBool(10,false); | |||
WriteMBool(5,true); | |||
} | |||
/****************************反向点动的槽函数********************************* | |||
Function :点击反向点动按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_DotReverseBtn_clicked() | |||
{ | |||
WriteMBool(5,false); | |||
WriteMBool(10,true); | |||
} | |||
/****************************停止运动的槽函数********************************* | |||
Function :点击停止运动按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_DotStopRunBtn_clicked() | |||
{ | |||
WriteMBool(15,true); | |||
} | |||
/****************************继续运动的槽函数********************************* | |||
Function :点击继续运动按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_DotKeepRunBtn_clicked() | |||
{ | |||
WriteMBool(15,false); | |||
} | |||
/****************************************************基础运动模块*****************************************************/ | |||
/****************************更新位置的槽函数********************************* | |||
Function :点击更新位置按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_RunPlaceUpdataBtn_clicked() | |||
{ | |||
int value=ui->RunPlaceLedit->text().toInt(); | |||
WriteDInt(100,value); | |||
} | |||
/****************************更新速度的槽函数********************************* | |||
Function :点击更新速度按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_RunSpeedUpdataBtn_clicked() | |||
{ | |||
int value=ui->RunSpeedLedit->text().toInt(); | |||
WriteDInt(150,value); | |||
} | |||
/****************************更新时间的槽函数********************************* | |||
Function :点击更新时间按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_RunTimeUpdataBtn_clicked() | |||
{ | |||
int value=ui->RunTimeLedit->text().toInt(); | |||
WriteDInt(200,value); | |||
} | |||
/****************************修改位置的槽函数********************************* | |||
Function :点击修改位置按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_RunStartPlaceModifyBtn_clicked() | |||
{ | |||
int value=ui->RunStartPlaceLedit->text().toInt(); | |||
WriteDInt(450,value); | |||
WriteMBool(40,true); | |||
WriteMBool(40,false); | |||
} | |||
/****************************绝对运动的槽函数********************************* | |||
Function :点击绝对运动按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_RunStartAbsolutBtn_clicked() | |||
{ | |||
WriteMBool(30,true); | |||
WriteMBool(30,false); | |||
} | |||
/****************************相对运动的槽函数********************************* | |||
Function :点击相对运动按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_RunStartRelativeBtn_clicked() | |||
{ | |||
WriteMBool(25,true); | |||
WriteMBool(25,false); | |||
} | |||
/****************************停止运动的槽函数********************************* | |||
Function :点击停止运动按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_RunStopBtn_clicked() | |||
{ | |||
WriteMBool(20,false); | |||
WriteMBool(15,true); | |||
} | |||
/****************************继续运动的槽函数********************************* | |||
Function :点击继续运动按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_RunKeepBtn_clicked() | |||
{ | |||
WriteMBool(15,false); | |||
WriteMBool(20,true); | |||
} | |||
/****************************************************多段运动模块*****************************************************/ | |||
/****************************添加运动的槽函数********************************* | |||
Function :点击添加运动按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_RunMoreAddRunBtn_clicked() | |||
{ | |||
Movement.setWindowFlags(Qt::Dialog|Qt::WindowCloseButtonHint|Qt::WindowMaximizeButtonHint); | |||
Movement.setWindowModality(Qt::ApplicationModal); | |||
Movement.show(); | |||
} | |||
/****************************更新数据的槽函数********************************* | |||
Function :点击更新数据按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_RunMoreDataUpdataBtn_clicked() | |||
{ | |||
int AddValue=ui->RunMoreAddSpeedTimeLedit->text().toInt(); | |||
int SubValue=ui->RunMoreSubSpeedTimeLedit->text().toInt(); | |||
int RunModel=ui->RunMoreModelBox->currentIndex(); | |||
WriteDInt(400,RunModel); | |||
WriteDInt(404,AddValue); | |||
WriteDInt(406,SubValue); | |||
} | |||
/****************************启动运动的槽函数********************************* | |||
Function :点击启动运动按钮,会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::on_RunMoreStartBtn_clicked() | |||
{ | |||
WriteMBool(35,true); | |||
WriteMBool(35,false); | |||
} | |||
/****************************closeEvent函数********************************* | |||
Function :窗口关闭事件函数 | |||
Output : | |||
*********************************************************************/ | |||
void MotorControll::closeEvent(QCloseEvent *event) | |||
{ | |||
QMessageBox::StandardButton Value=QMessageBox::question(this,QStringLiteral("退出提示"),QStringLiteral("确认退出程序?")); | |||
if(Value==QMessageBox::Yes) | |||
{ | |||
emit CloseWin(); | |||
event->accept(); | |||
}else | |||
{ | |||
event->ignore(); | |||
} | |||
} |
@@ -0,0 +1,161 @@ | |||
/******************************motorcontroll.h文件说明********************************** | |||
* Descript :头文件,包含主窗口的头文件引用,以及宏定义 | |||
* Author :caitiancheng | |||
* Date :2021_12_19 | |||
*******************************************************************************/ | |||
#ifndef MOTORCONTROLL_H | |||
#define MOTORCONTROLL_H | |||
/***********************************头文件****************************************/ | |||
#include <QMainWindow> | |||
#include <Base.h> | |||
#include "XnetConnect.h" | |||
#include "Addpar.h" | |||
#include "moretypemovement.h" | |||
#include <QTimer> | |||
#include <QTableWidgetItem> | |||
#include <QMessageBox> | |||
/***********************************类的声明和继承****************************************/ | |||
namespace Ui { | |||
class MotorControll; | |||
} | |||
class MotorControll : public QMainWindow,public Base | |||
{ | |||
Q_OBJECT | |||
public: | |||
explicit MotorControll(QWidget *parent = 0); | |||
~MotorControll(); | |||
signals: | |||
void CloseWin(); | |||
protected: | |||
void closeEvent(QCloseEvent *event=NULL); | |||
private slots: | |||
void Slot_Status(); | |||
void Slot_ShowWin(); | |||
void Slot_Monitor(); | |||
void on_pushButton_clicked(); | |||
void on_pushButton_2_clicked(); | |||
void on_pushButton_3_clicked(); | |||
void on_pushButton_4_clicked(); | |||
void on_DotStepUpdataBtn_clicked(); | |||
void on_DotSpeedUpdataBtn_clicked(); | |||
void on_DotPositiveBtn_clicked(); | |||
void on_DotReverseBtn_clicked(); | |||
void on_DotStopRunBtn_clicked(); | |||
void on_DotKeepRunBtn_clicked(); | |||
void on_RunPlaceUpdataBtn_clicked(); | |||
void on_RunSpeedUpdataBtn_clicked(); | |||
void on_RunTimeUpdataBtn_clicked(); | |||
void on_RunStartPlaceModifyBtn_clicked(); | |||
void on_RunStartAbsolutBtn_clicked(); | |||
void on_RunStartRelativeBtn_clicked(); | |||
void on_RunStopBtn_clicked(); | |||
void on_RunKeepBtn_clicked(); | |||
void on_RunMoreAddRunBtn_clicked(); | |||
void on_RunMoreDataUpdataBtn_clicked(); | |||
void on_RunMoreStartBtn_clicked(); | |||
private: | |||
Ui::MotorControll *ui; | |||
XnetConnect Xcon; | |||
AddPar Apar; | |||
MoreTypeMovement Movement; | |||
//定义时间显示定时器 | |||
QTimer *TimeShow; | |||
//定义监视栏定时器 | |||
QTimer *Monitor; | |||
//监视栏初始化函数 | |||
void InitMonitor(); | |||
//控件连接的信号和槽函数 | |||
void InitConnect(); | |||
//状态栏界面设置初始化函数 | |||
void InitBarStatus(); | |||
//声明表格控件对象 | |||
QList<QTableWidgetItem *> TableHeadItem; | |||
//状态栏 | |||
//定义连接状态定时器 | |||
QTimer *StatuTimer; | |||
const QString m_red_SheetStyle = "min-width: 16px; min-height: 16px;max-width:16px; max-height: 16px;border-radius: 8px; border:1px solid black;background:red"; | |||
const QString m_green_SheetStyle = "min-width: 16px; min-height: 16px;max-width:16px; max-height: 16px;border-radius: 8px; border:1px solid black;background:green"; | |||
QLabel *ConStatusText; | |||
QLabel *ConStatusImg; | |||
QLabel *SalveStatusText; | |||
QLabel *SalveStatusShow; | |||
//监控的值对象 | |||
//用于记录一些不需要操作的数据,但需要释放 | |||
QList<QTableWidgetItem *> MonitorLogs; | |||
//运动标识 | |||
QTableWidgetItem *MonitorSM2001; | |||
//使能标识 | |||
QTableWidgetItem *MonitorSM2010; | |||
//正向点动标识 | |||
QTableWidgetItem *MonitorSM2011; | |||
//方向点动标识 | |||
QTableWidgetItem *MonitorSM2012; | |||
//点动速度 | |||
QTableWidgetItem *MonitorSD2042; | |||
//点动步长 | |||
QTableWidgetItem *MonitorSD2040; | |||
//运行模式 | |||
QTableWidgetItem *MonitorSD2001; | |||
//监控速度 | |||
QTableWidgetItem *MonitorSD2010; | |||
//抽位置 | |||
QTableWidgetItem *MonitorSD2008; | |||
//位置设定 | |||
QTableWidgetItem *MonitorSD2030; | |||
//速度设定 | |||
QTableWidgetItem *MonitorSD2032; | |||
//加速时间设定 | |||
QTableWidgetItem *MonitorSD2034; | |||
//减速时间设定 | |||
QTableWidgetItem *MonitorSD2036; | |||
//添加监控值函数 | |||
void AddMonitorVal(QTableWidgetItem **Item,QString Value,QString QStrName,QString QStrVal); | |||
//加入监控槽 | |||
void SetMonitorVal(QTableWidgetItem *Item,bool Type,int addr); | |||
}; | |||
#endif // MOTORCONTROLL_H |
@@ -0,0 +1,789 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<ui version="4.0"> | |||
<class>MotorControll</class> | |||
<widget class="QMainWindow" name="MotorControll"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>0</x> | |||
<y>0</y> | |||
<width>965</width> | |||
<height>867</height> | |||
</rect> | |||
</property> | |||
<property name="windowTitle"> | |||
<string>MotorControll</string> | |||
</property> | |||
<widget class="QWidget" name="centralWidget"> | |||
<widget class="QGroupBox" name="groupBox"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>10</x> | |||
<y>10</y> | |||
<width>361</width> | |||
<height>161</height> | |||
</rect> | |||
</property> | |||
<property name="title"> | |||
<string>基础配置</string> | |||
</property> | |||
<widget class="QPushButton" name="pushButton"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>10</x> | |||
<y>30</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>通信连接</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="pushButton_2"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>230</x> | |||
<y>30</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>C运动配置</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="pushButton_3"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>10</x> | |||
<y>110</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>开启电机</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="pushButton_4"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>230</x> | |||
<y>110</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>关闭电机</string> | |||
</property> | |||
</widget> | |||
</widget> | |||
<widget class="QGroupBox" name="groupBox_2"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>10</x> | |||
<y>175</y> | |||
<width>421</width> | |||
<height>261</height> | |||
</rect> | |||
</property> | |||
<property name="title"> | |||
<string>点动</string> | |||
</property> | |||
<widget class="QPushButton" name="DotPositiveBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>10</x> | |||
<y>140</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>正向点动</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="DotStepUpdataBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>300</x> | |||
<y>20</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>更新步长</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="DotSpeedUpdataBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>300</x> | |||
<y>80</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>更新速度</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="DotReverseBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>160</x> | |||
<y>140</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>反向点动</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="DotKeepRunBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>160</x> | |||
<y>200</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>继续运动</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="DotStopRunBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>10</x> | |||
<y>200</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>停止运动</string> | |||
</property> | |||
</widget> | |||
<widget class="QLabel" name="label"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>10</x> | |||
<y>30</y> | |||
<width>72</width> | |||
<height>15</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>点动步长</string> | |||
</property> | |||
</widget> | |||
<widget class="QLabel" name="label_2"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>10</x> | |||
<y>90</y> | |||
<width>70</width> | |||
<height>15</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>点动速度</string> | |||
</property> | |||
</widget> | |||
<widget class="QLineEdit" name="DotStepLedit"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>90</x> | |||
<y>30</y> | |||
<width>131</width> | |||
<height>21</height> | |||
</rect> | |||
</property> | |||
</widget> | |||
<widget class="QLineEdit" name="DotSpeedLedit"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>90</x> | |||
<y>90</y> | |||
<width>131</width> | |||
<height>21</height> | |||
</rect> | |||
</property> | |||
</widget> | |||
<widget class="QLabel" name="label_3"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>240</x> | |||
<y>30</y> | |||
<width>31</width> | |||
<height>16</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>脉冲</string> | |||
</property> | |||
</widget> | |||
<widget class="QLabel" name="label_4"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>240</x> | |||
<y>90</y> | |||
<width>72</width> | |||
<height>15</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>脉冲/秒</string> | |||
</property> | |||
</widget> | |||
<zorder>DotPositiveBtn</zorder> | |||
<zorder>DotStepUpdataBtn</zorder> | |||
<zorder>DotSpeedUpdataBtn</zorder> | |||
<zorder>DotReverseBtn</zorder> | |||
<zorder>DotKeepRunBtn</zorder> | |||
<zorder>DotStopRunBtn</zorder> | |||
<zorder>label</zorder> | |||
<zorder>label_2</zorder> | |||
<zorder>DotSpeedLedit</zorder> | |||
<zorder>label_3</zorder> | |||
<zorder>label_4</zorder> | |||
<zorder>DotStepLedit</zorder> | |||
</widget> | |||
<widget class="QGroupBox" name="groupBox_3"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>480</x> | |||
<y>10</y> | |||
<width>481</width> | |||
<height>434</height> | |||
</rect> | |||
</property> | |||
<property name="sizePolicy"> | |||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> | |||
<horstretch>0</horstretch> | |||
<verstretch>0</verstretch> | |||
</sizepolicy> | |||
</property> | |||
<property name="minimumSize"> | |||
<size> | |||
<width>300</width> | |||
<height>0</height> | |||
</size> | |||
</property> | |||
<property name="maximumSize"> | |||
<size> | |||
<width>1000</width> | |||
<height>16777215</height> | |||
</size> | |||
</property> | |||
<property name="title"> | |||
<string>监控</string> | |||
</property> | |||
<layout class="QGridLayout" name="gridLayout"> | |||
<item row="0" column="0"> | |||
<widget class="QTableWidget" name="DataMonitorTableWidget"> | |||
<property name="textElideMode"> | |||
<enum>Qt::ElideMiddle</enum> | |||
</property> | |||
<attribute name="horizontalHeaderCascadingSectionResizes"> | |||
<bool>false</bool> | |||
</attribute> | |||
<attribute name="horizontalHeaderStretchLastSection"> | |||
<bool>true</bool> | |||
</attribute> | |||
</widget> | |||
</item> | |||
</layout> | |||
</widget> | |||
<widget class="QGroupBox" name="groupBox_4"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>10</x> | |||
<y>480</y> | |||
<width>441</width> | |||
<height>341</height> | |||
</rect> | |||
</property> | |||
<property name="title"> | |||
<string>基础运动</string> | |||
</property> | |||
<widget class="QLabel" name="label_6"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>10</x> | |||
<y>80</y> | |||
<width>60</width> | |||
<height>28</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>运行速度</string> | |||
</property> | |||
</widget> | |||
<widget class="QLabel" name="label_5"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>10</x> | |||
<y>30</y> | |||
<width>60</width> | |||
<height>28</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>目标位置</string> | |||
</property> | |||
</widget> | |||
<widget class="QLabel" name="label_7"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>10</x> | |||
<y>130</y> | |||
<width>60</width> | |||
<height>28</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>加速时间</string> | |||
</property> | |||
</widget> | |||
<widget class="QLabel" name="label_8"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>10</x> | |||
<y>180</y> | |||
<width>60</width> | |||
<height>28</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>位置修改</string> | |||
</property> | |||
</widget> | |||
<widget class="QLineEdit" name="RunSpeedLedit"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>90</x> | |||
<y>80</y> | |||
<width>140</width> | |||
<height>25</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>0</string> | |||
</property> | |||
<property name="alignment"> | |||
<set>Qt::AlignCenter</set> | |||
</property> | |||
</widget> | |||
<widget class="QLineEdit" name="RunPlaceLedit"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>90</x> | |||
<y>30</y> | |||
<width>140</width> | |||
<height>25</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>10000</string> | |||
</property> | |||
<property name="alignment"> | |||
<set>Qt::AlignCenter</set> | |||
</property> | |||
</widget> | |||
<widget class="QLineEdit" name="RunTimeLedit"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>90</x> | |||
<y>130</y> | |||
<width>140</width> | |||
<height>25</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>0</string> | |||
</property> | |||
<property name="alignment"> | |||
<set>Qt::AlignCenter</set> | |||
</property> | |||
</widget> | |||
<widget class="QLineEdit" name="RunStartPlaceLedit"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>90</x> | |||
<y>180</y> | |||
<width>140</width> | |||
<height>25</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>0</string> | |||
</property> | |||
<property name="alignment"> | |||
<set>Qt::AlignCenter</set> | |||
</property> | |||
</widget> | |||
<widget class="QLabel" name="label_9"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>250</x> | |||
<y>30</y> | |||
<width>31</width> | |||
<height>16</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>脉冲</string> | |||
</property> | |||
</widget> | |||
<widget class="QLabel" name="label_10"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>250</x> | |||
<y>80</y> | |||
<width>72</width> | |||
<height>15</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>脉冲/秒</string> | |||
</property> | |||
</widget> | |||
<widget class="QLabel" name="label_11"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>250</x> | |||
<y>130</y> | |||
<width>72</width> | |||
<height>15</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>毫秒</string> | |||
</property> | |||
</widget> | |||
<widget class="QLabel" name="label_12"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>250</x> | |||
<y>180</y> | |||
<width>31</width> | |||
<height>16</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>脉冲</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="RunPlaceUpdataBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>310</x> | |||
<y>15</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>更新位置</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="RunSpeedUpdataBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>310</x> | |||
<y>70</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>更新速度</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="RunTimeUpdataBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>310</x> | |||
<y>120</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>更新时间</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="RunStartPlaceModifyBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>310</x> | |||
<y>170</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>修改位置</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="RunStartAbsolutBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>10</x> | |||
<y>230</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>绝对运动</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="RunStartRelativeBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>10</x> | |||
<y>280</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>相对运动</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="RunStopBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>210</x> | |||
<y>230</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>停止运动</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="RunKeepBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>210</x> | |||
<y>280</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>继续运动</string> | |||
</property> | |||
</widget> | |||
</widget> | |||
<widget class="QGroupBox" name="groupBox_5"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>480</x> | |||
<y>480</y> | |||
<width>441</width> | |||
<height>341</height> | |||
</rect> | |||
</property> | |||
<property name="title"> | |||
<string>多段运动</string> | |||
</property> | |||
<widget class="QLabel" name="label_13"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>20</x> | |||
<y>34</y> | |||
<width>60</width> | |||
<height>28</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>运动模式</string> | |||
</property> | |||
</widget> | |||
<widget class="QComboBox" name="RunMoreModelBox"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>100</x> | |||
<y>34</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<item> | |||
<property name="text"> | |||
<string>相对运动</string> | |||
</property> | |||
</item> | |||
<item> | |||
<property name="text"> | |||
<string>绝对运动</string> | |||
</property> | |||
</item> | |||
</widget> | |||
<widget class="QLabel" name="label_14"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>20</x> | |||
<y>100</y> | |||
<width>72</width> | |||
<height>15</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>加速时间</string> | |||
</property> | |||
</widget> | |||
<widget class="QLineEdit" name="RunMoreAddSpeedTimeLedit"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>100</x> | |||
<y>100</y> | |||
<width>111</width> | |||
<height>21</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>1000</string> | |||
</property> | |||
<property name="alignment"> | |||
<set>Qt::AlignCenter</set> | |||
</property> | |||
</widget> | |||
<widget class="QLabel" name="label_15"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>220</x> | |||
<y>100</y> | |||
<width>31</width> | |||
<height>16</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>毫秒</string> | |||
</property> | |||
</widget> | |||
<widget class="QLabel" name="label_16"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>20</x> | |||
<y>160</y> | |||
<width>72</width> | |||
<height>15</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>减速时间</string> | |||
</property> | |||
</widget> | |||
<widget class="QLineEdit" name="RunMoreSubSpeedTimeLedit"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>100</x> | |||
<y>160</y> | |||
<width>111</width> | |||
<height>21</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>1000</string> | |||
</property> | |||
<property name="alignment"> | |||
<set>Qt::AlignCenter</set> | |||
</property> | |||
</widget> | |||
<widget class="QLabel" name="label_17"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>220</x> | |||
<y>160</y> | |||
<width>31</width> | |||
<height>15</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>毫秒</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="RunMoreDataUpdataBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>290</x> | |||
<y>110</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>更新数据</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="RunMoreAddRunBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>290</x> | |||
<y>34</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>添加运动</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="RunMoreStartBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>20</x> | |||
<y>250</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>启动运动</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="RunMoreStopBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>160</x> | |||
<y>250</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>停止运动</string> | |||
</property> | |||
</widget> | |||
<widget class="QPushButton" name="RunMoreKeepBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>290</x> | |||
<y>250</y> | |||
<width>111</width> | |||
<height>41</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>继续运动</string> | |||
</property> | |||
</widget> | |||
</widget> | |||
</widget> | |||
<widget class="QStatusBar" name="statusBar"/> | |||
</widget> | |||
<layoutdefault spacing="6" margin="11"/> | |||
<resources/> | |||
<connections/> | |||
</ui> |
@@ -0,0 +1,90 @@ | |||
#ifndef X_NET_H | |||
#define X_NET_H | |||
//#include "x_net_global.h" | |||
#include <Windows.h> | |||
#include <string> | |||
#include <iostream> | |||
using namespace std; | |||
#include "XNetClient.h" | |||
#define XNet_X 1 | |||
#define XNet_Y 2 | |||
#define XNet_M 3 | |||
#define XNet_S 4 | |||
#define XNet_T 5 | |||
#define XNet_C 6 | |||
#define XNet_ET 7 | |||
#define XNet_HM 8 | |||
#define XNet_HS 9 | |||
#define XNet_HT 10 | |||
#define XNet_HC 11 | |||
#define XNet_HSC 12 | |||
#define XNet_SM 13 | |||
#define XNet_SSM 14 | |||
#define XNet_TG 15 | |||
#define XNet_HTG 16 | |||
#define XNet_PF 17 | |||
#define XNet_SEM 18 | |||
#define XNet_STG 19 //add 2016.4.8 | |||
#define XNet_HSTG 20 | |||
#define XNet_D 128 | |||
#define XNet_TD 129 | |||
#define XNet_CD 130 | |||
#define XNet_SD 131 | |||
#define XNet_ETD 133 | |||
#define XNet_ID 134 | |||
#define XNet_QD 135 | |||
#define XNet_HD 136 | |||
#define XNet_HTD 137 | |||
#define XNet_HCD 138 | |||
#define XNet_HSCD 139 | |||
#define XNet_HSD 140 | |||
#define XNet_FD 141 | |||
#define XNet_SFD 142 | |||
#define XNet_SSFD 143 | |||
#define XNet_SSD 144 | |||
#define XNet_FS 145 | |||
#define FLAG 200 | |||
#define LW 201 | |||
#define LB 202 | |||
#define BARCODE "BARCODE" | |||
//为了和将来用到的程序中公用一个头文件,创建dll时用到的是__declspec(dllexport),而使用dll时用到__declspec(dllimport),完全可以各自写一下 | |||
#define X_NETSHARED_EXPORT __declspec(dllexport) | |||
#ifdef X_NETSHARED_EXPORT | |||
#else | |||
#define X_NETSHARED_EXPORT __declspec(dllimport) | |||
#endif | |||
//static XINJE::XNetClient device; | |||
extern "C" X_NETSHARED_EXPORT void SetXNetClient(char *); | |||
extern "C" X_NETSHARED_EXPORT void CloseXNetClient(); | |||
extern "C" X_NETSHARED_EXPORT void Write_Short(unsigned char regType, int start, int count,short value); | |||
extern "C" X_NETSHARED_EXPORT void Write_Int(unsigned char regType, int start, int count, int value); | |||
extern "C" X_NETSHARED_EXPORT void Write_Float(unsigned char regType, int start, int count, float value); | |||
extern "C" X_NETSHARED_EXPORT void Write_Double(unsigned char regType, int start, int count, double value); | |||
extern "C" X_NETSHARED_EXPORT void Write_Bool(unsigned char regType, int start, int count, bool value); | |||
extern "C" X_NETSHARED_EXPORT void Read_Short(unsigned char regType, int start, int count, short* value); | |||
extern "C" X_NETSHARED_EXPORT void Read_Int(unsigned char regType, int start, int count, int* value); | |||
extern "C" X_NETSHARED_EXPORT void Read_Float(unsigned char regType, int start, int count, float* value); | |||
extern "C" X_NETSHARED_EXPORT void Read_Double(unsigned char regType, int start, int count, double* value); | |||
extern "C" X_NETSHARED_EXPORT void Read_Bool(unsigned char regType, int start, int count,bool* value); | |||
#endif // X_NET_H |
@@ -0,0 +1,132 @@ | |||
#pragma once | |||
namespace XINJE | |||
{ | |||
//类型定义 | |||
typedef unsigned char Byte; | |||
typedef unsigned short UInt16; | |||
//XNet服务端口 | |||
#define ServicePort 2323 | |||
#define ServiceIp "127.0.0.1" | |||
//操作结果(仅告知操作是否成功) | |||
#define XNetCommResult int | |||
#define XNetCommResult_Err -1 | |||
#define XNetCommResult_Success 0 | |||
//XNet设备类型 | |||
typedef enum | |||
{ | |||
PLC_XD = 0, | |||
PLC_XE, | |||
TouchWin, | |||
WBox, | |||
_4GBox, | |||
COBox, | |||
ABox | |||
}XNetDevice; | |||
//线圈类型 | |||
typedef enum | |||
{ | |||
XNet_X = 1, | |||
XNet_Y = 2, | |||
XNet_M = 3, | |||
XNet_S = 4, | |||
XNet_T = 5, | |||
XNet_C = 6, | |||
XNet_ET = 7, | |||
XNet_HM = 8, | |||
XNet_HS = 9, | |||
XNet_HT = 10, | |||
XNet_HC = 11, | |||
XNet_HSC = 12, | |||
XNet_SM = 13, | |||
XNet_SSM = 14, | |||
XNet_TG = 15, | |||
XNet_HTG = 16, | |||
XNet_PF = 17, | |||
XNet_SEM = 18, | |||
XNet_STG = 19,//add 2016.4.8 | |||
XNet_HSTG = 20, | |||
}CoilType; | |||
//寄存器类型 | |||
typedef enum | |||
{ | |||
XNet_D = 128, | |||
XNet_TD = 129, | |||
XNet_CD = 130, | |||
XNet_SD = 131, | |||
XNet_ETD = 133, | |||
XNet_ID = 134, | |||
XNet_QD = 135, | |||
XNet_HD = 136, | |||
XNet_HTD = 137, | |||
XNet_HCD = 138, | |||
XNet_HSCD = 139, | |||
XNet_HSD = 140, | |||
XNet_FD = 141, | |||
XNet_SFD = 142, | |||
XNet_SSFD = 143, | |||
XNet_SSD = 144, | |||
XNet_FS = 145, | |||
}RegType; | |||
//通信对象 | |||
//每一个和每一个设备的连接都建议创建一个此对象,以避免不必要的线程同步 | |||
class XNetClient | |||
{ | |||
private: | |||
int Sock; | |||
unsigned short Net; | |||
unsigned short Station; | |||
unsigned char Com; | |||
Byte Type; | |||
Byte Serial; | |||
Byte Model; | |||
void LibXNetRegsToBuf(short* _regs, unsigned char* _buf, int _num); | |||
void LibXNetBufToRegs(unsigned char* _buf, unsigned short* _regs, int _num); | |||
void LibXNetCoilsToBuf(short* _coils, unsigned char* _buf, int _num); | |||
void LibXNetBufToCoils(char* _buf, short* _coils, Byte _startBit, int _num); | |||
unsigned short Byte2Word(Byte high, Byte low); | |||
public: | |||
//初始化WindowsSocket | |||
// XNetClient(char *ttyNo); | |||
static XNetCommResult WinSockInit(); | |||
//启动XNet服务 | |||
static XNetCommResult StartXNetWindows(); | |||
static XNetCommResult CloseXNetWindows(); | |||
//和XNet服务建立连接 | |||
XNetCommResult XNetCommunication(); | |||
//打开串口(网口也需配置一次,网口_com填129) | |||
XNetCommResult SetComPort(Byte _com); | |||
//关闭串口 | |||
XNetCommResult ReleaseComPort(Byte _com); | |||
//直接指定设备地址 | |||
void AdderLink(const char* _ipStr); | |||
void AdderLink(UInt16 _net, UInt16 _station); | |||
//对指定端口或网口查找设备,使本对象自动获取到设备地址 | |||
XNetCommResult FindDevice(Byte _comPort, Byte _type, Byte _serial, Byte _model); | |||
XNetCommResult FindDevice(Byte _comPort, XNetDevice _dev); | |||
XNetCommResult FindDevice(Byte _comPort, const char* _id); | |||
//读写寄存器(用户提供一个short数组缓存,用于传入或获取XNet16位寄存器的值) | |||
XNetCommResult WriteRegs(Byte _regType, int _offSet, int _num, short* _writeRegs); | |||
XNetCommResult ReadRegs(Byte _regType, int _offSet, int _num, short* _readRegs); | |||
//读写线圈(用户提供一个short数组缓存,用于传入或获取XNet线圈状态,0为off,1为on) | |||
XNetCommResult WriteCoils(Byte _coilType, int _offSet, int _num, short* _writeCoils); | |||
XNetCommResult ReadCoils(Byte _coilType, int _offSet, int _num, short* _readCoil); | |||
// ~XNetClient(); | |||
}; | |||
} | |||
@@ -0,0 +1,78 @@ | |||
/******************************xnetconnect.cpp文件说明********************************** | |||
* Descript :源文件,包含通信配置窗口的函数实现 | |||
* Author :caitiancheng | |||
* Date :2021_12_19 | |||
*******************************************************************************/ | |||
/***********************************头文件****************************************/ | |||
#include "xnetconnect.h" | |||
#include "ui_xnetconnect.h" | |||
#include "Base.h" | |||
#include <QCloseEvent> | |||
/***********************************类的声明和继承****************************************/ | |||
XnetConnect::XnetConnect(QWidget *parent) : | |||
QWidget(parent), | |||
ui(new Ui::XnetConnect) | |||
{ | |||
ui->setupUi(this); | |||
//禁止修改窗体大小 | |||
setFixedSize(this->width(), this->height()); | |||
ServiceFlag=false; | |||
//设置窗口标题 | |||
setWindowTitle("通信连接"); | |||
} | |||
/****************************closeEvent函数********************************* | |||
Function :窗口关闭事件函数 | |||
Output : | |||
*********************************************************************/ | |||
void XnetConnect::closeEvent(QCloseEvent *event) | |||
{ | |||
emit CloseWin(); | |||
event->accept(); | |||
} | |||
/****************************启动服务槽函数函数********************************* | |||
Function :点击启动服务会触发该槽函数 | |||
Output : | |||
*********************************************************************/ | |||
void XnetConnect::on_CtrlServiceBtn_clicked() | |||
{ | |||
Base TempBase; | |||
if(!ServiceFlag) | |||
{ | |||
QString NeetSetIp=ui->NeedIPEdit->text(); | |||
SetXNetClient(NeetSetIp.toLatin1().data()); | |||
if(TempBase.ConStatus()) | |||
{ | |||
ServiceFlag=true; | |||
ui->CtrlServiceBtn->setText(QStringLiteral("关闭服务")); | |||
QMessageBox::information(this,QStringLiteral("启动提示"),QStringLiteral("通信成功")); | |||
}else | |||
{ | |||
QMessageBox::information(this,QStringLiteral("启动提示"),QStringLiteral("通信失败")); | |||
} | |||
}else | |||
{ | |||
CloseXNetClient(); | |||
ServiceFlag=false; | |||
ui->CtrlServiceBtn->setText(QStringLiteral("开启服务")); | |||
QMessageBox::information(this,QStringLiteral("关闭提示"),QStringLiteral("关闭成功")); | |||
} | |||
} | |||
/******************************************************析构函数*****************************************************/ | |||
XnetConnect::~XnetConnect() | |||
{ | |||
delete ui; | |||
} | |||
@@ -0,0 +1,44 @@ | |||
/******************************xnetconnect.h文件说明********************************** | |||
* Descript :头文件,包含通信配置窗口的头文件引用,以及宏定义 | |||
* Author :caitiancheng | |||
* Date :2021_12_19 | |||
*******************************************************************************/ | |||
#ifndef XNETCONNECT_H | |||
#define XNETCONNECT_H | |||
/***********************************头文件****************************************/ | |||
#include <QWidget> | |||
#include <QMessageBox> | |||
/***********************************类的声明和继承****************************************/ | |||
namespace Ui { | |||
class XnetConnect; | |||
} | |||
class XnetConnect : public QWidget | |||
{ | |||
Q_OBJECT | |||
public: | |||
explicit XnetConnect(QWidget *parent = 0); | |||
~XnetConnect(); | |||
signals: | |||
void CloseWin(); | |||
protected: | |||
void closeEvent(QCloseEvent *event=NULL); | |||
private slots: | |||
void on_CtrlServiceBtn_clicked(); | |||
private: | |||
Ui::XnetConnect *ui; | |||
bool ServiceFlag; | |||
}; | |||
#endif // XNETCONNECT_H |
@@ -0,0 +1,66 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<ui version="4.0"> | |||
<class>XnetConnect</class> | |||
<widget class="QWidget" name="XnetConnect"> | |||
<property name="enabled"> | |||
<bool>true</bool> | |||
</property> | |||
<property name="geometry"> | |||
<rect> | |||
<x>0</x> | |||
<y>0</y> | |||
<width>371</width> | |||
<height>81</height> | |||
</rect> | |||
</property> | |||
<property name="windowTitle"> | |||
<string>Form</string> | |||
</property> | |||
<widget class="QPushButton" name="CtrlServiceBtn"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>260</x> | |||
<y>30</y> | |||
<width>75</width> | |||
<height>23</height> | |||
</rect> | |||
</property> | |||
<property name="text"> | |||
<string>启动服务</string> | |||
</property> | |||
</widget> | |||
<widget class="QLineEdit" name="NeedIPEdit"> | |||
<property name="geometry"> | |||
<rect> | |||
<x>20</x> | |||
<y>30</y> | |||
<width>181</width> | |||
<height>20</height> | |||
</rect> | |||
</property> | |||
<property name="sizePolicy"> | |||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> | |||
<horstretch>0</horstretch> | |||
<verstretch>0</verstretch> | |||
</sizepolicy> | |||
</property> | |||
<property name="inputMask"> | |||
<string/> | |||
</property> | |||
<property name="text"> | |||
<string>192.168.6.6</string> | |||
</property> | |||
<property name="alignment"> | |||
<set>Qt::AlignCenter</set> | |||
</property> | |||
<property name="placeholderText"> | |||
<string>请输入PLC的IP!</string> | |||
</property> | |||
<property name="clearButtonEnabled"> | |||
<bool>false</bool> | |||
</property> | |||
</widget> | |||
</widget> | |||
<resources/> | |||
<connections/> | |||
</ui> |