bytesToString static method
Convert bytes to ASCII string.
Parameters:
bytes: Byte array containing ASCII characterstrimNull: Remove null terminators (default: true)
Returns: ASCII string
Example:
final bytes = await client.readHoldingRegistersBytes(1, 300, 10);
final deviceName = DataConverter.bytesToString(bytes);
Implementation
static String bytesToString(Uint8List bytes, {bool trimNull = true}) {
if (trimNull) {
final nullIndex = bytes.indexOf(0);
if (nullIndex >= 0) {
bytes = bytes.sublist(0, nullIndex);
}
}
return String.fromCharCodes(bytes);
}