当前位置: 首页>>代码示例>>Python>>正文


Python machine.UART属性代码示例

本文整理汇总了Python中machine.UART属性的典型用法代码示例。如果您正苦于以下问题:Python machine.UART属性的具体用法?Python machine.UART怎么用?Python machine.UART使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在machine的用法示例。


在下文中一共展示了machine.UART属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: uart_readline

# 需要导入模块: import machine [as 别名]
# 或者: from machine import UART [as 别名]
def uart_readline(self, **kwargs) -> str:
        """
        Read a line (any character until newline is found) from a UART interface.

        :param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.uart_open` and
            :meth:`platypush.plugins.esp.EspPlugin.execute`.
        :return: String representation of the read bytes, or base64-encoded representation if the
            data can't be decoded to a string.
        """
        self.uart_open(**kwargs)
        response = self.execute('uart.readline()', **kwargs).output

        try:
            return response.decode()
        except UnicodeDecodeError:
            return base64.encodebytes(response).decode() 
开发者ID:BlackLight,项目名称:platypush,代码行数:18,代码来源:__init__.py

示例2: uart_write

# 需要导入模块: import machine [as 别名]
# 或者: from machine import UART [as 别名]
def uart_write(self, data: str, binary: bool = False, **kwargs):
        """
        Write data to the UART bus.

        :param data: Data to be written.
        :param binary: By default data will be treated as a string. Set binary to True if it should
            instead be treated as a base64-encoded binary string to be decoded before being sent.
        :param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.uart_open` and
            :meth:`platypush.plugins.esp.EspPlugin.execute`.
        """
        if binary:
            data = base64.decodebytes(data.encode())
        else:
            data = data.encode()

        data = 'b"' + ''.join(['\\x{:02x}'.format(b) for b in data]) + '"'
        self.uart_open(**kwargs)

        code = 'uart.write({data})'.format(data=data)
        self.execute(code, **kwargs) 
开发者ID:BlackLight,项目名称:platypush,代码行数:22,代码来源:__init__.py

示例3: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import UART [as 别名]
def __init__(self):
        self.uart = machine.UART(2, baudrate=115200, tx=17, rx=-2) 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:4,代码来源:_lidarBot.py

示例4: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import UART [as 别名]
def __init__(self):
        self.uart = machine.UART(1, tx=17, rx=16)
        self.uart.init(9600, bits=8, parity=None, stop=1)
        self._timer = timEx.addTimer(200, timEx.PERIODIC, self._monitor)
        self.data_save = b'' 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:7,代码来源:_pm25.py

示例5: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import UART [as 别名]
def __init__(self):
        self.uart = machine.UART(1, tx=17, rx=16)
        self.uart.init(9600, bits=8, parity=None, stop=1)
        self.callback = None
        if self._reset() == 1:
            raise module.Module('Module lorawan not connect')
        self._timer = None
        self.uartString = ''
        time.sleep(2) 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:11,代码来源:_lorawan.py

示例6: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import UART [as 别名]
def __init__(self):

        self.uart = machine.UART(1, tx=17, rx=16)
        self.uart.init(19600, bits=0, parity=None, stop=1)
        self._timer = timEx.addTimer(100, timEx.PERIODIC, self._monitor)
        self._times = 0
        self.cb = None
        self.unknownCb = None
        self.access_add = 0
        self.user_id_add = 0
        
        self.state = ''
        time.sleep_ms(100)
        self.readUser() 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:16,代码来源:_finger.py

示例7: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import UART [as 别名]
def __init__(self, port):
        self.uart = machine.UART(1, tx=port[0], rx=port[1])
        self.uart.init(19600, bits=0, parity=None, stop=1)
        self._timer = timEx.addTimer(100, timEx.PERIODIC, self._monitor)
        self._times = 0
        self.cb = None
        self.unknownCb = None
        self.access_add = 0
        self.user_id_add = 0
        
        self.state = ''
        time.sleep_ms(100)
        self.readUser() 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:15,代码来源:_finger.py

示例8: uart_close

# 需要导入模块: import machine [as 别名]
# 或者: from machine import UART [as 别名]
def uart_close(self, **kwargs):
        """
        Turn off the UART bus.

        :param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.uart_open` and
            :meth:`platypush.plugins.esp.EspPlugin.execute`.
        """
        self.uart_open(**kwargs)
        self.execute('uart.deinit()', **kwargs) 
开发者ID:BlackLight,项目名称:platypush,代码行数:11,代码来源:__init__.py

示例9: uart_read

# 需要导入模块: import machine [as 别名]
# 或者: from machine import UART [as 别名]
def uart_read(self, size: Optional[int] = None, **kwargs) -> str:
        """
        Read from a UART interface.

        :param size: Number of bytes to read (default: read all available characters).
        :param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.uart_open` and
            :meth:`platypush.plugins.esp.EspPlugin.execute`.
        :return: String representation of the read bytes, or base64-encoded representation if the
            data can't be decoded to a string.
        """
        self.uart_open(**kwargs)

        code = '''
args = []
if {size}:
    args.append({size})

uart.read(*args)
'''.format(size=size)

        response = self.execute(code, **kwargs).output
        try:
            return response.decode()
        except UnicodeDecodeError:
            return base64.encodebytes(response).decode() 
开发者ID:BlackLight,项目名称:platypush,代码行数:27,代码来源:__init__.py

示例10: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import UART [as 别名]
def __init__(self, en, tx, rx, rst):
        self.en = en
        self.tx = tx
        self.rx = rx
        self.rst = rst
        self.en.mode(Pin.OUT)
        self.rst.mode(Pin.OUT)

        self.uart = UART(1, baudrate=9600, pins=(self.tx, self.rx))
        self.uart.deinit() 
开发者ID:ayoy,项目名称:upython-aq-monitor,代码行数:12,代码来源:pms5003.py

示例11: read_gps_sample

# 需要导入模块: import machine [as 别名]
# 或者: from machine import UART [as 别名]
def read_gps_sample():
    """
    Attempts to read GPS and print the latest GPS values.
    """

    try:
        # Attempt to read GPS data up to 3 times.
        for i in range(3):
            print("- Reading GPS data... ",  end="")
            # Configure the UART to the GPS required parameters.
            u.init(9600, bits=8, parity=None, stop=1)
            time.sleep(1)
            # Ensures that there will only be a print if the UART
            # receives information from the GPS module.
            while not u.any():
                if u.any():
                    break
            # Read data from the GPS.
            gps_data = str(u.read(), 'utf8')
            # Close the UART.
            u.deinit()
            # Get latitude and longitude from the read GPS data.
            lat = extract_latitude(extract_gps(gps_data))
            lon = extract_longitude(extract_gps(gps_data))
            # Print location.
            if lon != 9999 and lat != 9999:
                print("[OK]")
                print("- Latitude: %s" % lat)
                print("- Longitude: %s" % lon)
                print(32 * "-")
                break
            else:
                print("[ERROR]")
                print("   * Bad GPS signal. Retrying...")

    except Exception as E:
        print("[ERROR]")
        print("   * There was a problem getting GPS data: %s", str(E)) 
开发者ID:digidotcom,项目名称:xbee-micropython,代码行数:40,代码来源:main.py

示例12: init_gnss

# 需要导入模块: import machine [as 别名]
# 或者: from machine import UART [as 别名]
def init_gnss():
    """Initialize the GNSS receiver"""

    log('Initializing GNSS...')

    enable = Pin(GNSS_ENABLE_PIN, mode=Pin.OUT)
    enable(False)
    uart = UART(GNSS_UART_PORT)
    uart.init(GNSS_UART_BAUD, bits=8, parity=None, stop=1)
    enable(True)

    log('Done!')

    return (uart, enable) 
开发者ID:ttn-be,项目名称:ttnmapper,代码行数:16,代码来源:ttnmapper.py

示例13: enable_serial

# 需要导入模块: import machine [as 别名]
# 或者: from machine import UART [as 别名]
def enable_serial(self):
        """ """
        # Disable these two lines if you don't want serial access.
        # The Pycom forum tells us that this is already incorporated into
        # more recent firmwares, so this is probably a thing of the past.
        #uart = machine.UART(0, 115200)
        #os.dupterm(uart)
        pass 
开发者ID:hiveeyes,项目名称:terkin-datalogger,代码行数:10,代码来源:device.py

示例14: start

# 需要导入模块: import machine [as 别名]
# 或者: from machine import UART [as 别名]
def start(self):
        """Start Terminal on UART0 interface."""
        # Conditionally enable terminal on UART0. Default: False.
        # https://forum.pycom.io/topic/1224/disable-console-to-uart0-to-use-uart0-for-other-purposes
        uart0_enabled = self.settings.get('interfaces.uart0.terminal', False)
        if uart0_enabled:
            from machine import UART
            self.uart = UART(0, 115200)
            #self.uart = UART(0)
            os.dupterm(self.uart)
        else:
            self.shutdown() 
开发者ID:hiveeyes,项目名称:terkin-datalogger,代码行数:14,代码来源:device.py

示例15: uart_open

# 需要导入模块: import machine [as 别名]
# 或者: from machine import UART [as 别名]
def uart_open(self, id=1, baudrate: Optional[int] = 9600, bits: Optional[int] = 8, parity: Optional[int] = None,
                  stop: int = 1, tx_pin: Optional[int] = None, rx_pin: Optional[int] = None,
                  timeout: Optional[float] = None, timeout_char: Optional[float] = None, **kwargs):
        """
        Open a connection to a UART port.

        :param id: Bus ID (default: 1).
        :param baudrate: Port baudrate (default: 9600).
        :param bits: Number of bits per character. It can be 7, 8 or 9.
        :param parity: Parity configuration. It can be None (no parity), 0 (even) or 1 (odd).
        :param stop: Number of stop bits. It can be 1 or 2.
        :param tx_pin: Specify the TX PIN to use.
        :param rx_pin: Specify the RX PIN to use.
        :param timeout: Specify the time to wait for the first character in seconds.
        :param timeout_char: Specify the time to wait between characters in seconds.
        :param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.execute`.
        """
        code = '''
args = {
    'bits': {bits},
    'parity': {parity},
    'stop': {stop},
}

if {tx_pin}:
    args['tx'] = {tx_pin}
if {rx_pin}:
    args['rx'] = {rx_pin}
if {timeout}:
    args['timeout'] = {timeout}
if {timeout_char}:
    args['timeout_char'] = {timeout_char}
'''.format(bits=bits, parity=parity, stop=stop, tx_pin=tx_pin, rx_pin=rx_pin,
           timeout=timeout, timeout_char=timeout_char)

        self.execute(code, **kwargs)

        code = '''
import machine
uart = machine.UART({id}, {baudrate}, **args)
'''.format(id=id, baudrate=baudrate)

        self.execute(code, **kwargs) 
开发者ID:BlackLight,项目名称:platypush,代码行数:45,代码来源:__init__.py


注:本文中的machine.UART属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。