class McuComponent(ApplicationSession): """ MCU WAMP application component. """ def __init__(self, config=None): ApplicationSession.__init__(self, config) self._primare_talker = PrimareTalker(source=None, volume=None) @inlineCallbacks def onJoin(self, details): print("MyComponent ready! Configuration: {}".format(self.config.extra)) port = self.config.extra["port"] baudrate = self.config.extra["baudrate"] debug = self.config.extra["debug"] serial_protocol = McuProtocol(self, self._primare_talker, debug) self._primare_talker.register_mcu_write_cb(serial_protocol.wrapSendLine) print("About to open serial port {0} [{1} baud] ..".format(port, baudrate)) try: # Prototype: # SerialPort(protocol, deviceNameOrPortNumber, reactor, # baudrate=9600, bytesize=EIGHTBITS, parity=PARITY_NONE, # stopbits=STOPBITS_ONE, xonxoff=0, rtscts=0) # Primare serial link config # BAUDRATE = 4800 # BYTESIZE = 8 # PARITY = 'N' # STOPBITS = 1 # TODO: Try changing the name once everything works serialPort = SerialPort(serial_protocol, port, reactor, baudrate=baudrate) # self._primare_talker.setup() # yield self._primare_talker._set_device_to_known_state() yield self._primare_talker._print_device_info1() yield self._primare_talker._print_device_info2() # yield self._primare_talker._print_device_info2() # yield self._primare_talker._print_device_info3() yield self._primare_talker._print_device_info3() yield self._primare_talker._print_device_info4() yield self._primare_talker._print_device_info4() yield self._primare_talker._print_device_info4() yield self._primare_talker._print_device_info4() except Exception as e: print("Could not open serial port: {0}".format(e)) self.leave() else: yield self.register(serial_protocol.randomFunc, u"com.mopidy.primare.randomFunc")
def __init__(self, config=None): ApplicationSession.__init__(self, config) self._primare_talker = PrimareTalker(source=None, volume=None)