• 大小: 123KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: 其他
  • 标签: PLC  Qt  

资源简介

Qt基于snap7第三方库西门子PLC通信示例,附件中包括snap7.dll、snap7.lib、Qt示例源码和配置文档

资源截图

代码片段和文件信息

#include “motioncontroll.h“
#include “ui_motioncontroll.h“
#include 
#include 

#include “snap7.h“

MotionControll::MotionControll(QWidget *parent) :
    QWidget(parent)
    ui(new Ui::MotionControll)
{
    ui->setupUi(this);
    ptrPLC = new TS7Client();

    ui->lineEdit_Distance->setDisabled(true);
    ui->btn_Stop->setstyleSheet(“background:rgb(20010070)“);
    m_bStatus = false;

    connect(&m_timer SIGNAL(timeout()) this SLOT(readHorisonVal()));
}

MotionControll::~MotionControll()
{
    delete ui;
    m_timer.stop();
}

void MotionControll::on_btn_Connect_clicked()
{
    if(!ptrPLC->Connected())
    {
        int res = ptrPLC->ConnectTo(“192.168.1.20“ 0 1);
        if(!res)
        {
            ui->btn_Connect->setDisabled(true);
            m_timer.start(500);
        }
    }
}

void MotionControll::on_btn_RotateStart_clicked()
{
    if(ptrPLC->Connected())
    {
        byte buff = 1;
        ptrPLC->WriteArea(0x83 1 16 1 1 &buff);
        ui->btn_RotateStart->setDisabled(true);
        ui->btn_RotateStop->setDisabled(false);
    }
}

void MotionControll::on_btn_RotateStop_clicked()
{
    if(ptrPLC->Connected())
    {
        byte buff = 0;
        ptrPLC->WriteArea(0x83 1 16 1 1 &buff);
        ui->btn_RotateStart->setDisabled(true);
        ui->btn_RotateStop->setDisabled(false);
    }
}


void MotionControll::on_CheckBox_DistanceSet_stateChanged(int arg1)
{
    if(ui->CheckBox_DistanceSet->isChecked())
    {
        ui->lineEdit_Distance->setDisabled(false);
    }
    else
    {
        ui->lineEdit_Distance->setDisabled(true);
    }
}


void MotionControll::on_btn_GoEnd_clicked()
{
    //M201.5
    if(ptrPLC->Connected())
    {
        byte buff = 1;
        ptrPLC->WriteArea(0x83 1 1613 1 1 &buff);
        buff = 0;
        ptrPLC->WriteArea(0x83 1 1613 1 1 &buff);
    }
}

void MotionControll::on_btn_Stop_clicked()
{
    //M201.4
    if(ptrPLC->Connected())
    {
        if(!m_bStatus)
        {
            byte buff = 1;
            ptrPLC->WriteArea(0x83 1 1612 1 1 &buff);
            ui->btn_Stop->setstyleSheet(“background:rgb(02000)“);
            ui->btn_Stop->setText(“Continue“);
            m_bStatus = true;
        }
        else
        {
            byte buff = 0;
            ptrPLC->WriteArea(0x83 1 1612 1 1 &buff);
            ui->btn_Stop->setstyleSheet(“background:rgb(20010070)“);
            ui->btn_Stop->setText(“Pause“);
            m_bStatus = false;
        }
    }
}

void MotionControll::on_btn_GoBeginMannul_pressed()
{
    //M200.2
    if(ptrPLC->Connected())
    {
        byte buff = 1;
        ptrPLC->WriteArea(0x83 1 1603 1 1 &buff);
    }
}

void MotionControll::on_btn_GoBeginMannul_released()
{
    //M200.2
    if(ptrPLC->Connected())
    {
        byte buff = 0;
        ptrPLC->WriteArea(0x83 1 1603 1 1 &b

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-09-19 13:55  PLC通信\
     文件        5230  2019-09-18 09:27  PLC通信\motioncontroll.cpp
     文件        1046  2019-09-18 09:27  PLC通信\motioncontroll.h
     文件        3065  2019-09-18 09:27  PLC通信\motioncontroll.ui
     目录           0  2019-09-19 13:55  PLC通信\snap7\
     文件      244224  2019-09-12 13:45  PLC通信\snap7\snap7.dll
     文件       26188  2019-09-12 13:45  PLC通信\snap7\snap7.lib
     文件       30338  2019-09-18 09:27  PLC通信\snap7.cpp
     文件       41954  2019-09-18 09:27  PLC通信\snap7.h
     文件         315  2019-10-05 20:18  PLC通信\库添加.txt

评论

共有 条评论