def on_ReadReadButton(self,event): global GlobalSerialPort NotRead = True for i in range(0,2): if NotRead: try: InfoDict = CapReadAll(GlobalSerialPort) self.ReadFacilityTextCtrl.SetValue(InfoDict['Facility'].strip()) self.ReadDrTextCtrl.SetValue(InfoDict['Doctor'].strip()) self.ReadMedTextCtrl.SetValue(InfoDict['Treatment'].strip()) self.ReadDoseTextCtrl.SetValue(DosePatterns.get(InfoDict['DosePattern'].strip(), 'Unrecognized')) self.ReadDoseCount.SetValue(InfoDict['DoseCount'].strip()) self.ReadClientTextCtrl.SetValue(InfoDict['Client'].strip()) self.ReadPatientTextCtrl.SetValue(InfoDict['Patient'].strip()) self.TimePointsText.Clear() self.TimePoints = CapDataRead(GlobalSerialPort) for Points in self.TimePoints: DataSubList = ComSubs.RxdStrParse(Points) if int(DataSubList[0]) == 0 and int(DataSubList[1]) == 0 and int(DataSubList[2]) == 0 and int(DataSubList[3]) == 0: self.TimePointsText.AppendText('Missed Dose\r') else: self.TimePointsText.AppendText('{} {} {} {}\r'.format(DataSubList[3], DataSubList[2], DataSubList[1], DataSubList[0])) self.ReadStartTimeTextCtrl.SetValue(CapTimeRead(GlobalSerialPort, 'H\r')) self.ReadSaveButton.Enable() NotRead = False # success don't try again except: if(i==1): dlg = wx.MessageDialog(None, 'Read Error:\nCheck cap alignment.\nPress cap.\nCheck battery.\nCap may be blank.', 'Error', wx.OK) DialogReturn = dlg.ShowModal()
def CapPing(SPort): COMPort = serial.Serial(SPort, CAP_BAUD_RATE, timeout=DEFAULT_SERIAL_TIMEOUT) COMPort.write('T\r') # ResponseString = COMPort.readline() ResponseList = ComSubs.RxdStrParse(COMPort.readline()) COMPort.close() return ResponseList
def CapDataRead(SPort): ReturnStringList = [] COMPort = serial.Serial(SPort, CAP_BAUD_RATE, timeout=DEFAULT_SERIAL_TIMEOUT) COMPort.write('T\r') COMPort.readline() COMPort.write('D\r') ResponseList = ComSubs.RxdStrParse(COMPort.readline()) for i in range(0, int(ResponseList[1])): ReturnStringList.append(COMPort.readline()) COMPort.close() return ReturnStringList
def CapReadAll(SPort): ReturnDict = {} COMPort = serial.Serial(SPort, CAP_BAUD_RATE, timeout=DEFAULT_SERIAL_TIMEOUT) COMPort.write('T\r') COMPort.readline() for Description, Command in Commands.iteritems(): COMPort.write('G') COMPort.write(Command) COMPort.write('\r') ResponseList = ComSubs.RxdStrParse(COMPort.readline()) #print ResponseList ReturnDict[Description] = ResponseList[2] COMPort.close() return ReturnDict
def FindBaseStation(): # scan for open com ports # if no port return Fail # starting with port from INI file if present and open # send 'z\r\n' to port # wait for response # if not found, next port # if found then return OK # if tried all ports return Fail # Error messages begin with 'No', for checking later ReturnList = [] ResponseString = '' PortList = ComSubs.PortScan() if not len(PortList): PortName = 'No Com Ports Found' else: # search through open ports, will return last one that responds PortName = 'No Base Stations Found.\nCheck cables.\nBe sure FTDI230X driver is installed.\nRemove from bright lights.\nInserting a cap may help.' for Port in PortList: try: COMPort = serial.Serial(Port, CAP_BAUD_RATE, timeout=DEFAULT_SERIAL_TIMEOUT) COMPort.write('T') sleep(0.05) COMPort.write('\r') COMPort.readline() COMPort.write('Z') sleep(0.05) COMPort.write('\r') ResponseString = COMPort.readline() COMPort.close() if ResponseString.find('Base') > 0: PortName = Port finally: pass ReturnList.append(PortName) ReturnList.append(ResponseString) return ReturnList