本文整理汇总了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()
示例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)
示例3: __init__
# 需要导入模块: import machine [as 别名]
# 或者: from machine import UART [as 别名]
def __init__(self):
self.uart = machine.UART(2, baudrate=115200, tx=17, rx=-2)
示例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''
示例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)
示例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()
示例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()
示例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)
示例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()
示例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()
示例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))
示例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)
示例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
示例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()
示例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)