writeBytes method

int writeBytes(
  1. MraaUartContext dev,
  2. MraaUartBuffer buffer,
  3. int length
)

Write bytes - mraa_uart_write

Write bytes to the device from a buffer. Returns the number of bytes written, or Mraa.generalError

Implementation

int writeBytes(MraaUartContext dev, MraaUartBuffer buffer, int length) {
  if (length <= 0) {
    return Mraa.generalError;
  }
  if (buffer.byteData.isEmpty || buffer.byteLength < length) {
    return Mraa.generalError;
  }
  final ptrBuffer = ffi.calloc.allocate<Char>(length);
  final typedBuffer = ptrBuffer.cast<Uint8>().asTypedList(length);
  typedBuffer.setAll(0, buffer.byteData);
  final ret = _impl.mraa_uart_write(dev, ptrBuffer, length);
  ffi.calloc.free(ptrBuffer);
  return ret;
}