コード例 #1
0
	def OnOk( self, event ):
		""" Clicked on OK """
		twr_ser = self.cbTwrSerPort.GetValue().encode('ASCII')
		
		
		if twr_ser == "":
			wx.MessageBox("Please enter an valid serial port name for \
			communicating with the tower ")
			self.set_invalid()
			return 
		else:
			try:
				ser = SerialPort(twr_ser)
				ser.write_to_port('X0')  # Write some known command for a check
				read_info = ser.read_from_twr()
				if read_info[1] == False:
					dlg = wx.MessageDialog(self, "The Tower did not respond with expected response."+ \
					" Please make sure that you have selected appropriate port."+ \
					"\n\n Do you want to retry with a different serial port ?", \
					"Warning",
					wx.YES_NO)
					
					resp = dlg.ShowModal()
					dlg.Destroy()
					if resp == wx.ID_YES:
						ser.close_port()
						self.set_invalid()
						return 
				else:
					self.config.set_twr_ser_port(twr_ser)	
					ser.close_port()
			except IOError:
				wx.MessageBox("Could not open com port %s ", twr_ser)
				self.set_invalid()
				return  
				
			dmm_ser = self.cbDmmSerPort.GetValue().encode('ASCII')
			
			if dmm_ser == "":
				wx.MessageBox("Please enter an valid serial port name for \
			communicating with the DMM ")
				self.set_invalid()
				return
			else:
				try:
					ser = SerialPort(dmm_ser, '9600', '2')
					read_info = ser.read_from_dmm()
				
						
					if read_info[1] == False :
						dlg = wx.MessageDialog(self, "The dmm did not respond with expected response."+ \
						" Please make sure that you have selected appropriate port."+ \
						" And that the DMM has been set up properly " + \
						"\n\n Do you want to retry with a different serial port ?", \
						"Warning",
						wx.YES_NO)
					
						resp = dlg.ShowModal()
						dlg.Destroy()
						if resp == wx.ID_YES:
							ser.close_port()
							self.set_invalid()
							return 
					else:
						self.config.set_dmm_ser_port(dmm_ser)
						ser.close_port()	
				except IOError:
					wx.MessageBox("Could not open com port %s ", twr_ser)
					self.set_invalid()
					return  
				
					 
		if dmm_ser == twr_ser:
			# can't use same port for both DMM and Tower	
			wx.MessageBox("Cannot use same port for communicating with both \n"+
			"Tower and DMM ")
			self.set_invalid()
			return  
				
		# Let us validate the exstince of the command file
		
		if os.path.exists(self.config.get_cmd_file()) == False:
			wx.MessageBox("Please enter a valid path for command file ")
			self.set_invalid()
			return 
			
		if os.path.exists(self.config.get_log_file()) == False:
			wx.MessageBox("Please enter a valid path for log file ")
			self.set_invalid()
			return
					
		# if we have made it to this point, most of the things are valid
		# except for the serial ports which are dependent on user choice(s)
		
		self.set_valid()	
		self.Close()