Esempio n. 1
0
def contextGen():
    tree = writeMusicObj.tree
    names = writeMusicObj.folder_names
    folders = writeMusicObj.folders_in_tree
    port = Usbhost.get_device_port()
    with serial.Serial(port, baudrate=115200, timeout=0.1) as ser:
        with open(os.path.join(master.dest, 'folders.csv'), 'w',
                  newline='') as csvfile:
            writer = csv.writer(csvfile, dialect='excel')
            previous = ""
            while True:
                i = yield (True)
                if i > 0 and i <= len(names):
                    name = names[i - 1]
                    folder = folders[i - 1]

                    done = False
                    while not done:
                        answer = ser.readall().decode('utf-8').split('\r')
                        _ = yield (False)
                        for line in answer:
                            if line.startswith("Card: ") and line != previous:
                                previous = line
                                words = line.split(" ")
                                writer.writerow([words[1], words[2], name])
                                done = True

                    tree.item(folder, tags=())
                if i < len(names):
                    tree.item(folders[i], tags=('active'))
Esempio n. 2
0
def write_points(points):
    for i in range(len(points)):
        pts_lbls[i].config(text=points[i])

    command = "set %d %d %d %d\r\n" % tuple(points)
    ser = Usbhost.open_port(Usbhost.get_device_port())
    Usbhost.send_command(ser, command)
    Usbhost.close_port(ser)
    with open(FILENAME, "w", newline="") as file:
        writer = csv.writer(file)
        writer.writerow(points)
Esempio n. 3
0
 def test_QueryNoParam(self):
     if device_connected:
         ser = Usbhost.open_port(Usbhost.get_device_port())
         self.assertEqual(Usbhost.send_query(ser, 'GetBtns'), 'Btns: 1 0 2 0')
Esempio n. 4
0
 def test_CommandWrongPort(self):
     ser = Usbhost.open_port('COM3')
     self.assertEqual(Usbhost.send_command(ser, 'Ping'), "Bad data")
     Usbhost.close_port(ser)
Esempio n. 5
0
 def test_OpenPortNotExists(self):
     self.assertIsNone(Usbhost.open_port('COM234'))
Esempio n. 6
0
 def test_ManyParamCommand(self):
     if device_connected:
         ser = Usbhost.open_port(Usbhost.get_device_port())
         self.assertEqual(Usbhost.send_command(ser, 'SetClr', 1, 255, 0, 0), "Ok")
         Usbhost.close_port(ser)
Esempio n. 7
0
 def test_UnknownCommand(self):
     if device_connected:
         ser = Usbhost.open_port(Usbhost.get_device_port())
         self.assertEqual(Usbhost.send_command(ser, 'SomeCommand'), "Unknown command")
         Usbhost.close_port(ser)
Esempio n. 8
0
 def test_BadDataCommand(self):
     if device_connected:
         ser = Usbhost.open_port(Usbhost.get_device_port())
         self.assertEqual(Usbhost.send_command(ser, 'SetClr'), "Bad data")
         Usbhost.close_port(ser)
Esempio n. 9
0
 def test_QueryWrongPort(self):
     ser = Usbhost.open_port('COM3')
     self.assertEqual(Usbhost.send_query(ser, 'SetClr', 1, 255, 0, 0), '')
     Usbhost.close_port(ser)
Esempio n. 10
0
 def test_CommandNoParam(self):
     if device_connected:
         ser = Usbhost.open_port(Usbhost.get_device_port())
         self.assertEqual(Usbhost.send_command(ser, 'Ping'), "Ok")
         Usbhost.close_port(ser)
Esempio n. 11
0
 def test_ManyParams(self):
     self.assertEqual(Usbhost.create_command('SetClr', 1, 255, 0, 0), 'SetClr 1 255 0 0\r\n')
Esempio n. 12
0
 def test_OpenPortExists(self):
     if device_connected:
         self.assertIsNotNone(Usbhost.open_port(device_port))
     else:
         self.assertIsNotNone(Usbhost.open_port('COM3'))
Esempio n. 13
0
 def test_OneParam(self):
     self.assertEqual(Usbhost.create_command('WritePill', 5), 'WritePill 5\r\n')
Esempio n. 14
0
 def test_NoParams(self):
     self.assertEqual(Usbhost.create_command("Ping"), 'Ping\r\n')
Esempio n. 15
0
 def test_NoOurDeviceList(self):
     if not device_connected:
         self.assertEqual(Usbhost.get_all_device_ports(), [])
Esempio n. 16
0
 def test_NoOurDevice(self):
     if not device_connected:
         self.assertIsNone(Usbhost.get_device_port())
Esempio n. 17
0
 def test_PortList(self):
     if device_connected:
         self.assertEqual(Usbhost.get_ports_list(), ['COM3', 'COM4'])
     else:
         self.assertEqual(Usbhost.get_ports_list(), ['COM3'])