darker
2025-02-18 f4e3d35dd0f912c303b13b48a4a3fc09ccb0a845
1. 遍历设备类的属性,并显示在界面上
已添加2个文件
已修改2个文件
117 ■■■■■ 文件已修改
SourceCode/Bond/Servo/CEquipment.cpp 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CEquipment.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/DevicePropertyDlg.cpp 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/DevicePropertyDlg.h 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CEquipment.cpp
@@ -24,6 +24,15 @@
        m_listener.onCimStateChanged = listener.onCimStateChanged;
    }
    void CEquipment::getProperties(std::vector<std::pair<std::string, std::string>>& container)
    {
        container.clear();
        // ç¤ºä¾‹ï¼šå°†ä¸€äº›å±žæ€§æ·»åŠ åˆ°å®¹å™¨
        container.push_back(std::make_pair("DeviceName", "ServoMotor"));
        container.push_back(std::make_pair("SerialNumber", "123456789"));
        container.push_back(std::make_pair("Version", "1.0"));
    }
    void CEquipment::init()
    {
SourceCode/Bond/Servo/CEquipment.h
@@ -51,6 +51,7 @@
        MemoryBlock& getReadBitBlock();
        void setWriteBitBlock(unsigned int start, unsigned int end);
        MemoryBlock& getWriteBitBlock();
        void getProperties(std::vector<std::pair<std::string, std::string>>& container);
        virtual void init();
        virtual void term();
        virtual void onTimer(UINT nTimerid);
SourceCode/Bond/Servo/DevicePropertyDlg.cpp
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,79 @@
// CDevicePropertyDlg.cpp: å®žçŽ°æ–‡ä»¶
//
#include "stdafx.h"
#include "Servo.h"
#include "afxdialogex.h"
#include "DevicePropertyDlg.h"
// CDevicePropertyDlg å¯¹è¯æ¡†
IMPLEMENT_DYNAMIC(CDevicePropertyDlg, CDialogEx)
CDevicePropertyDlg::CDevicePropertyDlg(CWnd* pParent /*=nullptr*/, int nDeviceID /*=0*/)
    : CDialogEx(IDD_DIALOG_DEVICE_PROPERTY, pParent), m_nDeviceID(nDeviceID)
{
}
CDevicePropertyDlg::~CDevicePropertyDlg()
{
}
void CDevicePropertyDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_LIST_DEVICE_PROPERTY, m_listDeviceProperties);
}
BEGIN_MESSAGE_MAP(CDevicePropertyDlg, CDialogEx)
END_MESSAGE_MAP()
// CDevicePropertyDlg æ¶ˆæ¯å¤„理程序
BOOL CDevicePropertyDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
    // TODO:  åœ¨æ­¤æ·»åŠ é¢å¤–çš„åˆå§‹åŒ–
    SERVO::CEquipment* pEquipment = theApp.m_model.m_master.getEquipment(m_nDeviceID);
    if (nullptr == pEquipment) {
        LOGI("<设备ID:%d>获取设备属性失败。", m_nDeviceID);
        return FALSE;
    }
    // ä¿®æ”¹å¯¹è¯æ¡†æ ‡é¢˜
    std::string strDeviceName = pEquipment->getName();
    SetWindowText(CString(strDeviceName.c_str()));
    // èŽ·å–æ‰€æœ‰è®¾å¤‡å±žæ€§
    std::vector<std::pair<std::string, std::string>> properties;
    pEquipment->getProperties(properties);
    // èŽ·å–ListCtrl的客户区域
    CRect rect;
    m_listDeviceProperties.GetClientRect(&rect);
    int nTotalWidth = rect.Width();
    int nColumnWidth = 150;
    m_listDeviceProperties.InsertColumn(0, _T("名称"), LVCFMT_LEFT, nColumnWidth);
    m_listDeviceProperties.InsertColumn(1, _T("值"), LVCFMT_LEFT, nColumnWidth);
    // éåŽ†å®¹å™¨ä¸­çš„æ‰€æœ‰å±žæ€§å¹¶è¾“å‡º
    int nItem = 0;
    for (const auto& property : properties) {
        // æ’入设备属性
        m_listDeviceProperties.InsertItem(nItem, property.first.c_str());
        m_listDeviceProperties.SetItemText(nItem, 1, property.second.c_str());
        ++nItem;
    }
    // è®¾ç½®ç¬¬äºŒåˆ—宽度
    m_listDeviceProperties.SetColumnWidth(1, nTotalWidth - nColumnWidth);
    return TRUE;  // return TRUE unless you set the focus to a control
    // å¼‚常: OCX å±žæ€§é¡µåº”返回 FALSE
}
SourceCode/Bond/Servo/DevicePropertyDlg.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,28 @@
#pragma once
#include "afxdialogex.h"
// CDevicePropertyDlg å¯¹è¯æ¡†
class CDevicePropertyDlg : public CDialogEx
{
    DECLARE_DYNAMIC(CDevicePropertyDlg)
public:
    CDevicePropertyDlg(CWnd* pParent = nullptr, int nDeviceID = 0);   // æ ‡å‡†æž„造函数
    virtual ~CDevicePropertyDlg();
// å¯¹è¯æ¡†æ•°æ®
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_DIALOG_DEVICE_PROPERTY };
#endif
protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV æ”¯æŒ
    virtual BOOL OnInitDialog();
    DECLARE_MESSAGE_MAP()
private:
    int m_nDeviceID;
    CListCtrl m_listDeviceProperties;
};