pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

RS485

Example

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)

API

RS485_0.init(1, baudrate=9600, data_bits=8, stop_bits=1, parity=None, ctrl_pin=None)
  • Initialize RS485 Unit
    • UART:1/2
    • Baudrate:value
    • Data Bits:7/8/9
    • Stop Bits:1/2
    • Parity:None/Even/Odd
    • Ctrl pin
print(RS485_0.any())
  • Retrieve Buffer
print(RS485_0.read())
  • Retrieve All Received Data
print(RS485_0.readline())
  • Retrieve One Line of Received Data
print(RS485_0.read(10))
  • Read Character
print(RS485_0.read_coils(1, 1, 0))
  • Read Coil from Address
print(RS485_0.read_discrete_inputs(1, 1, 0))
  • Read Discrete Input
print(RS485_0.read_holding_registers(1, 1, 0, True))
  • Read Holding Register
print(RS485_0.read_input_registers(1, 1, 0, True))
  • Read Input Register
RS485_0.write('')
  • Write String to Serial Port
RS485_0.write(''+"\r\n")
  • Write One Line String to Serial Port
print(RS485_0.write_multiple_coils(1, 1, 0))
  • Retrieve Addresses for Writing Multiple Coils
print(RS485_0.write_multiple_registers(1, 1, 0, True))
  • Retrieve Addresses for Writing Multiple Holding Registers
RS485_0.write(bytes([0, 0, 0]))
  • Write Raw Data to Serial Port
print(RS485_0.write_single_coil(1, 1, 0))
  • Retrieve Address for Writing Single Coil
print(RS485_0.write_single_register(1, 1, 0, True))
  • Retrieve Address for Writing Single Holding Register
On This Page