def setUp(self):
     self.cnc_library = CncLibrary(device="invalid")
     self.cnc_library._serial = FakeDevice()
     self.device = self.cnc_library._serial
     self.cnc_library.initialize_device_locations(
         os.path.join("..", "..", "examples", "test_device.json"))
     self.cnc_library.timeout = 1
Esempio n. 2
0
class ChopperController(DeviceController):
    def run(self):
        # self.chopper = serial.Serial(port="COM3", timeout=2, baudrate=115200)
        self.chopper = FakeDevice()
        self.to_device("verbose=1")

        # override what DeviceController.__init__ defaulted to
        self.ListenerCls = StreamingListener
        self.device_args = (self.chopper.readall, self._device_dt)
        self.device_connect = lambda: self.from_device(self.read_device())

        """
        # Continuously collect device output here and use it as a proxy
        # for the device itself.
        self.device_stream = ""
        self.device_stream_pos = 0
        self.device_streamer = threading.Thread(target=self.sync_device_stream)
        self.device_streamer.daemon = True
        self.device_streamer.start()
        """

        super(ChopperController, self).run()

    """
    def sync_device_stream(self):
        while True:
            self.device_stream += self.chopper.readall().replace("\r", "\n")
            time.sleep(0.1)
    """

    def to_device(self, s):
        self.chopper.write(s + "\r")

    """
    def device_has_output(self):
        return self.device_stream_pos < len(self.device_stream)
    """

    def read_device(self):
        return self.chopper_stream.readall()

    def from_parent(self, recv):
        self.to_device(recv)

    def from_device(self, s):
        print "called"
        self.to_parent(s)
Esempio n. 3
0
    def run(self):
        # self.chopper = serial.Serial(port="COM3", timeout=2, baudrate=115200)
        self.chopper = FakeDevice()
        self.to_device("verbose=1")

        # override what DeviceController.__init__ defaulted to
        self.ListenerCls = StreamingListener
        self.device_args = (self.chopper.readall, self._device_dt)
        self.device_connect = lambda: self.from_device(self.read_device())

        """
        # Continuously collect device output here and use it as a proxy
        # for the device itself.
        self.device_stream = ""
        self.device_stream_pos = 0
        self.device_streamer = threading.Thread(target=self.sync_device_stream)
        self.device_streamer.daemon = True
        self.device_streamer.start()
        """

        super(ChopperController, self).run()