📄 triggerdlg.cpp
字号:
// @dlg
//
// @module TriggerDlg.cpp
//
//
// Maintenance:
//
// Version Date Who What
// ------- -------- --- -------------------------------------
// 7.0 06/01/97 jra Created
//
// TriggerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ItkPlc.h"
#include "TriggerDlg.h"
#include "ItkProtocol.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// jra 061097
#define INVALID_MAP_ENTRY 0xFFFF
/////////////////////////////////////////////////////////////////////////////
// CTriggerDlg dialog
//----(Member Function)-------------------------------------------------------
//
// @mfunc | CTriggerDlg | CTriggerDlg |
//
// Constructor.
// Allocate your memory here.
//
CTriggerDlg::CTriggerDlg(DWORD dwMemorySize, CWnd* pParent)
: CDialog(CTriggerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTriggerDlg)
m_timer_rate = 0;
//}}AFX_DATA_INIT
this->m_dwMemorySize = dwMemorySize;
m_nNumTimers = 0;
}
//----(Member Function)-------------------------------------------------------
//
// @mfunc | CTriggerDlg | CTriggerDlg |
//
// Destructor.
// Free any dynamically allocated memory here.
//
CTriggerDlg::~CTriggerDlg()
{
}
//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CTriggerDlg | DoDataExchange |
//
//
void CTriggerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTriggerDlg)
DDX_Control(pDX, IDC_TRIGGER_REGS, m_TriggerRegisters);
DDX_Control(pDX, IDC_EXISTING_REGS, m_ExistingRegisters);
DDX_Text(pDX, IDC_TIMER_RATE, m_timer_rate);
DDV_MinMaxUInt(pDX, m_timer_rate, 1, 60000);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTriggerDlg, CDialog)
//{{AFX_MSG_MAP(CTriggerDlg)
ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
ON_BN_CLICKED(IDC_ADDALL_BUTTON, OnAddallButton)
ON_BN_CLICKED(IDC_REMOVE_BUTTON, OnRemoveButton)
ON_BN_CLICKED(IDC_REMOVEALL_BUTTON, OnRemoveallButton)
ON_BN_CLICKED(IDC_CANCEL, OnCancel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTriggerDlg message handlers
//----(Member Function)-------------------------------------------------------
//
// @mfunc BOOL | CTriggerDlg | OnInitDialog |
//
// Initialize the dialog members.
// Any any specific member initialization code here.
//
BOOL CTriggerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//
// Initialize our member variables
//
DWORD dwLoop;
CString str;
for (dwLoop = 0; dwLoop < this->m_dwMemorySize; dwLoop++)
{
if (m_nTriggerMap[dwLoop] == FALSE)
{
str.Format("%d", dwLoop);
this->m_ExistingRegisters.AddString(str);
}
else
{
str.Format("%d", dwLoop);
this->m_TriggerRegisters.AddString(str);
}
}
//
// Set the timer rate to the parent's rate
//
this->m_timer_rate = this->m_nCurrentRefreshRate;
UpdateData(FALSE);
return(TRUE);
}
//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CTriggerDlg | OnAddButton |
//
// Places the selected PLC registers in the timer map.
//
void CTriggerDlg::OnAddButton()
{
int nTempTriggerMap[PLC_MEMORY_SIZE],
nNewTimerVal;
DWORD dwMoved = 0,
i;
CString str;
//
// Invalidate the temp timer map
//
for (i = 0; i < this->m_dwMemorySize; i++)
{
nTempTriggerMap[i] = INVALID_MAP_ENTRY;
}
//
// Fetch the entries that were selected. Then go through and mark
// our global map and add them to the timer listbox
//
m_ExistingRegisters.GetSelItems(this->m_dwMemorySize, (LPINT)&nTempTriggerMap);
for (i = 0; i < this->m_dwMemorySize; i++)
{
if (nTempTriggerMap[i] != INVALID_MAP_ENTRY)
{
//
// Add it to the timer list
//
m_ExistingRegisters.GetText(nTempTriggerMap[i], str);
m_TriggerRegisters.AddString(str);
nNewTimerVal = atoi(str);
//
// Mark the register in the timer map
//
this->m_nTriggerMap[nNewTimerVal] = TRUE;
//
// Increment the Number of Timers holder
//
m_nNumTimers++;
}
else
{
break;
}
}
//
// Now delete the entries from the register box
//
for (i = 0; i < this->m_dwMemorySize; i++)
{
if (nTempTriggerMap[i] != INVALID_MAP_ENTRY)
{
//
// Remove item from exiting register list
//
m_ExistingRegisters.DeleteString(nTempTriggerMap[i]-dwMoved);
dwMoved++;
}
else
{
break;
}
}
}
//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CTriggerDlg | OnAddallButton |
//
// Places all PLC registers in the timer map.
//
void CTriggerDlg::OnAddallButton()
{
DWORD i;
CString str;
for (i = 0; i < this->m_dwMemorySize; i++)
{
//
// Mark the register in the timer map
//
this->m_nTriggerMap[i] = TRUE;
//
// Add it to the timer list
//
str.Format("%d", i);
m_TriggerRegisters.AddString(str);
}
//
// Clear the registers listbox
//
m_ExistingRegisters.ResetContent();
//
// The the Number of Timers holder to the PLC Memory size
//
m_nNumTimers = PLC_MEMORY_SIZE;
}
//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CTriggerDlg | OnRemoveButton |
//
// Removes the selected timers from the timer map.
//
void CTriggerDlg::OnRemoveButton()
{
int nTempTriggerMap[PLC_MEMORY_SIZE],
nNewTimerVal;
DWORD dwMoved = 0,
i;
CString str;
//
// Invalid the timer map.
//
for (i = 0; i < this->m_dwMemorySize; i++)
{
nTempTriggerMap[i] = INVALID_MAP_ENTRY;
}
//
// Fetch the entries that were selected. Then go through and mark
// our global map and add them to the timer listbox
//
m_TriggerRegisters.GetSelItems(this->m_dwMemorySize, (LPINT)&nTempTriggerMap);
for (i = 0; i < this->m_dwMemorySize; i++)
{
if (nTempTriggerMap[i] != INVALID_MAP_ENTRY)
{
//
// Add it to the existing list.
//
m_TriggerRegisters.GetText(nTempTriggerMap[i], str);
m_ExistingRegisters.AddString(str);
nNewTimerVal = atoi(str);
//
// Unmark the register in the timer map
//
this->m_nTriggerMap[nNewTimerVal] = FALSE;
//
// Decrement the Number of Timers holder
//
m_nNumTimers--;
}
else
{
break;
}
}
//
// Now delete the entries from the timer box
//
for (i = 0; i < this->m_dwMemorySize; i++)
{
if (nTempTriggerMap[i] != INVALID_MAP_ENTRY)
{
//
// Remove item from exiting register list
//
m_TriggerRegisters.DeleteString(nTempTriggerMap[i]-dwMoved);
dwMoved++;
}
else
{
break;
}
}
}
//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CTriggerDlg | OnRemoveallButton |
//
// Removes all triggers from the trigger map.
//
void CTriggerDlg::OnRemoveallButton()
{
DWORD i;
CString str;
for (i = 0; i < this->m_dwMemorySize; i++)
{
//
// Mark the register in the timer map
//
this->m_nTriggerMap[i] = FALSE;
//
// Add it to the existing list
//
str.Format("%d", i);
m_ExistingRegisters.AddString(str);
}
//
// Clear the triggers listbox
//
m_TriggerRegisters.ResetContent();
//
// Set the Number of Timers holder to 0
//
m_nNumTimers = 0;
}
//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CTriggerDlg | InitTimerMap |
//
// Initializes the timer map to either TRUE or FALSE (default). If it's TRUE,
// then every PLC register will be in the timer list. If it's FALSE, then
// no PLC registers will be in the timer list.
//
void CTriggerDlg::InitTimerMap(BOOL bInitVal)
{
memset(&this->m_nTriggerMap, bInitVal, (this->m_dwMemorySize*sizeof(int)));
}
//----(Member Function)-------------------------------------------------------
//
// @mfunc BOOL | COLEServerDlg | GetTimerMap |
//
// Returns the timer map. The timer map is an array that contains
// which values should be updated.
//
void CTriggerDlg::GetTimerMap(int *nMap)
{
memcpy(nMap, this->m_nTriggerMap, (this->m_dwMemorySize*sizeof(int)));
}
//----(Member Function)-------------------------------------------------------
//
// @mfunc BOOL | COLEServerDlg | GetNumTimers |
//
// Returns the number ot timers in the timer map
//
int CTriggerDlg::GetNumTimers(void)
{
return (this->m_nNumTimers);
}
//----(Member Function)-------------------------------------------------------
//
// @mfunc UINT | CTriggerDlg | GetRefreshRate |
//
// Returns the refresh rate for the timer.
//
UINT CTriggerDlg::GetRefreshRate()
{
return(this->m_timer_rate);
}
//----(Member Function)-------------------------------------------------------
//
// @mfunc BOOL | CTriggerDlg | OnCancel |
//
// Default Cancel button
// Add any code here to be executed when the user clicks the Cancel button.
//
void CTriggerDlg::OnCancel()
{
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -