rpi_serial is a Dart package for using serial communication on the Raspberry Pi.
Be sure to enable serial on the Raspberry Pi using
Also make sure to disable the console on the serial port.
RpiSerial uses a native library written in C. For security reasons, authors cannot publish binary content to pub.dev, so there are some extra steps necessary to compile the native library on the RPi before this package can be used. These two steps must be performed when you install and each time you upgrade the rpi_serial package.
- Activate the rpi_serial package using the pub global command.
pub global activate rpi_serial
- From your application directory (the application that references the rpi_serial package) run the following command to build the native library
pub global run rpi_serial:build_lib
- Deactivate the rpi_serial package.
pub global deactivate rpi_serial
pub global activate makes the Dart scripts in the rpi_serial/bin directory runnable from the command line. pub global run rpi_serial:build_lib runs the rpi_serial/bin/build_lib.dart program which in turn calls the build_lib script to compile the native librpi_serial_ext.so library for the rpi_serial package.
Refer to Raspberry Pi GPIO for connecting your serial device to the Raspberry Pi. By default pins 8 is TX and 10 is RX on the GPIO header.
Note that the Raspberry Pi actually has two UARTs. On the versions with Bluetooth (Raspberry Pi 3 and Raspberry Pi Zero W), the UART exposed to the GPIO pins is "/dev/ttyS0", while it is "/dev/ttyAMA0" on the rest of the boards. This can be changed (see Rapsberry Pi UART configuration). On the compute module, you can supposedly expose both serial interfaces on the GPIO.
basic_device is a class containing most of the basic features that you would need to comunicate with a serial device. This is implemented using the API (Serial). No low-level interactions required. If you want to communicate with another device, you should probably create a similar class, but specific to that device.
Hopefully the examples are pretty self-explanatory.