// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + // + FileName: Comms.cpp Author: S.Hammond // + // + Version: 1 Date: 23/June/1999 // + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + // + This file controls the communications selection dialog // + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #include "stdafx.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define _COMMS_C_ #include "CalPoll.h" #include "Comms.h" // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + CComms dialog // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ CComms::CComms(CWnd* pParent /*=NULL*/) : CDialog(CComms::IDD, pParent) { //{{AFX_DATA_INIT(CComms) //}}AFX_DATA_INIT } void CComms::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CComms) DDX_Control(pDX, IDC_PARITY, m_Parity); DDX_Control(pDX, IDC_COMMS_DEVICE, m_Device); DDX_Control(pDX, IDC_CALICON, m_Icon); DDX_Control(pDX, IDC_BAUD_RATE, m_Baud); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CComms, CDialog) //{{AFX_MSG_MAP(CComms) //}}AFX_MSG_MAP END_MESSAGE_MAP() // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Setup the dialog ready for use // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ BOOL CComms::OnInitDialog() { CDialog::OnInitDialog(); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Fill the drop down lists with the selections // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ m_Device.SetWindowText("COM1"); m_Device.AddString("COM1"); m_Device.AddString("COM2"); m_Device.AddString("COM3"); m_Device.AddString("COM4"); m_Device.AddString("COM5"); m_Device.AddString("COM6"); m_Device.AddString("COM7"); m_Device.AddString("COM8"); m_Device.AddString("COM9"); m_Baud.SetWindowText("9600"); m_Baud.AddString("1200"); m_Baud.AddString("2400"); m_Baud.AddString("4800"); m_Baud.AddString("9600"); m_Baud.AddString("19200"); m_Parity.SetWindowText("None"); m_Parity.AddString("None"); m_Parity.AddString("Even"); m_Parity.AddString("Odd"); return(TRUE); } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Save the setup values from the dialog into the local setup store // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void CComms::OnOK() { char TempString[256]; // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Fetch device name from dialog // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ m_Device.GetWindowText(TempString,256); if ( m_Device.FindString(-1,TempString)==LB_ERR ) { AfxMessageBox("Invalid Communications Device Selected"); return; } strcpy(LocalSetup.Device,TempString); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Fetch baud rate from dialog // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ m_Baud.GetWindowText(TempString,256); if ( m_Baud.FindString(-1,TempString)==LB_ERR ) { AfxMessageBox("Invalid Baud Rate Selected"); return; } LocalSetup.Baud=(WORD)atoi(TempString); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Fetch parity from dialog // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ m_Parity.GetWindowText(TempString,256); if ( m_Parity.FindString(-1,TempString)==LB_ERR ) { AfxMessageBox("Invalid Parity Selected"); return; } switch ( TempString[0] ) { case 'N': LocalSetup.Parity=_PARITY_NONE; break; case 'E': LocalSetup.Parity=_PARITY_EVEN; break; case 'O': LocalSetup.Parity=_PARITY_ODD; break; } CDialog::OnOK(); } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Get a copy of the communications setup entered in the dialog // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void CComms::GetCommsSetup(COMMSSETUP *pSetup) { // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Copy the communications setup back to the caller // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ memcpy(pSetup,&LocalSetup,sizeof(COMMSSETUP)); }