LAPTOP-SNT8I5JK\Boounion
2024-11-18 0239509af412b74083b33a6924ffd79007dfda5f
1.轴对话框,当前参数读取和显示;
已修改8个文件
90 ■■■■■ 文件已修改
SourceCode/Bond/BondEq/AxisSettingsDlg.cpp 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BondEq/AxisSettingsDlg.h 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BondEq/BondEqDlg.cpp 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BondEq/CBonder.cpp 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BondEq/CBonder.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BondEq/CPLC.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BondEq/ToolUnits.cpp 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BondEq/ToolUnits.h 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BondEq/AxisSettingsDlg.cpp
@@ -5,7 +5,11 @@
#include "BondEq.h"
#include "afxdialogex.h"
#include "AxisSettingsDlg.h"
#include "ToolUnits.h"
#define TIMER_INIT                1
#define TIMER_READ_PLC_DATA        2
// CAxisSettingsDlg 对话框
@@ -16,6 +20,7 @@
{
    m_nInitialWidth = 0;
    m_nInitialHeight = 0;
    m_pPLC = nullptr;
}
CAxisSettingsDlg::~CAxisSettingsDlg()
@@ -48,11 +53,17 @@
    ON_WM_SIZE()
    ON_WM_CTLCOLOR()
    ON_WM_SIZING()
    ON_WM_TIMER()
END_MESSAGE_MAP()
// CAxisSettingsDlg 消息处理程序
void CAxisSettingsDlg::SetPLC(CPLC* pPLC)
{
    ASSERT(pPLC);
    m_pPLC = pPLC;
}
BOOL CAxisSettingsDlg::OnInitDialog()
{
@@ -70,6 +81,9 @@
    rect.bottom *= 1.5;
    // 调整对话框大小
    MoveWindow(rect);
    SetTimer(TIMER_READ_PLC_DATA, 500, nullptr);
    return TRUE;  // return TRUE unless you set the focus to a control
    // 异常: OCX 属性页应返回 FALSE
@@ -243,3 +257,36 @@
    pWnd->SetFont(&newFont);
    pWnd->Invalidate();
}
void CAxisSettingsDlg::OnTimer(UINT_PTR nIDEvent)
{
    if (TIMER_READ_PLC_DATA == nIDEvent) {
        ASSERT(m_pPLC);
        int addr1, addr2, readSize;
        addr1 = 5120;
        addr2 = 5425;
        readSize = (addr2 - addr1 + 1) * 2;
        auto funOnReadData = [&, addr1, readSize](IMcChannel* pChannel, int addr, char* pData, unsigned int nDataSize, int flag) -> void {
            if (nDataSize == readSize && flag == 0) {
                double fCurPos = CToolUnits::toInt32(pData) * 0.001;
                double fManualSpeed = CToolUnits::toInt32(&pData[(5422- addr1)*2]) * 0.001;
                double fAutoSpeed = CToolUnits::toInt32(&pData[(5424 - addr1) * 2]) * 0.001;
                double fPrm = CToolUnits::toInt32(&pData[(5150 - addr1) * 2]) * 0.1;
                int nLoad = CToolUnits::toInt16(&pData[(5154 - addr1) * 2]);
                int nErrCode = CToolUnits::toInt16(&pData[(5126 - addr1) * 2]);
                int nAlarmCode = CToolUnits::toInt16(&pData[(5127 - addr1) * 2]);
                CToolUnits::setDlgItemDouble(this, IDC_EDIT_AXIS_CURR_POS, fCurPos);
                CToolUnits::setDlgItemDouble(this, IDC_EDIT_AXIS_CURR_MANUAL_SPEED, fManualSpeed);
                CToolUnits::setDlgItemDouble(this, IDC_EDIT_AXIS_CURR_AUTO_SPEED, fAutoSpeed);
                CToolUnits::setDlgItemDouble(this, IDC_EDIT_AXIS_CURR_ROTA_SPEED, fPrm);
                SetDlgItemInt(IDC_EDIT_AXIS_CURR_LOAD, nLoad);
                SetDlgItemInt(IDC_EDIT_AXIS_CURR_ERROR_NUMBER, nErrCode);
                SetDlgItemInt(IDC_EDIT_AXIS_CURR_ALARM_NUMBER, nAlarmCode);
            }
        };
        m_pPLC->readData(MC::SOFT_COMPONENT::D, addr1, readSize, funOnReadData);
    }
    CDialogEx::OnTimer(nIDEvent);
}
SourceCode/Bond/BondEq/AxisSettingsDlg.h
@@ -1,5 +1,6 @@
#pragma once
#include "afxdialogex.h"
#include "CPLC.h"
// CAxisSettingsDlg 对话框
@@ -11,6 +12,10 @@
public:
    CAxisSettingsDlg(CWnd* pParent = nullptr);   // 标准构造函数
    virtual ~CAxisSettingsDlg();
public:
    void SetPLC(CPLC* pPLC);
// 对话框数据
#ifdef AFX_DESIGN_TIME
@@ -48,4 +53,9 @@
private:
    int m_nInitialWidth;
    int m_nInitialHeight;
private:
    CPLC* m_pPLC;
public:
    afx_msg void OnTimer(UINT_PTR nIDEvent);
};
SourceCode/Bond/BondEq/BondEqDlg.cpp
@@ -542,8 +542,9 @@
                m_pTopToolbar->SetOperatorBtnText(_T("未登录"));
            }
            CAxisSettingsDlg loginDlg;
            loginDlg.DoModal();
            CAxisSettingsDlg axisDlg;
            axisDlg.SetPLC(theApp.m_model.getBonder().getPLC("PLC(1)"));
            axisDlg.DoModal();
        }
    }
SourceCode/Bond/BondEq/CBonder.cpp
@@ -69,6 +69,11 @@
    return m_components;
}
CPLC* CBonder::getPLC(const char* pszName)
{
    return (CPLC*)GetComponent("PLC(1)");
}
int CBonder::save()
{
    CFile file;
SourceCode/Bond/BondEq/CBonder.h
@@ -42,6 +42,7 @@
    void setListener(BondListener& listener);
    void setWorkDir(const char* pszWorkDir);
    const std::vector<CComponent*>& getComponents();
    CPLC* getPLC(const char* pszName);
    int init();
    int term();
    void sendBroadcast(CComponent* pSender, CIntent* pIntent);
SourceCode/Bond/BondEq/CPLC.cpp
@@ -308,7 +308,7 @@
    static int iii = 0;
    iii++;
    if (iii % 5 == 3) {
        if (!m_pChannel->isConnected())
        if (m_pChannel != nullptr && !m_pChannel->isConnected())
            m_pChannel->connect();
    }
}
SourceCode/Bond/BondEq/ToolUnits.cpp
@@ -145,3 +145,20 @@
    DWORD attributes = GetFileAttributes(path.c_str());
    return (attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_DIRECTORY));
}
double CToolUnits::toInt32(const char* pBuffer)
{
    return (pBuffer[0] & 0xff) | (pBuffer[1] & 0xff) << 8 | (pBuffer[2] & 0xff) << 16 | (pBuffer[3] & 0xff) << 24;
}
double CToolUnits::toInt16(const char* pBuffer)
{
    return (pBuffer[0] & 0xff) | (pBuffer[1] & 0xff) << 8;
}
void CToolUnits::setDlgItemDouble(CWnd* pWnd, int nCtrlId, double value)
{
    CString strText;
    strText.Format(_T("%.03f"), value);
    pWnd->SetDlgItemText(nCtrlId, strText);
}
SourceCode/Bond/BondEq/ToolUnits.h
@@ -20,5 +20,8 @@
    static std::string getCurrentExePath();
    static bool isFile(const std::string& path);
    static bool isDirectory(const std::string& path);
    static double toInt32(const char* pBuffer);
    static double toInt16(const char* pBuffer);
    static void setDlgItemDouble(CWnd* pWnd, int nCtrlId, double value);
};