/***************************************************************** OnInitDialog VISUAL C++ FUNCTION CALL *****************************************************************/ BOOL CComPortSettings::OnInitDialog() { char cCOMPort[10]; int nCOMPort, nBaudRate, nStopBits, nParity, nDataBits; CDialog::OnInitDialog(); ReadINIParm( "Communication", "Baud Rate", "0", &nBaudRate ); ReadINIParm( "Communication", "Stop Bits", "0", &nStopBits ); ReadINIParm( "Communication", "Parity", "0", &nParity ); ReadINIParm( "Communication", "Data Bits", "0", &nDataBits ); ReadINIParm( "Communication", "Hardware", "0", &m_bHardware ); ReadINIParm( "Communication", "COM Port", "0", &nCOMPort ); ReadINIParm( "Communication", "Reset Hardware", "0", &m_bReset ); ReadINIParm( "Communication", "Wireless", "0", &m_bWireless ); for ( int i = 1; i < 20; i++ ) { sprintf( cCOMPort, "COM%d", i ); m_ctlCOMPorts.AddString( cCOMPort ); } /* for */ m_ctlCOMPorts.SetCurSel( nCOMPort ); m_ctlBaudRate.AddString( "9600" ); m_ctlBaudRate.AddString( "14400" ); m_ctlBaudRate.AddString( "19200" ); m_ctlBaudRate.AddString( "38400" ); m_ctlBaudRate.AddString( "57600" ); m_ctlBaudRate.AddString( "115200" ); m_ctlBaudRate.AddString( "921600" ); m_ctlBaudRate.AddString( "1228739" ); m_ctlBaudRate.SetCurSel( nBaudRate ); m_ctlParity.AddString( "None" ); m_ctlParity.AddString( "Odd" ); m_ctlParity.AddString( "Even" ); m_ctlParity.SetCurSel( nParity ); m_ctlStopBits.AddString( "1 bit" ); m_ctlStopBits.AddString( "2 bits" ); m_ctlStopBits.SetCurSel( nStopBits ); m_ctlDataBits.AddString( "8 bits" ); m_ctlDataBits.AddString( "7 bits" ); m_ctlDataBits.SetCurSel( nDataBits ); UpdateData( false ); OnWireless(); return TRUE; } /* OnInitDialog */
/* Description: This function implement the virtual fucntion in TrackerBase class You should just call this single function to finished the whole initialization process. Return Value: 0: success other: fail */ int PloarisVicraConfiguration::ConfigureTracker() { int nBaudRate = 0, nStopBits = 0, nParity = 0, nDataBits = 0, nHardware = 0, nWireless = 0, m_nCOMPort; bool m_bWireless, m_bResetHardware; /* * read the COM port parameters from the ini file */ ReadINIParm("Communication", "Baud Rate", "0", &nBaudRate); ReadINIParm("Communication", "Stop Bits", "0", &nStopBits); ReadINIParm("Communication", "Parity", "0", &nParity); ReadINIParm("Communication", "Data Bits", "0", &nDataBits); ReadINIParm("Communication", "Hardware", "0", &nHardware); ReadINIParm("Communication", "COM Port", "0", &m_nCOMPort); ReadINIParm("Communication", "Wireless", "0", &m_bWireless); // this feature is useful for debugging only ReadINIParm("Communication", "Reset Hardware", "0", &m_bResetHardware); //close the port first and then open this->nCloseComPorts(); if (!this->nOpenComPort(m_nCOMPort)) { //cannot open port, post a message here std::cout << " COMM Port cannot Open" << std::endl; return 1; } //if you are supposed to reset, call the reset now if (m_bResetHardware) { if (!this->nHardWareReset(m_bWireless)) return 1; } /* * get the timeout values for the commands * this will return an error with all other systems, other than Vicra */ this->CreateTimeoutTable(); /* * set the System COM Port parameters, then the computers COM Port parameters. * if that is successful, initialize the system */ if (this->nSetSystemComParms(nBaudRate, nDataBits, nParity, nStopBits, nHardware)) { if (this->nSetCompCommParms(nBaudRate, nDataBits, nParity, nStopBits, nHardware)) { if (this->nInitializeSystem()) { /* * get the system information */ if (!this->nGetSystemInfo()) { /* * Check system type: Polaris, Polaris Accedo, and Aurora */ std::cout << "Cannot get device information " << std::endl; return 1; } /* Post a message here to indicate system type */ std::cout << "System Type is: "; switch (this->m_dtSystemInformation.nTypeofSystem) { case POLARIS_SYSTEM: { m_szTypeOfSystem = "Polaris system"; std::cout << "Polaris system" << std::endl; break; } case AURORA_SYSTEM: { m_szTypeOfSystem = "Aurora system"; std::cout << "Aurora system" << std::endl; break; } case ACCEDO_SYSTEM: { m_szTypeOfSystem = "Accedo system"; std::cout << "Accedo system" << std::endl; break; } case VICRA_SYSTEM: { m_szTypeOfSystem = "Polaris Vicra system"; std::cout << "Polaris Vicra system" << std::endl; break; } case SPECTRA_SYSTEM: { m_szTypeOfSystem = "Spectra system"; std::cout << "Spectra system" << std::endl; break; } default: { m_szTypeOfSystem = "Unknown system"; std::cout << "Unknown system" << std::endl; break; } } /* Tracking device version information */ m_szVersionInfo = m_dtSystemInformation.szVersionInfo; std::cout << "Device Version Info:\t"<<m_szVersionInfo << std::endl; /* Post message of system informations */ m_szSerialNo = m_dtHandleInformation[1].szSerialNo; m_szToolRev = m_dtHandleInformation[1].szRev; m_szToolType = m_dtHandleInformation[1].szToolType; m_szPartNumber = m_dtHandleInformation[1].szPartNumber; m_szManufID = m_dtHandleInformation[1].szManufact; /* * Set firing rate if system type is Polaris or Polaris Accedo. */ if (this->m_dtSystemInformation.nTypeofSystem != AURORA_SYSTEM) { this->nSetFiringRate(); } m_szSystemMode = "System Initialized"; SetMode(MODE_INIT); m_bSystemInitialized = TRUE; //show a message that the system has been initilized std::cout << "initialization success" << std::endl; // ======== activate all rom files ========== // if (nActivatePorts() == 1) // fail { std::cout << "Cannot activated tool model" << std::endl; std::cout << "Initilization process cannot finisheed" << std::endl; return 1; } return 0; } else { //Post message here std::cout << "Cannot initialized" << std::endl; return 1; } } else { std::cout << "Cannot Set COM parameters" << std::endl; return 1; } } else { std::cout << "Cannot set system comm parameters\nMaybe low temperature, Just wait a minute" << std::endl; return 1; } }