python类serial_for_url()的实例源码

esptool.py 文件源码 项目:iot 作者: akademikbilisim 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __init__(self, port=DEFAULT_PORT, baud=ESP_ROM_BAUD):
        """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, serial.Serial):
            self._port = port
        else:
            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
esptool.py 文件源码 项目:nodemcu-pyflasher 作者: marcelstoer 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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, serial.Serial):
            self._port = port
        else:
            self._port = serial.serial_for_url(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
micropi.py 文件源码 项目:Micro-Pi 作者: Bottersnike 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def serialPoller(self):
    start = True
    def addText(self, text):
        tb = self.consoleBody.get_buffer()
        tb.insert(tb.get_end_iter(), text)
    while True:
        if self.serialConnection:
            try:
                data = self.serialConnection.read()
                d2 = ''
                for i in data:
                    if i in string.printable:
                        d2 += i
                gobject.idle_add(addText, self, d2)
            except:
                pass
        else:
            try:
                self.serialConnection = serial.serial_for_url(self.serialLocation)
                self.serialConnection.baudrate = self.baudrate
            except:
                pass
            time.sleep(0.1)
micropi.py 文件源码 项目:Micro-Pi 作者: Bottersnike 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def inlineSerialPoller(self):
    start = True
    def addText(self, text):
        tb = self.serialConsoleBody.get_buffer()
        tb.insert(tb.get_end_iter(), text)
    while True:
        if self.serialConnection:
            try:
                data = self.serialConnection.read()
                d2 = ''
                for i in data:
                    if i in string.printable:
                        d2 += i
                gobject.idle_add(addText, self, d2)
            except:
                pass
        else:
            try:
                self.serialConnection = serial.serial_for_url(self.serialLocation)
                self.serialConnection.baudrate = self.baudrate
            except:
                pass
            time.sleep(0.1)
esptool.py 文件源码 项目:iot 作者: karakaplanm 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __init__(self, port=DEFAULT_PORT, baud=ESP_ROM_BAUD):
        """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, serial.Serial):
            self._port = port
        else:
            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
test_settings_dict.py 文件源码 项目:Jackal_Velodyne_Duke 作者: MengGuo 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def test_init_sets_the_correct_attrs(self):
        """__init__ sets the fields that get_settings reads"""
        for setting, value in (
                ('baudrate', 57600),
                ('timeout', 7),
                ('write_timeout', 12),
                ('inter_byte_timeout', 15),
                ('stopbits', serial.STOPBITS_TWO),
                ('bytesize', serial.SEVENBITS),
                ('parity', serial.PARITY_ODD),
                ('xonxoff', True),
                ('rtscts', True),
                ('dsrdtr', True)):
            kwargs = {'do_not_open': True, setting: value}
            ser = serial.serial_for_url(PORT, **kwargs)
            d = ser.get_settings()
            self.assertEqual(getattr(ser, setting), value)
            self.assertEqual(d[setting], value)
test_threaded.py 文件源码 项目:Jackal_Velodyne_Duke 作者: MengGuo 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_framed_packet(self):
        """simple test of line reader class"""

        class TestFramedPacket(serial.threaded.FramedPacket):
            def __init__(self):
                super(TestFramedPacket, self).__init__()
                self.received_packets = []

            def handle_packet(self, packet):
                self.received_packets.append(packet)

            def send_packet(self, packet):
                self.transport.write(self.START)
                self.transport.write(packet)
                self.transport.write(self.STOP)

        ser = serial.serial_for_url(PORT, baudrate=115200, timeout=1)
        with serial.threaded.ReaderThread(ser, TestFramedPacket) as protocol:
            protocol.send_packet(b'1')
            protocol.send_packet(b'2')
            protocol.send_packet(b'3')
            time.sleep(1)
            self.assertEqual(protocol.received_packets, [b'1', b'2', b'3'])
esptool.py 文件源码 项目:cotcha 作者: hevnsnt 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def __init__(self, port=DEFAULT_PORT, baud=ESP_ROM_BAUD):
        """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, serial.Serial):
            self._port = port
        else:
            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._set_port_baudrate(baud)
piksi_driver.py 文件源码 项目:piksi_ros 作者: uscresl 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def __init__(self, port, baud_rate):
        import serial
        self.serial = serial.serial_for_url(port)
        self.serial.baudrate = baud
        self.serial.timeout = 1
faceplate_format.py 文件源码 项目:mycroft-light 作者: MatthewScholefield 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, rt):
        super().__init__(rt, '.faceplate')
        enc_cfg = self.rt.config['enclosure']
        self.serial = serial.serial_for_url(url=enc_cfg['port'], baudrate=enc_cfg['rate'],
                                            timeout=enc_cfg['timeout'])
        self.queue = Queue()
        self.timers = []
esptool.py 文件源码 项目:phatsniffer 作者: larsjuhljensen 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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
__init__.py 文件源码 项目:pyelk 作者: BioSehnsucht 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def connect(self, pyelk, address, ratelimit):
        """Connect to the Elk panel.

        address: Host to connect to in either
        "socket://IP.Add.re.ss:Port" or "/dev/ttyUSB0" format.
        ratelimit: rate limit for outgoing events
        """
        self._connection = serial.serial_for_url(address, timeout=1)
        self._connection_thread = serial.threaded.ReaderThread(self._connection, SerialInputHandler)
        self._connection_thread.start()
        self._connection_transport, self._connection_protocol = self._connection_thread.connect()
        self._connection_protocol.set_pyelk(pyelk)
        self._connection_output = SerialOutputHandler(ratelimit)
        self._connection_output.set_pyelk(pyelk)
        _LOGGER.debug('ReaderThread created')
test_serial.py 文件源码 项目:pyrealtime 作者: ewhitmire 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def setUp(self):
        self.s = serial.serial_for_url(PORT, timeout=10)
miniterm.py 文件源码 项目:microbit-gateway 作者: whaleygeek 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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
miniterm.py 文件源码 项目:mb_remote 作者: whaleygeek 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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
miniterm.py 文件源码 项目:gcodeplot 作者: arpruss 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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
esptool.py 文件源码 项目:codal 作者: lancaster-university 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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/themadinventor/esptool/issues/44#issuecomment-107094446
        self._port.baudrate = baud
micropi.py 文件源码 项目:Micro-Pi 作者: Bottersnike 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def refresh(self, *args):
        self.ports = list(list_ports.grep(''))
        #self.serialLocation = self.ports[0][0] if self.ports else None
        #self.serialConnection = None if not self.serialLocation else serial.serial_for_url(self.serialLocation)
        #if self.serialLocation is not None:
            #self.serialConnection.baudrate = self.baudrate
        self.gtkserialloc.get_model().clear()
        for i in self.ports:
            self.gtkserialloc.append_text(i[0])
        self.gtkserialloc.set_active(0 if self.ports else -1)
micropi.py 文件源码 项目:Micro-Pi 作者: Bottersnike 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def brtchange(self, widget, *args):
        model = widget.get_model()
        index = widget.get_active()
        newbdrate = int(model[index][0])
        self.baudrate = newbdrate
        if not self.serialConnection:
            self.serialConnection = serial.serial_for_url(self.serialLocation)
        self.serialConnection.baudrate = newbdrate
micropi.py 文件源码 项目:Micro-Pi 作者: Bottersnike 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def portchange(self, widget, *args):
        model = widget.get_model()
        index = widget.get_active()
        if 0 <= index < len(model):
            newport = model[index][0]
            self.serialLocation = newport
            if not self.serialConnection:
                self.serialConnection = serial.serial_for_url(self.serialLocation)
            self.serialConnection.port = newport
            self.serialConnection.baudrate = self.baudrate
micropi.py 文件源码 项目:Micro-Pi 作者: Bottersnike 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def brtchange(self, widget, *args):
        model = widget.get_model()
        index = widget.get_active()
        newbdrate = int(model[index][0])
        self.baudrate = newbdrate
        if not self.serialConnection:
            self.serialConnection = serial.serial_for_url(self.serialLocation)
        self.serialConnection.baudrate = newbdrate
micropi.py 文件源码 项目:Micro-Pi 作者: Bottersnike 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def portchange(self, widget, *args):
        model = widget.get_model()
        index = widget.get_active()
        if 0 <= index < len(model):
            newport = model[index][0]
            self.serialLocation = newport
            if not self.serialConnection:
                self.serialConnection = serial.serial_for_url(self.serialLocation)
            self.serialConnection.port = newport
            self.serialConnection.baudrate = self.baudrate
miniterm.py 文件源码 项目:driveboardapp 作者: nortd 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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
comm_uart.py 文件源码 项目:drtio_transceiver_test 作者: m-labs 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, port, baudrate=115200):
        self.port = serial.serial_for_url(port, baudrate)
miniterm.py 文件源码 项目:mb_sdcard 作者: whaleygeek 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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
serialdriver.py 文件源码 项目:labgrid 作者: labgrid-project 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __attrs_post_init__(self):
        super().__attrs_post_init__()
        self.logger = logging.getLogger("{}({})".format(self, self.target))
        if isinstance(self.port, SerialPort):
            self.serial = serial.Serial()
        else:
            if self.port.protocol == "rfc2217":
                self.serial = serial.rfc2217.Serial()
            elif self.port.protocol == "raw":
                self.serial = serial.serial_for_url("socket://", do_not_open=True)
            else:
                raise Exception("SerialDriver: unknown protocol")
        self.status = 0
aio.py 文件源码 项目:mt7687-serial-uploader 作者: will127534 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
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)
miniterm.py 文件源码 项目:get_started_with_respeaker 作者: respeaker 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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
concord.py 文件源码 项目:concord232 作者: JasonCarter80 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, dev_name, timeout_secs, control_char_cb, logger):
        """ 
        *dev_name* is string name of the device e.g. /dev/cu.usbserial
        *timeout_secs* in fractional seconds; e.g. 0.25 = 250 milliseconds
        """
        self.control_char_cb = control_char_cb
        self.logger = logger
        self.logger.debug("SerialInterface Starting")
        # Ugly debugging hack
        if dev_name == 'fake':
            return
        self.serdev = serial.serial_for_url(dev_name, baudrate=CONCORD_BAUD,
                                    bytesize=CONCORD_BYTESIZE, parity=CONCORD_PARITY,
                                    stopbits=CONCORD_STOPBITS, timeout=timeout_secs,
                                    xonxoff=False, rtscts=False, dsrdtr=False)
esptool.py 文件源码 项目:johnny-five-esp8266 作者: anaganisk 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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/themadinventor/esptool/issues/44#issuecomment-107094446
        self._port.baudrate = baud


问题


面经


文章

微信
公众号

扫码关注公众号