⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod_rssimdlg.cpp

📁 用于开发Modbus工业级通信
💻 CPP
📖 第 1 页 / 共 5 页
字号:
   m_listCtrlData.SetupColumns(LONG (cols+1), m_isClone);
} // SetupListViewControl


// ---------------------------- LoadApplicationSettings -----------------
void CMOD_simDlg::LoadApplicationSettings()
{
CString registryPath;
DRegKey key;
DWORD len = sizeof(m_portNameShort);
DWORD animationType;

   ////////////////////////////////////////////////////
   // set default values
   strcpy(m_portNameShort, "COM1");
   m_baud = CBR_9600;
   m_byteSize = 8;
   m_parity = NOPARITY;
   m_stopBits = ONESTOPBIT;
   m_rts = RTS_CONTROL_ENABLE;

   registryPath = APPREGISTRY_SETTINGSKEY;
   // colors
   m_mTickColorActive =   RGB(0xFF, 0xFF, 0x00);   // yellow
   m_mTickColorInactive = RGB(0x80, 0x80, 0x80);   // gray
   m_mTickColorEnabled =  RGB(0x00, 0x80, 0x00);   // green
   m_mTickColorDisabled = RGB(0xFF, 0x00, 0x00);   // red
   m_mTickColorText =     RGB(0x00, 0x00, 0x00);   // black
   m_mTickDisColorText =  RGB(0x00, 0x00, 0x00);   // black

   m_appSettingAdressHex = FALSE;
   m_numInputs  = 65535;
   m_numOutputs = 65535;
   m_numHolding = 65535;
   m_numExtended= 65535;
   m_numAnalogs = 65535;
   m_PDUSize = 2048; // 4096 bytes max

   m_selectedProtocol = PROTOCOL_SELMODETH;  // default protocol
   m_isClone = FALSE;
   m_startUpRegisterArea = 3;

   m_localPort = 502;
   m_otherPort = 501;
   m_numServers = 10;
   m_linger = FALSE;
   m_localId = 1;

   //////////////////////////////////////////////////
   // load the baud rate etc
   key.Open(DRegKey::local_machine, registryPath);
   key.QueryValue("Port", m_portNameShort, &len); 
   key.QueryValue("BaudRate", &m_baud);
   key.QueryValue("ByteSize", &m_byteSize);
   key.QueryValue("Parity", &m_parity);
   key.QueryValue("StopBits", &m_stopBits);
   key.QueryValue("RTS", &m_rts);
   key.QueryValue("ResponseDelays", &m_responseDelay);
   key.QueryValue("MOSCAD", &m_MOSCADchecks);
   key.QueryValue("AutoLoad", &m_autoLoad);
   key.QueryValue("DevicesOfflineAtStart", &m_startAsOff);
   key.QueryValue("ModifyThenRespond", &m_modifyThenRespond);
   key.QueryValue("DisableWrites", &m_disableWrites);
   key.QueryValue("PLCMaster", &m_PLCMaster);
   key.QueryValue("UseBCCs", &m_useBCC);
   // JOY
   key.QueryValue("JOYSOURCE", &m_JOYsourceStation);
   key.QueryValue("JOYDEST", &m_JOYdestStation);
   key.QueryValue("JOYShields", &m_JOYnumShields);
   key.QueryValue("JOYRun", &m_JOYrunMode);
   key.QueryValue("JOYRead", &m_JOYreadVariables);
   key.QueryValue("JOYWrite", &m_JOYwriteVariables);
   key.QueryValue("ABmasterIDLETime", &m_ABmasterIDLETime);
   key.QueryValue("ABtimeoutValue", &m_ABtimeoutValue);

   key.QueryValue("TickColorActive",   &m_mTickColorActive);
   key.QueryValue("TickColorInactive", &m_mTickColorInactive);
   key.QueryValue("TickColorEnabled",  &m_mTickColorEnabled);
   key.QueryValue("TickColorDisabled", &m_mTickColorDisabled);
   key.QueryValue("TickColorText",     &m_mTickColorText);
   key.QueryValue("TickDisabledColorText",     &m_mTickDisColorText);

   key.QueryValue("AddressHex", &m_appSettingAdressHex);
   key.QueryValue("AnimationON", &m_animationPeriod);
   key.QueryValue("RegisterSel", &m_startUpRegisterArea);

   key.QueryValue("InputRegisters",    &m_numInputs  );
   key.QueryValue("OutputRegisters",   &m_numOutputs );
   key.QueryValue("HoldingRegisters",  &m_numHolding );
   key.QueryValue("ExtendedRegisters", &m_numExtended);
   key.QueryValue("AnalogRegisters",   &m_numAnalogs );
   key.QueryValue("PDUSize",   &m_PDUSize);

   key.QueryValue("Protocol", &m_selectedProtocol);
   key.QueryValue("EthernetServers", &m_numServers);
   key.QueryValue("LingerClose", &m_linger);
   key.QueryValue("EthernetID", &m_localId);
   key.QueryValue("EthernetPort", &m_localPort);
   key.QueryValue("EthernetPort2", &m_otherPort);

   key.QueryValue("AnimationIncrement", &m_animationIncValue);

   key.QueryValue("RegistrationUserName", m_registeredUser);
   key.QueryValue("RegistrationKey", m_registeredKey);
   key.SetValue("RegistrationUserName", m_registeredUser);
   key.SetValue("RegistrationKey", m_registeredKey);

   m_registeredOK = CheckRegistrationKey(m_registeredUser, m_registeredKey);
   if (!m_registeredOK)
      CSplashWnd::SetWaitCount(5);
   m_animationON = FALSE;
   m_plantAnimation = FALSE;
   m_animationBYTE = FALSE;
   m_animationWORD = FALSE;
   key.QueryValue("AnimationType", &animationType);
   switch (animationType)
   {
      case 1: m_animationBYTE = TRUE;
         break;
      case 2: m_animationWORD = TRUE;
         break;
      case 3: m_plantAnimation = TRUE;
         break;
      default:
         break;
   }
   if (m_animationBYTE || m_animationWORD || m_plantAnimation)
      m_animationON = TRUE;
   key.QueryValue("AnimationScript", m_animationScriptFile);
//   m_checkParity = (NOPARITY==m_parity?FALSE;TRUE);

} // LoadApplicationSettings

// ---------------------------- SaveApplicationSettings -----------------
// save program settings to HKEY_LOCAL_MACHINE registry
void CMOD_simDlg::SaveApplicationSettings()
{
CString registryPath;
DRegKey key;
DWORD animationType;

   m_appSettingAdressHex = m_listCtrlData.IsAddressFormatHex();
   // Save the baud rate etc
   registryPath = APPREGISTRY_SETTINGSKEY;
   key.Open(DRegKey::local_machine, registryPath);
   key.SetValue("Port", m_portNameShort, strlen(m_portNameShort)); 
   key.SetValue("BaudRate", m_baud);
   key.SetValue("ByteSize", m_byteSize);
   key.SetValue("Parity", m_parity);
   key.SetValue("StopBits", m_stopBits);
   key.SetValue("RTS", m_rts);
   key.SetValue("ResponseDelays", m_responseDelay);
   key.SetValue("MOSCAD", m_MOSCADchecks);
   key.SetValue("AutoLoad", m_autoLoad);
   key.SetValue("DevicesOfflineAtStart", m_startAsOff);
   key.SetValue("ModifyThenRespond", m_modifyThenRespond);
   key.SetValue("DisableWrites", m_disableWrites);
   key.SetValue("PLCMaster", m_PLCMaster);
   key.SetValue("UseBCCs", m_useBCC);
   
   key.SetValue("JOYSOURCE",  m_JOYsourceStation);
   key.SetValue("JOYDEST",    m_JOYdestStation);
   key.SetValue("JOYShields", m_JOYnumShields);
   key.SetValue("JOYRun",     m_JOYrunMode);
   key.SetValue("JOYRead",    m_JOYreadVariables);
   key.SetValue("JOYWrite",    m_JOYwriteVariables);
   key.SetValue("ABmasterIDLETime", m_ABmasterIDLETime);
   key.SetValue("ABtimeoutValue", m_ABtimeoutValue);

   key.SetValue("TickColorActive",     m_mTickColorActive);
   key.SetValue("TickColorInactive",   m_mTickColorInactive);
   key.SetValue("TickColorEnabled",    m_mTickColorEnabled);
   key.SetValue("TickColorDisabled",   m_mTickColorDisabled);
   key.SetValue("TickColorText",       m_mTickColorText);
   key.SetValue("TickDisabledColorText", m_mTickDisColorText);

   key.SetValue("AddressHex",  m_appSettingAdressHex);
   key.SetValue("AnimationON", m_animationPeriod);
   key.SetValue("RegisterSel", m_startUpRegisterArea);

   key.SetValue("InputRegisters",    m_numInputs);
   key.SetValue("OutputRegisters",   m_numOutputs);
   key.SetValue("HoldingRegisters",  m_numHolding);
   key.SetValue("ExtendedRegisters", m_numExtended);
   key.SetValue("AnalogRegisters",   m_numAnalogs);
   key.SetValue("PDUSize",   m_PDUSize);

   key.SetValue("Protocol", m_selectedProtocol);
   key.SetValue("EthernetServers", m_numServers);
   key.SetValue("LingerClose", m_linger);
   key.SetValue("EthernetID", m_localId);

   key.SetValue("EthernetPort", m_localPort);
   key.SetValue("EthernetPort2", m_otherPort);

   key.SetValue("AnimationIncrement", m_animationIncValue);
   animationType = 0;
   if (m_animationON)
   {
      if (m_animationBYTE) animationType = 1;
      if (m_animationWORD) animationType = 2;
      if (m_plantAnimation) animationType = 3;
   }
   key.SetValue("AnimationType", animationType);
   key.SetValue("AnimationScript", m_animationScriptFile);

} // SaveApplicationSettings


// -------------------------- OnSysCommand -----------------------------
// Handle the "system menu"
void CMOD_simDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
   switch (nID & 0xFFF0) 
   {
   case IDM_ABOUTBOX:
      OnAboutboxBn();
      break;
   case IDM_ALPHA_60:
      SetAlphaBlendLow();
      break;
   case IDM_ALPHA_70:
      SetAlphaBlendHigh();
      break;
   case IDM_ALPHA:
      SetAlphaBlendSolid();
      break;
   case IDM_ONTOP :
      ToggleOnTop();
      break;
   case IDM_EMULATE :
      OnEmulation();
      break;
   default:
      CDialog::OnSysCommand(nID, lParam);
      break;
   }
} // OnSysCommand

// --------------------------------- OnPaint --------------------------------
// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.
void CMOD_simDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIconMB);
	}
	else
	{
		CDialog::OnPaint();
	}
} // OnPaint

// ------------------------------- OnQueryDragIcon --------------------------
// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMOD_simDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIconMB;
}

// -------------------------------- UnloadCommsProcessors ----------------------
// Stop and load all comms processors, there is only 1, but can be many if on ethernet
vo

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -