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


Python UART.readline方法代码示例

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


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

示例1: JYMCU

# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import readline [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

示例2: print

# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import readline [as 别名]
reason=upower.why()   # motivo dell'uscita da low power mode.
                      # see upower.py module documentation.

uart.write(str(reason) +'\n')

#reason='ALARM_B'     # solo per debug
try:
    if reason=='X1':
       verde.on()
       pyb.delay(3)
       verde.off()
       uart.write('ready'+'\n') # uscito da standby - standby exit.
       while test==0:
          inBuffer_rx=""
          if uart.any(): 
             inBuffer_rx=uart.readline()
             print(inBuffer_rx)
             inBuffer_chr=""

             if inBuffer_rx!='':
                inBuffer_chr=inBuffer_rx.decode()
             if inBuffer_chr=='connecting':
                print('connecting')
                uart.write('sono connesso!'+'\n') # uscito da standby - standby exit.
                restore_data()
                sa=leggi_sonda_a()
                pkl['in_sonda_a']=int(sa)
                sb=leggi_sonda_b()
                pkl['in_sonda_b']=int(sb)
                uart.write(str(pkl)+'\n') # invia dati a host - send data to host.  
开发者ID:BOB63,项目名称:My-uPy-Gardener,代码行数:32,代码来源:irrigatoreBT.V07.py

示例3: Switch

# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import readline [as 别名]
#create switch object
big_red_button = Switch()
big_red_button.callback(start)

finished = False
 

#########################
#       Main Loop       #
#########################
 
while finished == False: #While loop that loops forever

	if hc12.any(): 
		data = hc12.readline()
		data = data.decode('utf-8')

		dataArray = data.split(',')   #Split it into an array called dataArray

		if dataArray[0] == 'end':
			green.off()
			sleep(0.5)
			green.on()
			sleep(0.5)
			green.off()
			finished == True
		elif len(dataArray) == 6:
			tagx = dataArray[0]
			temp = dataArray[1]
			pres = dataArray[2]
开发者ID:aurorasat,项目名称:cansataurora,代码行数:32,代码来源:lumos2_receiver.py

示例4: print

# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import readline [as 别名]
print(uart0.read(2) == b'23')
print(uart0.read() == b'')

uart0.write(b'123')
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)
开发者ID:rubencabrera,项目名称:micropython,代码行数:33,代码来源:uart.py

示例5: print

# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import readline [as 别名]
from pyb import UART
import network
import socket

if __name__ == "__main__":
    nic = network.CC3K(pyb.SPI(2), pyb.Pin.board.Y5, pyb.Pin.board.Y4, pyb.Pin.board.Y3)
    nic.connect('Joi', 'deadbeef')
    while not nic.isconnected():
        pyb.delay(50)
    print(nic.ifconfig())

    uart = UART(1, 9600)
    addr = ('192.168.1.242', 9999)
    while True:
        s = socket.socket()
        s.connect(addr)
        s.send(b"Hello\r\n")
        while True:
            try:
                incoming = "" 
                incoming = s.recv(1024)
                uart.write("%s\r"%incoming.decode().strip())
                while uart.any():
                    serialdata = uart.readline()
                    s.send("%s\n"%serialdata.decode().strip())
            except:
                print("error")
                break
        s.close()

开发者ID:johannfr,项目名称:fillinn,代码行数:31,代码来源:connectToNetwork.py


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