當前位置: 首頁>>代碼示例>>Python>>正文


Python serial.serial_for_url方法代碼示例

本文整理匯總了Python中serial.serial_for_url方法的典型用法代碼示例。如果您正苦於以下問題:Python serial.serial_for_url方法的具體用法?Python serial.serial_for_url怎麽用?Python serial.serial_for_url使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在serial的用法示例。


在下文中一共展示了serial.serial_for_url方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_serial_connection

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import serial_for_url [as 別名]
def create_serial_connection(loop, protocol_factory, *args, **kwargs):
    ser = serial.serial_for_url(*args, **kwargs)
    protocol = protocol_factory()
    transport = SerialTransport(loop, protocol, ser)
    return (transport, protocol) 
開發者ID:wolfmanjm,項目名稱:kivy-smoothie-host,代碼行數:7,代碼來源:serial_asyncio.py

示例2: __init__

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import serial_for_url [as 別名]
def __init__(self, port=DEFAULT_PORT, baud=ESP_ROM_BAUD, trace_enabled=False):
        """Base constructor for ESPLoader bootloader interaction

        Don't call this constructor, either instantiate ESP8266ROM
        or ESP32ROM, or use ESPLoader.detect_chip().

        This base class has all of the instance methods for bootloader
        functionality supported across various chips & stub
        loaders. Subclasses replace the functions they don't support
        with ones which throw NotImplementedInROMError().

        """
        if isinstance(port, basestring):
            self._port = serial.serial_for_url(port)
        else:
            self._port = port
        self._slip_reader = slip_reader(self._port, self.trace)
        # setting baud rate in a separate step is a workaround for
        # CH341 driver on some Linux versions (this opens at 9600 then
        # sets), shouldn't matter for other platforms/drivers. See
        # https://github.com/espressif/esptool/issues/44#issuecomment-107094446
        self._set_port_baudrate(baud)
        self._trace_enabled = trace_enabled
        # set write timeout, to prevent esptool blocked at write forever.
        try:
            self._port.write_timeout = DEFAULT_SERIAL_WRITE_TIMEOUT
        except NotImplementedError:
            # no write timeout for RFC2217 ports
            # need to set the property back to None or it will continue to fail
            self._port.write_timeout = None 
開發者ID:marcelstoer,項目名稱:nodemcu-pyflasher,代碼行數:32,代碼來源:esptool.py

示例3: __init__

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import serial_for_url [as 別名]
def __init__(self, port=0, baud=ESP_ROM_BAUD):
        self._port = serial.serial_for_url(port)
        self._slip_reader = slip_reader(self._port)
        # setting baud rate in a separate step is a workaround for
        # CH341 driver on some Linux versions (this opens at 9600 then
        # sets), shouldn't matter for other platforms/drivers. See
        # https://github.com/espressif/esptool/issues/44#issuecomment-107094446
        self._port.baudrate = baud 
開發者ID:larsjuhljensen,項目名稱:phatsniffer,代碼行數:10,代碼來源:esptool.py

示例4: setUp

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import serial_for_url [as 別名]
def setUp(self):
    self.dummy_serial = serial.serial_for_url("loop://logging=debug")
    self.comm_dummy = AyabCommunication(self.dummy_serial) 
開發者ID:fossasia,項目名稱:knitlib,代碼行數:5,代碼來源:test_ayab_communication.py

示例5: _doSerialCommand

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import serial_for_url [as 別名]
def _doSerialCommand(self, command):
        """
        Opens serial connection, sends command (multiple times if needed)
        and returns the byte_response
        """
        command.clearByteResponse()
        response_line = None
        log.debug('port %s, baudrate %s', self._serial_device, self._baud_rate)
        try:
            with serial.serial_for_url(self._serial_device, self._baud_rate) as s:
                # Execute command multiple times, increase timeouts each time
                for x in range(1, 5):
                    log.debug('Command execution attempt %d...', x)
                    s.timeout = 1 + x
                    s.write_timeout = 1 + x
                    s.flushInput()
                    s.flushOutput()
                    s.write(command.byte_command)
                    time.sleep(0.5 * x)  # give serial port time to receive the data
                    response_line = s.readline()
                    log.debug('serial byte_response was: %s', response_line)
                    command.setByteResponse(response_line)
                    return command
        except Exception as e:
            log.warning("Serial read error: {}".format(e))
        log.info('Command execution failed')
        return command 
開發者ID:jblance,項目名稱:mpp-solar,代碼行數:29,代碼來源:mppinverter.py

示例6: __init__

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import serial_for_url [as 別名]
def __init__(self, port=DEFAULT_PORT, baud=ESP_ROM_BAUD, trace_enabled=False):
        """Base constructor for ESPLoader bootloader interaction

        Don't call this constructor, either instantiate ESP8266ROM
        or ESP32ROM, or use ESPLoader.detect_chip().

        This base class has all of the instance methods for bootloader
        functionality supported across various chips & stub
        loaders. Subclasses replace the functions they don't support
        with ones which throw NotImplementedInROMError().

        """
        self.secure_download_mode = False  # flag is set to True if esptool detects the ROM is in Secure Download Mode

        if isinstance(port, basestring):
            self._port = serial.serial_for_url(port)
        else:
            self._port = port
        self._slip_reader = slip_reader(self._port, self.trace)
        # setting baud rate in a separate step is a workaround for
        # CH341 driver on some Linux versions (this opens at 9600 then
        # sets), shouldn't matter for other platforms/drivers. See
        # https://github.com/espressif/esptool/issues/44#issuecomment-107094446
        self._set_port_baudrate(baud)
        self._trace_enabled = trace_enabled
        # set write timeout, to prevent esptool blocked at write forever.
        try:
            self._port.write_timeout = DEFAULT_SERIAL_WRITE_TIMEOUT
        except NotImplementedError:
            # no write timeout for RFC2217 ports
            # need to set the property back to None or it will continue to fail
            self._port.write_timeout = None 
開發者ID:espressif,項目名稱:esptool,代碼行數:34,代碼來源:esptool.py

示例7: test_load_ram

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import serial_for_url [as 別名]
def test_load_ram(self):
        """ Verify load_ram command

        The "hello world" binary programs for each chip print
        "Hello world!\n" to the serial port.
        """
        self.run_esptool("load_ram images/helloworld-%s.bin" % chip)
        p = serial.serial_for_url(serialport, default_baudrate)
        p.timeout = 0.2
        output = p.read(100)
        print("Output: %r" % output)
        self.assertIn(b"Hello world!", output)
        p.close() 
開發者ID:espressif,項目名稱:esptool,代碼行數:15,代碼來源:test_esptool.py

示例8: __init__

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import serial_for_url [as 別名]
def __init__(self, port, baudrate, parity, rtscts, xonxoff, echo=False, convert_outgoing=CONVERT_CRLF, repr_mode=0):
        try:
            self.serial = serial.serial_for_url(port, baudrate, parity=parity, rtscts=rtscts, xonxoff=xonxoff, timeout=1)
        except AttributeError:
            # happens when the installed pyserial is older than 2.5. use the
            # Serial class directly then.
            self.serial = serial.Serial(port, baudrate, parity=parity, rtscts=rtscts, xonxoff=xonxoff, timeout=1)
        self.echo = echo
        self.repr_mode = repr_mode
        self.convert_outgoing = convert_outgoing
        self.newline = NEWLINE_CONVERISON_MAP[self.convert_outgoing]
        self.dtr_state = True
        self.rts_state = True
        self.break_state = False 
開發者ID:FSecureLABS,項目名稱:Jandroid,代碼行數:16,代碼來源:miniterm.py

示例9: __init__

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import serial_for_url [as 別名]
def __init__(self, port=None, baudrate=19200, parity=serial.PARITY_NONE,
                 reconnect_dt=10):
        """Constructor.

        The client will not be connected until connect() is called.
        Either manually or by the network manager.

        Args:
          port (str):  The serial device or URL to connect to.  See
                       the serial.serial_for_url() documentation for details.
          baudrate (int):  Baud rate to use in the connection.
          parity:  serial.PARITY value to use.
          reconnect_dt (int): Time in seconds to try and reconnect if the
                       connection drops.

        """
        # Public signals to connect to for read/write notification.
        self.signal_read = Signal()   # (Serial, bytes)
        self.signal_wrote = Signal()  # (Serial, bytes)

        super().__init__()

        self._port = port
        self._baudrate = baudrate
        self._parity = parity
        self._reconnect_dt = reconnect_dt
        self._fd = None

        # List of packets to write.  Each is a tuple of (bytes, time) where
        # the time is the time after which to do the write.
        self._write_buf = []

        # Create the serial client but don't open it yet.  We'll wait for a
        # connection call to do that.
        self.client = None
        if port:
            self._open_client()

        self.signal_connected.connect(self._connected)

    #----------------------------------------------------------------------- 
開發者ID:TD22057,項目名稱:insteon-mqtt,代碼行數:43,代碼來源:Serial.py

示例10: _open_client

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import serial_for_url [as 別名]
def _open_client(self):
        """Create the serial client.

        The connection is not actually opened yet - that happens in
        connect().
        """
        client = serial.serial_for_url(self._port, do_not_open=True, timeout=0,
                                       write_timeout=0)
        client.baudrate = self._baudrate
        client.parity = self._parity
        return client

    #----------------------------------------------------------------------- 
開發者ID:TD22057,項目名稱:insteon-mqtt,代碼行數:15,代碼來源:Serial.py

示例11: test_send_message_with_timeout

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import serial_for_url [as 別名]
def test_send_message_with_timeout():
    """ Test if TimoutError is raised when serial port doesn't receive enough
    data.
    """
    s = serial_for_url('loop://', timeout=0)
    # As we are using a loop, the sent request will be read back as response.
    # To test timeout use a request that needs more bytes for the response.
    message = read_coils(slave_id=0, starting_address=1, quantity=40)

    with pytest.raises(ValueError):
        send_message(message, s) 
開發者ID:AdvancedClimateSystems,項目名稱:uModbus,代碼行數:13,代碼來源:test_rtu.py

示例12: test_rtu_server_send_empty_message

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import serial_for_url [as 別名]
def test_rtu_server_send_empty_message(rtu_server):
    rtu_server.serial_port = serial_for_url('loop://')
    rtu_server.serial_port.write(b'')

    with pytest.raises(ValueError):
        rtu_server.serve_once() 
開發者ID:AdvancedClimateSystems,項目名稱:uModbus,代碼行數:8,代碼來源:test_rtu.py

示例13: sync_connect

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import serial_for_url [as 別名]
def sync_connect(transport):
    """Connect to the serial port.

    This should be run in a new thread.
    """
    while transport.protocol:
        _LOGGER.info("Trying to connect to %s", transport.gateway.port)
        try:
            ser = serial.serial_for_url(
                transport.gateway.port,
                transport.gateway.baud,
                timeout=transport.timeout,
            )
        except serial.SerialException:
            _LOGGER.error("Unable to connect to %s", transport.gateway.port)
            _LOGGER.info(
                "Waiting %s secs before trying to connect again",
                transport.reconnect_timeout,
            )
            time.sleep(transport.reconnect_timeout)
        else:
            serial_transport = serial.threaded.ReaderThread(
                ser, lambda: transport.protocol
            )
            serial_transport.daemon = False
            serial_transport.start()
            serial_transport.connect()
            return 
開發者ID:theolind,項目名稱:pymysensors,代碼行數:30,代碼來源:gateway_serial.py

示例14: change_port

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import serial_for_url [as 別名]
def change_port(self):
        """Have a conversation with the user to change the serial port"""
        with self.console:
            try:
                port = ask_for_port()
            except KeyboardInterrupt:
                port = None
        if port and port != self.serial.port:
            # reader thread needs to be shut down
            self._stop_reader()
            # save settings
            settings = self.serial.getSettingsDict()
            try:
                new_serial = serial.serial_for_url(port, do_not_open=True)
                # restore settings and open
                new_serial.applySettingsDict(settings)
                new_serial.rts = self.serial.rts
                new_serial.dtr = self.serial.dtr
                new_serial.open()
                new_serial.break_condition = self.serial.break_condition
            except Exception as e:
                sys.stderr.write('--- ERROR opening new port: {} ---\n'.format(e))
                new_serial.close()
            else:
                self.serial.close()
                self.serial = new_serial
                sys.stderr.write('--- Port changed to: {} ---\n'.format(self.serial.port))
            # and restart the reader thread
            self._start_reader() 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:31,代碼來源:miniterm.py

示例15: setUp

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import serial_for_url [as 別名]
def setUp(self):
        self.serial_handler = SerialHandler("LOOP FOR TESTS")  # device_name will not be used
        self.serial_handler.serial_device = serial.serial_for_url('loop://') 
開發者ID:alexandreblin,項目名稱:python-can-monitor,代碼行數:5,代碼來源:test_source_handler.py


注:本文中的serial.serial_for_url方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。