Microbit 串行端口 (UART) 接口
The Microbit_Uart
sensor provides the ability to read from and write strings to the BBC micro:bit’s serial UART port.
Properties
Methods
RequestTXCharacteristic
– Requests notifications of messages received from the micro:bit’s serial UART. New messages will be received through theTXCharacteristicReceived
event.
StopTXCharacteristicUpdates
– Stops receiving updates from the micro:bit’s serial UART. Note that there may be pending messages from the device that will still be reported through theTXCharacteristicReceived
event.
WriteRXCharacteristic
– Writes the given valueUART_TX
to the micro:bit. The size of the message will depend on the value ofUART_TX
. Numbers will be converted to integers and sent as 32-bit integer values. Strings will be encoded using UTF-8. Lists of objects will be sent as a sequence of bytes using the aforementioned rules for numbers and strings.
Parameters:
* <code>UART_TX</code> (_any_) —
The value to transmit to the RX "pin" of the micro:bit. Strings will be encoded as UTF-8,
numbers will be sent as 32-bit integers. Lists of values will be converted into be
converted into a sequence of bytes depending on the type of each value in the list.
Events
TXCharacteristicReceived
– TheTXCharacteristicReceived
event is run whenever messages are received over the micro:bit’s serial UART protocol.
Parameters:
* <code>UART_TX_FIELD</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/listsU.html#makealist">_list_</a>) —
A list of unsigned byte values read from the device.
WroteRXCharacteristic
– TheWroteRXCharacteristic
event is run after a message is written to the micro:bit via its serial UART.
Parameters:
* <code>UART_TX_FIELD</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/listsU.html#makealist">_list_</a>) —
A list of unsigned byte values written to the device.