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

📄 settingsdlg.cpp

📁 工业强度的PLC模拟程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// Returns a CStrinf containing the port name, such as "COM1".
//
CString CSettingsDlg::GetPortName()
{
	return(this->m_port_name);
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | SetPortName |
//
// Sets the port name for serial communications. Defaults to "COM1".
//
void CSettingsDlg::SetPortName(CString csPName)
{
	if (csPName.IsEmpty())
	{
		this->m_port_name = "COM1";
		return;
	}

	this->m_port_name = csPName;
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc CString | CSettingsDlg | GetPortMode |
//
// Returns a CString containing the serial protocol parameters used buy the port.
// The CString is in the form of "Baud,Parity,Data_bits,Stop_bits". An example 
// would be as follows: "9600,n,8,1"
//
CString CSettingsDlg::GetPortMode()
{
	CString szPortMode,
		    szParityLetter;

	if (this->m_parity == "None") 
	{
		szParityLetter = "n";
	}
	else if (this->m_parity == "Even") 
	{
		szParityLetter = "e";
	}
	else if (this->m_parity == "Odd") 
	{
		szParityLetter = "o";
	}
	else if (this->m_parity == "Space") 
	{
		szParityLetter = "s";
	}
	else if (this->m_parity == "Mark") 
	{
		szParityLetter = "m";
	}

	szPortMode.Empty();
	szPortMode = this->m_baud_rate + "," + szParityLetter + "," + 
		        this->m_data_bits + "," + this->m_stop_bits;
	return(szPortMode);
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | SetPortMode |
//
// Sets the serial port communications parameters. The CString is in the
// form of "Baud,Parity,Data_bits,Stop_bits". An example would be as follows:
// "9600,n,8,1"
//
void CSettingsDlg::SetPortMode(CString csPMode)
{
	//
	// If the mode is empty, then set to defaults
	//
	if (csPMode.IsEmpty())
	{
		this->m_baud_rate = "9600";
		this->m_data_bits = "8";
		this->m_stop_bits = "1";
		this->m_parity    = "None";
		return;
	}


	//
	// Well, the string is not empty, so parse out the data.
	//
	int		nLen = csPMode.GetLength(), nLoc = 0;

	char	pszTempBuf[20], 
			*psPtr = csPMode.GetBuffer(nLen + 1); 


	strcpy(pszTempBuf, psPtr);
	csPMode.ReleaseBuffer();
	psPtr = NULL;

	// 
	// Get the baud rate
	//
	nLoc = csPMode.Find(',');
	psPtr = pszTempBuf + nLoc;
	*psPtr = NULL;
	this->m_baud_rate = pszTempBuf;
	strcpy(pszTempBuf, ++psPtr);
	csPMode = pszTempBuf;

	// 
	// Get the parity
	//
	nLoc = csPMode.Find(',');
	psPtr = pszTempBuf + nLoc;
	*psPtr = NULL;
	switch (*pszTempBuf)
	{
	case 'e':
		this->m_parity = "Even";
		break;

	case 'o':
		this->m_parity = "Odd";
		break;

	case 's':
		this->m_parity = "Space";
		break;

	case 'm':
		this->m_parity = "Mark";
		break;

	case 'n':
	default:
		this->m_parity = "None";
		break;
	}
	strcpy(pszTempBuf, ++psPtr);
	csPMode = pszTempBuf;

	//
	// Get the data bits
	//
	nLoc = csPMode.Find(',');
	psPtr = pszTempBuf + nLoc;
	*psPtr = NULL;
	this->m_data_bits = pszTempBuf;
	strcpy(pszTempBuf, ++psPtr);
	csPMode = pszTempBuf;

	//
	// Get the stop bits
	//
	nLoc = csPMode.Find(',');
	psPtr = pszTempBuf + nLoc;
	*psPtr = NULL;
	this->m_stop_bits = pszTempBuf;
	strcpy(pszTempBuf, ++psPtr);
	csPMode = pszTempBuf;
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc CString | CSettingsDlg | GetIpAddress |
//
// Returns the TCP/IP Address to be used for ethernet communications.
//
CString CSettingsDlg::GetIpAddress()
{
	return(this->m_ip_address);
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | SetIpAddress |
//
// Sets the TCP/IP Address to be used for ethernet communications.
//
void CSettingsDlg::SetIpAddress(CString csIP)
{
	this->m_ip_address = csIP;
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc UINT | CSettingsDlg | GetPortNumber |
//
// Returns the port number.
//
UINT CSettingsDlg::GetPortNumber()
{
	return(this->m_port_number);
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | SetPortNumber |
//
// Sets the port number.
//
void CSettingsDlg::SetPortNumber(UINT nPortNum)
{
	this->m_port_number = nPortNum;
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc BOOL | CSettingsDlg | GetSendUnsol |
//
// Returns if Unsolicitied Messages will be used.
//
BOOL CSettingsDlg::GetSendUnsol()
{
	return(this->m_send_unsolicited);
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | SetSendUnsol |
//
// Sets if Unsolicitied Messages will be used.
//
void CSettingsDlg::SetSendUnsol(BOOL bUnsol)
{
	this->m_send_unsolicited = bUnsol;
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc UINT | CSettingsDlg | GetLocalStation |
//
// Returns the local station number.
//
UINT CSettingsDlg::GetLocalStation()
{
	return(this->m_local_station);
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | SetLocalStation |
//
// Sets the local station number.
//
void CSettingsDlg::SetLocalStation(UINT nLStation)
{
	this->m_local_station = nLStation;
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc UINT | CSettingsDlg | GetRemoteStation |
//
// Returns the remote station number.
//
UINT CSettingsDlg::GetRemoteStation()
{
	return(this->m_remote_station);
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | SetRemoteStation |
//
// Sets the remote station number.
//
void CSettingsDlg::SetRemoteStation(UINT nRStation)
{
	this->m_remote_station = nRStation;
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc UINT | CSettingsDlg | GetUnsolFrequency |
//
// Returns the frequency in which Unsolicited Messages will be sent out.
//
UINT CSettingsDlg::GetUnsolFrequency()
{
	return(this->m_unsol_frequency);
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | SetUnsolFrequency |
//
// Sets if Unsolicited Messages are to be used.
//
void CSettingsDlg::SetUnsolFrequency(UINT nUnsolFreq)
{
	this->m_unsol_frequency = nUnsolFreq;
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | SetProtocol |
//
// Sets the protocol to be used. Valid choices are TCP/IP or Serial.
//
void CSettingsDlg::SetProtocol(DWORD dwProtocol)
{
	switch (dwProtocol)
	{
	case TCPIP_PROTOCOL:
		m_serial = !(m_tcpip = TRUE);
		m_udpip  = !(m_tcpip = TRUE);
		break;

	case UDPIP_PROTOCOL:
		m_serial = !(m_udpip = TRUE);
		m_tcpip  = !(m_udpip = TRUE);
		break;

	case SERIAL_PROTOCOL:
	default:
		m_tcpip = !(m_serial = TRUE);
		m_udpip = !(m_serial = TRUE);
		break;
	}
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | OnOK |
//
// Default OnOK handler.
// Add any specific code to be executed when the OK button is clicked.
//
void CSettingsDlg::OnOK() 
{
	UpdateData(TRUE);
	
	CDialog::OnOK();
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | OnSourceCheck |
//
// When the user clicks the Source station checkbox
//
void CSettingsDlg::OnSourceCheck() 
{
	UpdateData(TRUE);
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | OnTransactionCheck |
//
// When the user clicks the Transaction Number checkbox
//
void CSettingsDlg::OnTransactionCheck() 
{
	UpdateData(TRUE);
}

void CSettingsDlg::OnUdpipCheckbox() 
{
	// TODO: Add your control notification handler code here
	
	// 
	// The UDP/IP, TXP/IP and Serial options are mutually exclusive.
	// If the user checks one, then uncheck the other.
	//
	m_serial = !(m_udpip = TRUE);
	m_tcpip  = !(m_udpip = TRUE);

	this->EnableProtocolWindows(UDPIP_PROTOCOL);

	UpdateData(FALSE);
}

⌨️ 快捷键说明

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