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


Python UART.readall方法代码示例

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


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

示例1: __init__

# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import readall [as 别名]
class WIFI:
  """docstring for wifi"""

  def __init__(self, uart, baudrate = 115200):
    """ uart = uart #1-6, baudrate must match what is set on the ESP8266. """
    self._uart = UART(uart, baudrate)

  def write( self, aMsg ) :
    self._uart.write(aMsg)
    res = self._uart.readall()
    if res:
      print(res.decode("utf-8"))

  def read( self ) : return self._uart.readall().decode("utf-8")

  def _cmd( self, cmd ) :
    """ Send AT command, wait a bit then return results. """
    self._uart.write("AT+" + cmd + "\r\n")
    udelay(500)
    return self.read()

  @property
  def IP(self): return self._cmd("CIFSR")

  @property
  def networks( self ) : return self._cmd("CWLAP")

  @property
  def baudrate(self): return self._cmd("CIOBAUD?")

  @baudrate.setter
  def baudrate(self, value): return self._cmd("CIOBAUD=" + str(value))

  @property
  def mode(self): return self._cmd("CWMODE?")

  @mode.setter
  def mode(self, value): self._cmd("CWMODE=" + str(value))

  def connect( self, ssid, password = "" ) :
    """ Connect to the given network ssid with the given password """
    constr = "CWJAP=\"" + ssid + "\",\"" + password + "\""
    return self._cmd(constr)

  def disconnect( self ) : return self._cmd("CWQAP")

  def reset( self ) : return self._cmd("RST")
开发者ID:rolandvs,项目名称:GuyCarverMicroPythonCode,代码行数:49,代码来源:ESP8266.py

示例2: ESP8266

# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import readall [as 别名]
class ESP8266(object):

    def __init__(self):
        self.uart = UART(6, 115200)
    
    def write(self, command):
        self.uart.write(command)
        count = 5
        while count >= 0:
            if self.uart.any():
                print(self.uart.readall().decode('utf-8'))
            time.sleep(0.1)
            count-=1
开发者ID:hiroki8080,项目名称:micropython,代码行数:15,代码来源:esp8266.py

示例3: JYMCU

# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import readall [as 别名]
class JYMCU(object):
  """JY-MCU Bluetooth serial device driver.  This is simply a light UART wrapper
     with addition AT command methods to customize the device."""

  def __init__( self, uart, baudrate ):
    """ uart = uart #1-6, baudrate must match what is set on the JY-MCU.
        Needs to be a #1-C. """
    self._uart = UART(uart, baudrate)

  def __del__( self ) : self._uart.deinit()

  def any( self ) : return self._uart.any()

  def write( self, astring ) : return self._uart.write(astring)
  def writechar( self, achar ) : self._uart.writechar(achar)

  def read( self, num = None ) : return self._uart.read(num)
  def readline( self ) : return self._uart.readline()
  def readchar( self ) : return self._uart.readchar()
  def readall( self ) : return self._uart.readall()
  def readinto( self, buf, count = None ) : return self._uart.readinto(buf, count)

  def _cmd( self, cmd ) :
    """ Send AT command, wait a bit then return result string. """
    self._uart.write("AT+" + cmd)
    udelay(500)
    return self.readline()

  def baudrate( self, rate ) :
    """ Set the baud rate.  Needs to be #1-C. """
    return self._cmd("BAUD" + str(rate))

  def name( self, name ) :
    """ Set the name to show up on the connecting device. """
    return self._cmd("NAME" + name)

  def pin( self, pin ) :
    """ Set the given 4 digit numeric pin. """
    return self._cmd("PIN" + str(pin))

  def version( self ) : return self._cmd("VERSION")

  def setrepl( self ) : repl_uart(self._uart)
开发者ID:rolandvs,项目名称:GuyCarverMicroPythonCode,代码行数:45,代码来源:JYMCU.py

示例4: command

# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import readall [as 别名]
class BLE:
    BLE_NONE=0
    BLE_SHIELD=1

    def command(self, cmd):
        if self.type==self.BLE_SHIELD:
            self.uart.write(cmd)
            self.uart.write("\r\n")
            r=self.uart.read(9)
            if r[0]!=82: raise OSError("Response corrupted!")
            if r[1]==49: raise OSError("Command failed!")
            if r[1]==50: raise OSError("Parse error!")
            if r[1]==51: raise OSError("Unknown command!")
            if r[1]==52: raise OSError("Too few args!")
            if r[1]==53: raise OSError("Too many args!")
            if r[1]==54: raise OSError("Unknown variable or option!")
            if r[1]==55: raise OSError("Invalid argument!")
            if r[1]==56: raise OSError("Timeout!")
            if r[1]==57: raise OSError("Security mismatch!")
            if r[1]!=48: raise OSError("Response corrupted!")
            for i in range(2,6):
                if r[i]<48 or 57<r[i]: raise OSError("Response corrupted!")
            if r[7]!=13 or r[8]!=10: raise OSError("Response corrupted!")
            l=((r[2]-48)*10000)+\
              ((r[3]-48)*1000)+\
              ((r[4]-48)*100)+\
              ((r[5]-48)*10)+\
              ((r[6]-48)*1)
            if not l: return None
            if l==1 or l==2: raise OSError("Response corrupted!")
            response=self.uart.read(l-2)
            if self.uart.readchar()!=13: raise OSError("Response corrupted!")
            if self.uart.readchar()!=10: raise OSError("Response corrupted!")
            return response

    def deinit(self):
        if self.type==self.BLE_SHIELD:
            self.uart.deinit()
            self.rst=None
            self.uart=None
            self.type=self.BLE_NONE

    def init(self, type=BLE_SHIELD):
        self.deinit()
        if type==self.BLE_SHIELD:
            self.rst=Pin("P7",Pin.OUT_OD,Pin.PULL_NONE)
            self.uart=UART(3,115200,timeout_char=1000)
            self.type=self.BLE_SHIELD
            self.rst.low()
            sleep(100)
            self.rst.high()
            sleep(100)
            self.uart.write("set sy c m machine\r\nsave\r\nreboot\r\n")
            sleep(1000)
            self.uart.readall() # clear

    def uart(self):
        if self.type==self.BLE_SHIELD: return self.uart

    def type(self):
        if self.type==self.BLE_SHIELD: return self.BLE_SHIELD

    def __init__(self):
        self.rst=None
        self.uart=None
        self.type=self.BLE_NONE
开发者ID:Killercotton,项目名称:OpenMV_medialab,代码行数:68,代码来源:ble.py

示例5: bytearray

# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import readall [as 别名]
buf = bytearray(3)
print(uart1.readinto(buf, 1) == 1) 
print(buf)
print(uart1.readinto(buf) == 2)
print(buf)

# try initializing without the id
uart0 = UART(baudrate=1000000, pins=uart_pins[0][0])
uart0.write(b'1234567890')
pyb.delay(2) # because of the fifo interrupt levels
print(uart1.any() == 10)
print(uart1.readline() == b'1234567890')
print(uart1.any() == 0)

uart0.write(b'1234567890')
print(uart1.readall() == b'1234567890')

# tx only mode
uart0 = UART(0, 1000000, pins=('GP12', None))
print(uart0.write(b'123456') == 6)
print(uart1.read() == b'123456')
print(uart1.write(b'123') == 3)
print(uart0.read() == b'')

# rx only mode
uart0 = UART(0, 1000000, pins=(None, 'GP13'))
print(uart0.write(b'123456') == 6)
print(uart1.read() == b'')
print(uart1.write(b'123') == 3)
print(uart0.read() == b'123')
开发者ID:rubencabrera,项目名称:micropython,代码行数:32,代码来源:uart.py


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