def setUpClass(cls): devs = getports.GetPorts().get() if not devs: eprint("No serial ports exist.") raise SystemExit("no serial ports exist") sp = serial.Serial() sp.baudrate = 1200 sp.timeout = .5 devs = getports.GetPorts().get() for dev in devs: sp.port = dev if not sp.isOpen(): break Testutils.sdevice = sp.port assert Testutils.sdevice assert not sp.isOpen() sp.open() openresult = sp.isOpen() if sp.isOpen(): sp.close() myserial.MySerial._debugging = True myserial.MySerial._debugreturns = [b'ok\nDTMF>'] myserial.MySerial._dbidx = 0 assert openresult
def request(self, port=None): """request() Request comm port id """ self.inputfn = '' if port: self.comm_port = port # print(f'Using serial port: {self.comm_port)}') return while 1: tups = [] available = getports.GetPorts().get() if available and len(available) > 1: print('Available comport(s) are: {}'.format(available)) tups = [(_.strip(), _.strip().lower()) for _ in available] useri = self._inputa("Comm Port for SmartCat slice?>").strip() elif available: tups = [(_.strip(), _.strip().lower()) for _ in available] useri = tups[0][1] else: print('No available ports') self.close() raise Exception(" no available ports") hits = [t for t in tups if useri.lower() in t] if hits: [_port] = hits self.comm_port = _port[0] print('Using serial port: {}'.format(self.comm_port)) break
def testrequest(self): fakeuser = ['', 'wrongport'] try: ui = userinput.UserInput(dlxii.Device(), testdata=fakeuser) ui.request() self.assertTrue(False, msg="did not fault on empty debug list") except IndexError: pass ports = getports.GetPorts().get() fakeuser += getports.GetPorts().get() + \ ['junk', 'dlx2', 'mytest.txt'] ui = userinput.UserInput(dlxii.Device(), testdata=fakeuser) ui.request() self.assertEqual(ports[0], ui.comm_port) self.assertEqual('mytest.txt', ui.inputfn) self.assertTrue(isinstance(ui.controller_type, dlxii.Device))
def main(): """main() gets the port and repeater type from the command line arguments, reads the time and date from the controller reads the time from the opsys if it is close to a day change (within 10 min) Will delay until after the day change compares them and if more than 60 seconds difference updates the time on the controller """ print(time.asctime(time.localtime(time.time()))) stuff = Stuff(process_cmdline(getports.GetPorts().get())) result = stuff.doit() print(result)
def setUpClass(cls): devs = getports.GetPorts().get() if not devs: eprint("No serial ports exist.") raise SystemExit("no serial ports exist") sp = serial.Serial() sp.baudrate = 9600 sp.timeout = .5 for dev in devs: sp.port = dev if not sp.isOpen(): break TestMySerial.sdevice = sp.port assert TestMySerial.sdevice assert not sp.isOpen() sp.open() openresult = sp.isOpen() if sp.isOpen(): sp.close() assert openresult
def testall(self): print(getports.GetPorts().get())
def testdoit(self): msclass = myserial.MySerial devs: List[str] = getports.GetPorts().get() port = 'COM3' if devs: port = devs[0] else: self.fail('no ports available') msclass._debugging = True msclass._dbidx = 0 # test same date and time msclass._debugreturns = [ b'preread ignored\r', b'\n9600 open default succeed DTMF>', b'DTMF>N029\r', b'\nThis is Wednesday, 01-03-2018\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N027\r', b'\nThe time is 12:23 P.M.\r', b'\nOK\r', b'\nDTMF>', ] ui = userinput.UserInput(ctype=dlxii.Device()) ui.controller_type = dlxii.Device() ui.comm_port = port ui.inputfn = 'updatetest.txt' matchtime = time.strptime("03 Jan 2018 12 23 00", "%d %b %Y %H %M %S") stuff = updatetime.Stuff((ui, False, False)) res = stuff.doit(debug_time=matchtime) self.assertTrue(res[2]) self.assertEqual(14, res[0]) self.assertTrue(14, res[1]) msclass._dbidx = 0 # test same date differnt time msclass._debugreturns = [ b'preread ignored\r', b'\n9600 open default succeed DTMF>', b'DTMF>N029\r', b'\nThis is Wednesday, 01-03-2018\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N027\r', b'\nThe time is 12:23 P.M.\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N02507071\r', b'\nTime set to 12:02 P.M.\r', b'\nOK\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N029\r', b'\nThis is Wednesday, 01-03-2018\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N027\r', b'\nThe time is 12:02 P.M.\r', b'\nOK\r', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', ] matchtime = time.strptime("03 Jan 2018 12 02 00", "%d %b %Y %H %M %S") res = stuff.doit(debug_time=matchtime) self.assertTrue(res[1]) self.assertEqual(13, res[0]) self.assertFalse(res[2]) msclass._dbidx = 0 # test differnt time and different date msclass._debugreturns = [ b'preread ignored\r', b'\n9600 open default succeed DTMF>', b'DTMF>N029\r', b'\nThis is Tuesday, 01-02-2018\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N0280103184\r', b'\nThis is Wednesday, 01-03-2018\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N029\r', b'\nThis is Wednesday, 01-03-2018\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N027\r', b'\nThe time is 12:23 P.M.\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N02507071\r', b'\nTime set to 12:02 P.M.\r', b'\nOK\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N029\r', b'\nThis is Wednesday, 01-03-2018\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N027\r', b'\nThe time is 12:02 P.M.\r', b'\nOK\r', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', ] matchtime = time.strptime("03 Jan 2018 12 02 00", "%d %b %Y %H %M %S") res = stuff.doit(debug_time=matchtime) self.assertTrue(res[1]) self.assertEqual(12, res[0]) self.assertFalse(res[2]) # still need to test the debug option in the affected code to make sure the time change is not sent to the controler msclass._debugging = False