Microbit 串行端口 (UART) 接口

« 返回首页

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

  • BluetoothDevice – The BluetoothLE component connected to the micro:bit device (setter).

get Microbit_Uart1 BluetoothDevice

set Microbit_Uart1 BluetoothDevice  to

Methods

  • RequestTXCharacteristic – Requests notifications of messages received from the micro:bit’s serial UART. New messages will be received through the TXCharacteristicReceived event.

call Microbit_Uart1 RequestTXCharacteristic

  • 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 the TXCharacteristicReceived event.

call Microbit_Uart1 StopTXCharacteristicUpdates

  • WriteRXCharacteristic – Writes the given value UART_TX to the micro:bit. The size of the message will depend on the value of UART_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_) &mdash;
   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.

call Microbit_Uart1 WriteRXCharacteristicUART_TX

Events

  • TXCharacteristicReceived – The TXCharacteristicReceived 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>) &mdash;
   A list of unsigned byte values read from the device.

when Microbit_Uart1 TXCharacteristicReceived UART_TX_Field do

  • WroteRXCharacteristic – The WroteRXCharacteristic 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>) &mdash;
   A list of unsigned byte values written to the device.

when Microbit_Uart1 WroteRXCharacteristic UART_TX_Field do