pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

RS485

案例程序

from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit

setScreenColor(0x222222)
RS485_0 = unit.get(unit.RS485, unit.PORTC)

RS485_0.init(1, baudrate=9600, data_bits=8, stop_bits=1, parity=None, ctrl_pin=None)
while True:
  RS485_0.write('Hello M5Stack')
  print((str('Msg:') + str((RS485_0.read()))))
  wait(1)
  wait_ms(2)

功能说明

RS485_0.init(1, baudrate=9600, data_bits=8, stop_bits=1, parity=None, ctrl_pin=None)
  • 初始化Unit RS485
    • UART:1/2
    • Baudrate:value
    • Data Bits:7/8/9
    • Stop Bits:1/2
    • Parity:None/Even/Odd
    • Ctrl pin
print(RS485_0.any())
  • 获取缓存
print(RS485_0.read())
  • 获取所有接收数据
print(RS485_0.readline())
  • 获取一行接收数据
print(RS485_0.read(10))
  • 读取字符
print(RS485_0.read_coils(1, 1, 0))
  • 读取线圈从地址
print(RS485_0.read_discrete_inputs(1, 1, 0))
  • 读取离散输入
print(RS485_0.read_holding_registers(1, 1, 0, True))
  • 读取保持寄存器
print(RS485_0.read_input_registers(1, 1, 0, True))
  • 读取输入寄存器
RS485_0.write('')
  • 串口写入字符串
RS485_0.write(''+"\r\n")
  • 串口写入一行字符串
print(RS485_0.write_multiple_coils(1, 1, 0))
  • 获取写入多个线圈地址
print(RS485_0.write_multiple_registers(1, 1, 0, True))
  • 获取写入多个保持寄存器地址
RS485_0.write(bytes([0, 0, 0]))
  • 串口写入原始数据
print(RS485_0.write_single_coil(1, 1, 0))
  • 获取写入单个线圈地址
print(RS485_0.write_single_register(1, 1, 0, True))
  • 获取写入单个保持寄存器
On This Page