//Esempio di utilizzo della classe di CBseModBus //www.germinara.it //info@germinara.it ////////////////////////////////////////////////////////// //HEADER---- .h ... ... #include "CBseModBus.h" // CSessForniDlg dialog class CDialogTestDlg : public CDialog { .... ... CBseModBus bseModBus;//ModBus Library CString m_EroMsgErr; //Descrizione eventuale messaggio di errore int stsOK; //STATO void DoCommand(); }; //IMPLEMENTAZIONE---- .cpp //Controllo se devo processare un comando void CDialogTestDlg::DoCommand(){ int stsEro=0; //nota: m_siCommEro è il componente activex della //Software InnoVations Inc. che si occupa della comunicazione seriale //---- www.sinnovations.com --- //Imposto il modo remoto stsEro=bseModBus.EE_SetRemote(&m_siCommEro,addr); m_EroMsgErr=bseModBus.DecodeError(sts); if(!m_EroMsgErr.IsEmpty()){ msgLog="CDialogTestDlg::DoCommand:"+m_EroMsgErr; stsOK=FALSE; } //IMPOSTO IL SETPOINT stsEro=bseModBus.EE_SetSetPoint(&m_siCommEro,addr,atof(setSetPoint)); m_EroMsgErr=bseModBus.DecodeError(sts); if(!m_EroMsgErr.IsEmpty()){ msgLog="CDialogTestDlg::DoCommand:"+m_EroMsgErr; stsOK=FALSE; } //LO RILEGGO ... stsEro=bseModBus.EE_GetSetPoint(&m_siCommEro,addr,&valSP); m_EroMsgErr=bseModBus.DecodeError(sts); if(!m_EroMsgErr.IsEmpty()){ msgLog="CDialogTestDlg::DoCommand:"+m_EroMsgErr; stsOK=FALSE; } if(m_EroMsgErr.IsEmpty()) getSetPoint.Format("%4d",(int)valSP); else getSetPoint="0"; //Leggo la Temperatura stsEro=bseModBus.EE_GetTemperature(&m_siCommEro,addr,&valTEMP); m_EroMsgErr=bseModBus.DecodeError(sts); if(!m_EroMsgErr.IsEmpty()){ msgLog="CDialogTestDlg::DoCommand:"+m_EroMsgErr; getCurrTemp=""; }else getCurrTemp.Format("%4d",(int)valTEMP); //Log di tutti i dati SetPoint Impostato, Letto, Temperatura e Stato m_strOper.Format("CF Addr:[%0x] SPImp: [%s] SPLet: [%s] TLet:[%s] StsOK: [%d]",addr,setSetPoint,getSetPoint,getCurrTemp,stsOK); msgLog="DoCommand:"+m_strOper; }else stsOK=FALSE; } //Fine...