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

📄 settingsdlg.cpp

📁 工业强度的PLC模拟程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// @dlg
//
// @module		SettingsDlg.cpp
//
//
// Maintenance:
//	
// Version		Date		Who		What
// -------		--------	---		-------------------------------------
// 7.0			06/01/97	jra		Created
// 7.1			04/30/98	mvs		Added TCP/IP Support
// 7.1			05/20/98	mvs		Added UDP Support
//

// SettingsDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ItkPlc.h"
#include "SettingsDlg.h"
#include "itkprotocol.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSettingsDlg dialog


CSettingsDlg::CSettingsDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSettingsDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSettingsDlg)
	m_serial = TRUE;
	m_tcpip = FALSE;
	m_ip_address = _T("");
	m_port_number = 0;
	m_send_unsolicited = FALSE;
	m_local_station = 1;
	m_remote_station = 2;
	m_unsol_frequency = 1000;
	m_port_name = _T("COM1");
	m_baud_rate = _T("9600");
	m_data_bits = _T("8");
	m_parity = _T("None");
	m_stop_bits = _T("1");
	m_source_station = FALSE;
	m_transaction_num = FALSE;
	m_udpip = FALSE;
	//}}AFX_DATA_INIT
}


void CSettingsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSettingsDlg)
	DDX_Control(pDX, IDC_SOURCE_CHECK, m_SourceStation);
	DDX_Control(pDX, IDC_TRANSACTION_CHECK, m_TransactionNum);
	DDX_Control(pDX, IDC_UNSOLICITED_CHECK, m_SendUnsol);
	DDX_Control(pDX, IDC_REMOTE_STATION, m_RemoteStation);
	DDX_Control(pDX, IDC_PORT_NUMBER, m_PortNumber);
	DDX_Control(pDX, IDC_PORT_NAME, m_PortName);
	DDX_Control(pDX, IDC_UNSOL_FREQ, m_UnsolFreq);
	DDX_Control(pDX, IDC_STOP_BITS, m_StopBits);
	DDX_Control(pDX, IDC_PARITY, m_Parity);
	DDX_Control(pDX, IDC_IP_ADDRESS, m_IPAddress);
	DDX_Control(pDX, IDC_DATA_BITS, m_DataBits);
	DDX_Control(pDX, IDC_BAUD_RATE, m_BaudRate);
	DDX_Check(pDX, IDC_SERIAL_CHECKBOX, m_serial);
	DDX_Check(pDX, IDC_TCPIP_CHECKBOX, m_tcpip);
	DDX_Text(pDX, IDC_IP_ADDRESS, m_ip_address);
	DDX_Text(pDX, IDC_PORT_NUMBER, m_port_number);
	DDX_Check(pDX, IDC_UNSOLICITED_CHECK, m_send_unsolicited);
	DDX_Text(pDX, IDC_LOCAL_STATION, m_local_station);
	DDV_MinMaxUInt(pDX, m_local_station, 0, 255);
	DDX_Text(pDX, IDC_REMOTE_STATION, m_remote_station);
	DDV_MinMaxUInt(pDX, m_remote_station, 0, 255);
	DDX_Text(pDX, IDC_UNSOL_FREQ, m_unsol_frequency);
	DDV_MinMaxUInt(pDX, m_unsol_frequency, 10, 100000);
	DDX_CBString(pDX, IDC_PORT_NAME, m_port_name);
	DDX_CBString(pDX, IDC_BAUD_RATE, m_baud_rate);
	DDX_CBString(pDX, IDC_DATA_BITS, m_data_bits);
	DDX_CBString(pDX, IDC_PARITY, m_parity);
	DDX_CBString(pDX, IDC_STOP_BITS, m_stop_bits);
	DDX_Check(pDX, IDC_SOURCE_CHECK, m_source_station);
	DDX_Check(pDX, IDC_TRANSACTION_CHECK, m_transaction_num);
	DDX_Check(pDX, IDC_UDPIP_CHECKBOX, m_udpip);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSettingsDlg, CDialog)
	//{{AFX_MSG_MAP(CSettingsDlg)
	ON_BN_CLICKED(IDC_SERIAL_CHECKBOX, OnSerialCheckbox)
	ON_BN_CLICKED(IDC_TCPIP_CHECKBOX, OnTcpipCheckbox)
	ON_EN_CHANGE(IDC_IP_ADDRESS, OnChangeIpAddress)
	ON_EN_CHANGE(IDC_PORT_NUMBER, OnChangePortNumber)
	ON_BN_CLICKED(IDC_UNSOLICITED_CHECK, OnUnsolicitedCheck)
	ON_BN_CLICKED(IDC_SOURCE_CHECK, OnSourceCheck)
	ON_BN_CLICKED(IDC_TRANSACTION_CHECK, OnTransactionCheck)
	ON_BN_CLICKED(IDC_UDPIP_CHECKBOX, OnUdpipCheckbox)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()



//----(Member Function)-------------------------------------------------------
//
// @mfunc BOOL | CSettingsDlg | OnInitDialog |
//
// Default Dialog initialization handler.
// Add any specific code here that will be used to initialize the dialog
// box members with data. Return TRUE unless you set the focus to a control!!
//
BOOL CSettingsDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	m_unsol_frequency = 1000;

	//
	// Enable and disable the appropriate windows, dependant on the protocol
	//
	if (this->m_serial)
	{
		// It's serial
		this->EnableProtocolWindows(SERIAL_PROTOCOL);
	}
	else if (this->m_udpip)
	{
		// It's UDP/IP
		this->EnableProtocolWindows(UDPIP_PROTOCOL);
	}
	else
	{	
		// It's TCP/IP
		this->EnableProtocolWindows(TCPIP_PROTOCOL);
	}

	//
	// Disable the Unsolicied Frequency Edit and the Remote Station Edit
	// if not using unsolicited messages.
	//
	if (!m_send_unsolicited)
	{
		m_UnsolFreq.EnableWindow(FALSE);
		m_RemoteStation.EnableWindow(FALSE);
	}

	UpdateData(FALSE);

	return(TRUE);
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | OnSerialCheckbox |
//
// Checks the Serial check box and unchecks the TCP/IP check box.
// Add any specific code here to be executed when the user checks the
// text in the Serial check box.
//
void CSettingsDlg::OnSerialCheckbox() 
{
	UpdateData(TRUE);

	
	// 
	// The TCP/IP and Serial options are mutually exclusive.
	// If the user checks one, then uncheck the other.
	//
	m_tcpip = !(m_serial = TRUE);
	m_udpip = !(m_serial = TRUE);

	this->EnableProtocolWindows(SERIAL_PROTOCOL);

	UpdateData(FALSE);
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | CTriggerDlg |
//
// Checks the TCP/IP check box and unchecks the Serial check box.
// Add any specific code here to be executed when the user checks the
// text in the TCP/IP check box.
//
void CSettingsDlg::OnTcpipCheckbox() 
{
	UpdateData(TRUE);

	// 
	// The TCP/IP and Serial options are mutually exclusive.
	// If the user checks one, then uncheck the other.
	//
	m_serial = !(m_tcpip = TRUE);
	m_udpip  = !(m_tcpip = TRUE);

	this->EnableProtocolWindows(TCPIP_PROTOCOL);

	UpdateData(FALSE);
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | EnableProtocolWindows |
//
// Dependant on what protocol is being used, this function disables windows
// that are not relevant and enables needed windows.
//
void CSettingsDlg::EnableProtocolWindows(DWORD dwProtocol)
{
	switch (dwProtocol)
	{
	case TCPIP_PROTOCOL:
		//
		// Using TCP/IP, so gray out all Serial options...
		//
		this->m_BaudRate.EnableWindow(FALSE);
		this->m_Parity.EnableWindow(FALSE);
		this->m_DataBits.EnableWindow(FALSE);
		this->m_StopBits.EnableWindow(FALSE);
		this->m_PortName.EnableWindow(FALSE);
		//
		// Using TCP/IP, disable unsolicited messages
		//
		m_send_unsolicited = FALSE;
		m_transaction_num = TRUE;
		m_source_station = FALSE;

		m_UnsolFreq.EnableWindow(FALSE);
		m_RemoteStation.EnableWindow(FALSE);
		m_SendUnsol.EnableWindow(FALSE);
		m_TransactionNum.EnableWindow(FALSE);
		m_SourceStation.EnableWindow(FALSE);

		//
		// ...And enable all TCP/IP options
		//
		this->m_PortNumber.EnableWindow(TRUE);
		this->m_IPAddress.EnableWindow(TRUE);
		break;

	case UDPIP_PROTOCOL:
		//
		// Using UDP/IP, so gray out all Serial options...
		//
		this->m_BaudRate.EnableWindow(FALSE);
		this->m_Parity.EnableWindow(FALSE);
		this->m_DataBits.EnableWindow(FALSE);
		this->m_StopBits.EnableWindow(FALSE);
		this->m_PortName.EnableWindow(FALSE);
		//
		// Using UDP/IP, disable unsolicited messages
		//
		m_send_unsolicited = FALSE;
		m_transaction_num = TRUE;
		m_source_station = FALSE;

		m_UnsolFreq.EnableWindow(FALSE);
		m_RemoteStation.EnableWindow(FALSE);
		m_SendUnsol.EnableWindow(FALSE);
		m_TransactionNum.EnableWindow(FALSE);
		m_SourceStation.EnableWindow(FALSE);

		//
		// ...And enable all TCP/UDP options
		//
		this->m_PortNumber.EnableWindow(TRUE);
		this->m_IPAddress.EnableWindow(TRUE);
		break;

	case SERIAL_PROTOCOL:
	default:
		//
		// Using serial, so gray out all TCP/UDP options...
		//
		this->m_PortNumber.EnableWindow(FALSE);
		this->m_IPAddress.EnableWindow(FALSE);

		//
		// ...And enable all Serial options
		//
		this->m_BaudRate.EnableWindow(TRUE);
		this->m_Parity.EnableWindow(TRUE);
		this->m_DataBits.EnableWindow(TRUE);
		this->m_StopBits.EnableWindow(TRUE);
		this->m_PortName.EnableWindow(TRUE);

		m_transaction_num = FALSE;
		m_send_unsolicited = FALSE;
		m_source_station = FALSE;

		m_UnsolFreq.EnableWindow(TRUE);
		m_RemoteStation.EnableWindow(TRUE);
		m_SendUnsol.EnableWindow(TRUE);
		m_TransactionNum.EnableWindow(TRUE);
		m_SourceStation.EnableWindow(TRUE);

		break;
	}
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | OnChangeIpAddress |
//
// Updates the TCP/IP Address text box.
// Add any specific code here to be executed when the user changes the
// text in the TCP/IP Address text box.
//
void CSettingsDlg::OnChangeIpAddress() 
{
	UpdateData(TRUE);
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | OnChangePortNumber |
//
// Updates the Port Number text box.
// Add any specific code here to be executed when the user changes the
// text in the Port Number text box.
//
void CSettingsDlg::OnChangePortNumber() 
{
	UpdateData(TRUE);
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc void | CSettingsDlg | OnUnsolicitedCheck |
//
// Updates the Unsolicited Message check box.
// Add any specific code here to be executed when the user checks or unchecks
// the Unsolicited Message check box.
//
void CSettingsDlg::OnUnsolicitedCheck() 
{
	UpdateData(TRUE);

	if (m_send_unsolicited)
	{
		m_UnsolFreq.EnableWindow(TRUE);
		m_RemoteStation.EnableWindow(TRUE);
	}
	else
	{
		m_UnsolFreq.EnableWindow(FALSE);
		m_RemoteStation.EnableWindow(FALSE);
	}
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc DWORD | CSettingsDlg | IsSerial |
//
// Returns TRUE is the port is Serial. False if it is TCP/IP.
//
DWORD CSettingsDlg::IsSerial()
{
	return(this->m_serial);
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc DWORD | CSettingsDlg | IsTcpIp |
//
// Returns TRUE is the port is TCP/IP. False if it is Serial.
//
DWORD CSettingsDlg::IsTcpIp()
{
	return(this->m_udpip);
}



//----(Member Function)-------------------------------------------------------
//
// @mfunc DWORD | CSettingsDlg | IsUdpIp |
//
// Returns TRUE is the port is UDP/IP. False if it is Serial.
//
DWORD CSettingsDlg::IsUdpIp()
{
	return(this->m_udpip);
}


//----(Member Function)-------------------------------------------------------
//
// @mfunc CString | CSettingsDlg | GetPortName |
//

⌨️ 快捷键说明

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