S5F1用途
This message reports a change in or presence of an alarm condition. One message will be issued when the alarm is set and one message will be issued when the alarm is cleared. Irrecoverable errors and attention flags may not have a corresponding clear message.
ALID是什么?
Alarm怎么处理
获取和处理ALID、ALTX等
S5F1、S5F2、S5F3、S5F4、S5F5、S5F6指令
?中文SECS/GEM方案网站 www.secsgem.cn?
头文件
#pragma once
#include "afxcmn.h"
// CAlarmView 对话框
class CAlarmView : public CMyDialogEx
{
DECLARE_DYNAMIC(CAlarmView)
public:
CAlarmView(CWnd* pParent = NULL); // 标准构造函数
virtual ~CAlarmView();
// 对话框数据
enum { IDD = IDD_ALARM_VIEW };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
virtual BOOL OnInitDialog();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBtnEnable();
afx_msg void OnBtnDisable();
afx_msg void OnBtnDiscovery();
afx_msg void OnLvnItemchangedListAlarm(NMHDR *pNMHDR, LRESULT *pResult);
LRESULT OnStateChange(WPARAM wp, LPARAM lp);
LRESULT OnAlarmChange(WPARAM wp, LPARAM lp);
public:
// 更新列表
void UpdateAlarmList();
void DeleteAllItem();
int AddItemToCtrl(ALARM_DATA& var);
void InitCtrl();
void AlarmEnable(string pALID, bool bEnable);
void UpdateAlarmLineColour(int nLine, bool bAlarm); // 改变警报行颜色
void InitAlarm();
void SortObject(vector<ALARM_DATA>& veVar); // 排序
private:
CListCtrlCl m_ctrlVariable;
int m_nSelID;
int m_nCurSel;
};
CPP部分
// ChildView/AlarmView.cpp : 实现文件
//
#include "stdafx.h"
#include "HostViewApp.h"
#include "ChildView/AlarmView.h"
#include "afxdialogex.h"
#include "CallbackHandle/CallbackHandle.h"
// CAlarmView 对话框
IMPLEMENT_DYNAMIC(CAlarmView, CMyDialogEx)
CAlarmView::CAlarmView(CWnd* pParent /*=NULL*/)
: CMyDialogEx(CAlarmView::IDD, pParent)
{
SetTitle("警报");
}
CAlarmView::~CAlarmView()
{
}
void CAlarmView::DoDataExchange(CDataExchange* pDX)
{
CMyDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST_ALARM, m_ctrlVariable);
}
BEGIN_MESSAGE_MAP(CAlarmView, CMyDialogEx)
ON_MESSAGE(ON_CONTROL_CHANGE, OnStateChange)
ON_BN_CLICKED(IDC_BTN_ENABLE, OnBtnEnable)
ON_BN_CLICKED(IDC_BTN_DISABLE, OnBtnDisable)
ON_BN_CLICKED(IDC_BTN_DISCOVERY, OnBtnDiscovery)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_ALARM, OnLvnItemchangedListAlarm)
ON_MESSAGE(ON_ALARM_CHANGE, OnAlarmChange)
END_MESSAGE_MAP()
// CAlarmView 消息处理程序
BOOL CAlarmView::OnInitDialog()
{
CMyDialogEx::OnInitDialog();
InitCtrl();
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void CAlarmView::InitCtrl()
{
m_ctrlVariable.InsertColumn(0, "ALID", 0, 100);
m_ctrlVariable.InsertColumn(1, "Enable", 0, 80);
m_ctrlVariable.InsertColumn(2, "Set", 0, 80);
m_ctrlVariable.InsertColumn(3, "Name", 0, 496);
m_ctrlVariable.InitCtrl();
}
void CAlarmView::OnBtnDiscovery()
{
UpdateAlarmList();
}
LRESULT CAlarmView::OnStateChange(WPARAM wp, LPARAM lp)
{
if(lp == eCONTROL_ONLINE)
{
InitAlarm();
}
return 0;
}
LRESULT CAlarmView::OnAlarmChange(WPARAM wp, LPARAM lp)
{
int nIsSet = (int)lp;
const char* pALID = (char* )wp;
if(pALID != nullptr)
{
// 从查找对应的ID进行修改
int nCount = m_ctrlVariable.GetItemCount();
CString ID;
for (int i = 0; i < nCount; i++)
{
ID = m_ctrlVariable.GetItemText(i, 0);
if(ID == pALID)
{
m_ctrlVariable.SetItemText(i, 2, (nIsSet==0?"0":"1"));
UpdateAlarmLineColour(i, nIsSet != 0);
break;
}
}
}
return 0;
}
// 更新列表
void CAlarmView::UpdateAlarmList()
{
vector<ALARM_DATA> vas;
RcResult rc = m_pSecs->AlarmListGet(vas);
SHOW_MSG_RC(rc);
if(rc.rc == 0)
{
SortObject(vas); // 排序
DeleteAllItem();
// 添加到界面
int nSel = 0;
for(unsigned int i = 0; i < vas.size(); i++)
{
nSel = AddItemToCtrl(vas[i]);
if (nSel >= 0)
{
// 更新颜色
UpdateAlarmLineColour(nSel, vas[i].bSet);
}
}
}
}
// 排序
void CAlarmView::SortObject(vector<ALARM_DATA>& veVar)
{
list<SORT_OBJECT> listSort;
list<SORT_OBJECT>::iterator listIte;
vector<ALARM_DATA> veTmp = veVar;
// 排序
for (unsigned int i = 0; i < veTmp.size(); i++)
{
SORT_OBJECT pObject;
pObject.nNum = ::atoi(veTmp[i].ALID.c_str());
pObject.pObject = &veTmp[i];
for (listIte = listSort.begin(); listIte != listSort.end(); listIte++)
{
if (listIte->nNum > pObject.nNum)
{
break;
}
}
listSort.insert(listIte, pObject);
}
// 复制到原来的对象
veVar.clear();
for (listIte = listSort.begin(); listIte != listSort.end(); listIte++)
{
veVar.push_back(*(ALARM_DATA*)(listIte->pObject));
}
}
void CAlarmView::DeleteAllItem()
{
m_ctrlVariable.DeleteAllItems();
}
int CAlarmView::AddItemToCtrl(ALARM_DATA& ad)
{
int nCount = m_ctrlVariable.GetItemCount();
m_ctrlVariable.InsertItem(nCount, ad.ALID.c_str());
m_ctrlVariable.SetItemText(nCount, 1, (ad.bEnable ? "1" : "0"));
m_ctrlVariable.SetItemText(nCount, 2, (ad.bSet ? "1" : "0"));
m_ctrlVariable.SetItemText(nCount, 3, ad.ALTX.c_str());
return nCount;
}
void CAlarmView::OnBtnEnable()
{
CString pALID = m_ctrlVariable.GetItemText(m_nCurSel, 0);
AlarmEnable((LPCSTR)pALID, true);
}
void CAlarmView::OnBtnDisable()
{
CString pALID = m_ctrlVariable.GetItemText(m_nCurSel, 0);
AlarmEnable((LPCSTR)pALID, false);
}
void CAlarmView::AlarmEnable(string pALID, bool bEnable)
{
int nALID = ::atoi(pALID.c_str());
RcResult rc = m_pSecs->AlarmEnable(nALID, bEnable);
if(rc.rc)
{
SHOW_MSG_RC(rc);
}
else
{
m_ctrlVariable.SetItemText(m_nCurSel, 1, bEnable?"1":"0");
}
}
void CAlarmView::OnLvnItemchangedListAlarm(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
*pResult = 0;
if(pNMLV->uOldState != 0 //旧状态
&& pNMLV->uNewState == 0)
{
}
else //新状态 和 选择同样
{
m_nCurSel = pNMLV->iItem;
CString pText = m_ctrlVariable.GetItemText(m_nCurSel, 0);
m_nSelID = ::atol(pText);
}
}
// 改变警报行颜色
void CAlarmView::UpdateAlarmLineColour(int nLine, bool bAlarm)
{
COLORREF pSetColor = RGB(128, 0, 0);
COLORREF pClearColor = RGB(128, 128, 128); // disco色
if(bAlarm)
{
// 警报
m_ctrlVariable.SetRowColor(nLine, pSetColor);
m_ctrlVariable.Invalidate();
}
else
{
// 正常
m_ctrlVariable.SetRowColor(nLine, pClearColor);
m_ctrlVariable.Invalidate();
}
}
void CAlarmView::InitAlarm()
{
if (g_appdata.m_bInitAlarm)
{
UpdateAlarmList();
}
}