// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + // + FileName: Status.cpp Author: S.Hammond // + // + Version: 1 Date: 23/June/1999 // + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + // + This file contains the code to control the instrument status // + dialog box. // + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #include "stdafx.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define _STATUS_C_ #include "CalPoll.h" #include "Comms.h" #include "CalPollDlg.h" #include "Status.h" #include "ModBus.h" #include "ModBus.h" // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + CStatus dialog // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ CStatus::CStatus(CWnd* pParent /*=NULL*/) : CDialog(CStatus::IDD, pParent) { iSlave=-1; //{{AFX_DATA_INIT(CStatus) //}}AFX_DATA_INIT } void CStatus::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CStatus) DDX_Control(pDX, IDC_SET, m_Set); DDX_Control(pDX, IDC_SP, m_sp); DDX_Control(pDX, IDC_TEMP, m_Temp); DDX_Control(pDX, IDC_SP1, m_sp1); DDX_Control(pDX, IDC_SP2, m_sp2); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CStatus, CDialog) //{{AFX_MSG_MAP(CStatus) ON_WM_TIMER() ON_BN_CLICKED(IDC_SET, OnSet) ON_EN_CHANGE(IDC_SP, OnChangeSp) //}}AFX_MSG_MAP END_MESSAGE_MAP() // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Reset the status dialog for first use // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ BOOL CStatus::OnInitDialog() { char TempString[256]; WORD Temp; CDialog::OnInitDialog(); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Check we have been told which slave to monitor // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if ( iSlave==-1 ) { EndDialog(0); } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Reset dialog elements // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ m_Temp.SetWindowText("----"); m_sp1.SetCheck(0); m_sp2.SetCheck(0); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Display initial values // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ModBus.ModReadSingle((BYTE)iSlave,MODBUS_CAL_SP1); if ( ModBus.ValidResponse() ) { Temp=ModBus.GetWord(3); sprintf(TempString,"%.1f",((float)Temp)/10); m_sp.SetWindowText(TempString); } SetDisplay(); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Start a timer to update the display // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Timer=SetTimer(1,MODBUS_CAL_POLL,NULL); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Move the focus to remove the cursor from the edit field(s) // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ m_Set.SetFocus(); return(FALSE); } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Save the slave address for this dialog to monitor // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void CStatus::SetSlave(int Slave) { iSlave=Slave; } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Fetch information from the instrument and display it // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void CStatus::SetDisplay(void) { char TempString[256]; WORD Temp; BYTE Display; // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Fetch the current temperature // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ModBus.ModReadSingle((BYTE)iSlave,MODBUS_CAL_TEMP); if ( ModBus.ValidResponse() ) { Temp=ModBus.GetWord(3); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Fetch the display byte for the current LED states // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ModBus.ModReadSingle((BYTE)iSlave,MODBUS_CAL_DISPLAY); if ( ModBus.ValidResponse() ) { Display=ModBus.GetByte(4); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Change the dialog elements to match the new data // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sprintf(TempString,"%.1f",((float)Temp)/10); m_Temp.SetWindowText(TempString); m_sp1.SetCheck( (Display&0x40)>>6 ); m_sp2.SetCheck( (Display&0x80)>>7 ); } } } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + The routine which is run when the timer expires // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void CStatus::OnTimer(UINT nIDEvent) { // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Update the display information // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ SetDisplay(); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Note that the timer will continue to work until it is 'killed' // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ CDialog::OnTimer(nIDEvent); } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Free up the timer in use // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ BOOL CStatus::DestroyWindow() { KillTimer(Timer); return CDialog::DestroyWindow(); } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Send a new set point to the instrument // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void CStatus::OnSet() { char TempString[256]; double sp; WORD wsp; // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Fetch the desired setpoint value from the dialog // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ m_sp.GetWindowText(TempString,256); sp=atof(TempString); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Check the value is valid // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if ( sp<0 || sp>9990 ) { AfxMessageBox("Invalid Set Point Value"); return; } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Scale the value for the instrument // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ wsp=(WORD)(sp*10); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Enter program mode // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if ( ModBus.ModEnterProgram((BYTE)iSlave) ) { // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Send the new set point // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ModBus.ModWriteSingle((BYTE)iSlave,MODBUS_CAL_SP1,wsp); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Exit program mode even if the set point was not set correctly // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ModBus.ModExitProgram((BYTE)iSlave); } } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Handle change messages to the edit control for the set point // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void CStatus::OnChangeSp() { int iLen; int f; char TempString[256]; // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Fetch the current contents of the edit control // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ m_sp.GetWindowText(TempString,256); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Loop for all characters in the string // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ iLen=strlen(TempString); for (f=0;f'9' ) { // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + or a decimal place ? // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if ( TempString[f]!='.' ) { // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Disable set button while edit control has invalid // + characters // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ m_Set.EnableWindow(FALSE); return; } } } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // + Enable set button // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ m_Set.EnableWindow(TRUE); }