def identify_device(cls, dev): sconn = SIMCardConnAdapter(dev) try: dport, speed = dev.dport, dev.baudrate _sp = serialport.SerialPort(sconn, dport, reactor, baudrate=speed) except SerialException, e: return defer.fail(e)
def connect(self, device, reactor): """ Connects to a device. :param device: The device name or port number. :param reactor: The twisted reactor. """ serialport.SerialPort(self, device, reactor, baudrate=57600)
def reconnect(self): try: RS232port, RS232baud = self.config.getRS232parms() serialport.SerialPort(self, RS232port, reactor, baudrate = RS232baud) serialLog.debug("RECONNECTED") except: serialLog.debug("Error opening serial port...", sys.exc_info()[1]) self.retry = reactor.callLater(5.31, self.reconnect)
def reconnect(self): try: options = Options() config = SafeConfigParser() config.read([options['config']]) serialport.SerialPort(self, config.get('RS-422', 'host'), reactor, baudrate=config.getint('RS-422', 'baudrate')) if self.deferred: self.deferred = None self.lock.release() except: log.debug("Error opening serial port...") self.retry = reactor.callLater(5.31, self.reconnect)
def run(): log.startLogging(sys.stdout) opts = Options() try: opts.parseOptions() except usage.UsageError as message: print(f"{sys.argv[0]}: {message}") return positioningReceiver = PositioningReceiver() nmeaReceiver = nmea.NMEAAdapter(positioningReceiver) proto = nmea.NMEAProtocol(nmeaReceiver) port, baudrate = opts["serial-port"], opts["baud-rate"] serialport.SerialPort(proto, port, reactor, baudrate=baudrate) reactor.run()
def start(self): self._serial_protocol = protocol.ArduinoProtocol(self._output_callable) try: self._serial_port = serialport.SerialPort( self._serial_protocol, self._device_file, self._reactor, baudrate=self._baud_rate, ) except Exception as e: _log.warn('serial port opening failed: {f}', f=e) raise _log.info( 'started: {d!r} open at {b} baud', d=self._device_file, b=self._baud_rate, ) yield defer.succeed(None)
def __new__(cls, reactor, port, initial_baud_rate=9600): self = object.__new__(XBee) buf = [] self._protocol = Protocol() self._protocol.dataReceived = lambda data: buf.extend(data) cmds = [ 'ATID9FF', 'ATHP6', 'ATKY0', 'ATRR0', 'ATMT0', 'ATAP1', 'ATMYFFFF', 'ATDTFFFF', #'ATMK0', # sniffing # RB/PK? 'ATCN', ] self._port = serialport.SerialPort(self._protocol, port, reactor, initial_baud_rate) self._port.flushInput() yield deferral.sleep(1.1) print repr(''.join(buf)) buf = [] self._port.write('+++') yield deferral.sleep(1.1) for cmd in cmds: print repr(''.join(buf)) buf = [] self._port.write(cmd + '\r') yield deferral.sleep(.1) self.packet_received = variable.Event() self._protocol.dataReceived = datachunker.DataChunker( self.dataReceiver()) defer.returnValue(self)
def setup(self): # Read our file, and attach it to the status. self.port = self.adapter_json.get('port') self.name = self.adapter_json.get('name', 'iogear') logging.info('IOGear %s on port %s', self.name, self.port) # Active stores which port is active. self.active_url = os.path.join(self.url, 'iogear', self.name, 'active') self.target_url = os.path.join(self.url, 'iogear', self.name, 'target') # Setup our state values with None. self.status.set(self.active_url, None) self.status.set(self.target_url, None) self.serial_port = serialport.SerialPort(self, self.port, reactor) # Send a query message. This will get a reponse to dataReceived and populate # the active_url. self.sendData('?') # Start watching target. self.status.deferred(url=self.target_url).addCallback(self._target_updated)
def __init__(self, nh, port): self._protocol = LoadCellProtocol() self.measurement_event = self._protocol.measurement_event self._port = serialport.SerialPort(self._protocol, port, reactor, 9600)
class Options(usage.Options): optParameters = [ ['baud-rate', 'b', 4800, "Baud rate (default: 4800)"], ['serial-port', 'p', '/dev/ttyS0', 'Serial Port device'], ] def run(): log.startLogging(sys.stdout) opts = Options() try: opts.parseOptions() except usage.UsageError, message: print "{}: {}".format(sys.argv[0], message) return positioningReceiver = PositioningReceiver() nmeaReceiver = nmea.NMEAAdapter(positioningReceiver) proto = nmea.NMEAProtocol(nmeaReceiver) port, baudrate = opts["serial-port"], opts["baud-rate"] serialport.SerialPort(proto, port, reactor, baudrate=baudrate) reactor.run() if __name__ == "__main__": run()