We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I am getting error of: The getter 'address' was called on null. Bluetooth connection to a device
import 'dart:convert'; import 'dart:typed_data';
import 'package:flutter_bluetooth_serial/flutter_bluetooth_serial.dart';
class Obd { BluetoothConnection connection; String address; String _messageBuffer = '';
void initObd(address) { BluetoothConnection.toAddress(address).then((_connection) { print('Connected to the device'); connection = _connection;
connection.input.listen(_onDataReceived).onDone(() { print("Is Connected: " + _connection.isConnected.toString()); }); }).catchError( (error) { print('Cannot connect, exception occured'); print(error); }, );
}
void _onDataReceived(Uint8List data) { // Allocate buffer for parsed data
int backspacesCounter = 0; data.forEach((byte) { print(byte); if (byte == 8 || byte == 127) { backspacesCounter++; } }); Uint8List buffer = Uint8List(data.length - backspacesCounter); int bufferIndex = buffer.length; // Apply backspace control character backspacesCounter = 0; for (int i = data.length - 1; i >= 0; i--) { if (data[i] == 8 || data[i] == 127) { backspacesCounter++; } else { if (backspacesCounter > 0) { backspacesCounter--; } else { buffer[--bufferIndex] = data[i]; } } } // Create message if there is new line character String dataString = String.fromCharCodes(buffer); int index = buffer.indexOf(13); if (~index != 0) { _messageBuffer = dataString.substring(index); print("////////////////////////1"); print(index); print("////////////////////////"); } else { _messageBuffer = (backspacesCounter > 0 ? _messageBuffer.substring( 0, _messageBuffer.length - backspacesCounter) : _messageBuffer + dataString); print("////////////////////////2"); print(_messageBuffer); print("////////////////////////"); }
void sendMessage(String text) async { print(text); text = text.trim(); print(text);
if (text.length > 0) { try { connection.output.add(utf8.encode("1")); await connection.output.allSent; print("ll"); } catch (e) { print(e); // Ignore error, but notify state } print("Send Successfully"); }
} }
The text was updated successfully, but these errors were encountered:
Duplicate of #131
Sorry, something went wrong.
No branches or pull requests
I am getting error of:
The getter 'address' was called on null. Bluetooth connection to a device
import 'dart:convert';
import 'dart:typed_data';
import 'package:flutter_bluetooth_serial/flutter_bluetooth_serial.dart';
class Obd {
BluetoothConnection connection;
String address;
String _messageBuffer = '';
void initObd(address) {
BluetoothConnection.toAddress(address).then((_connection) {
print('Connected to the device');
connection = _connection;
}
void _onDataReceived(Uint8List data) {
// Allocate buffer for parsed data
}
void sendMessage(String text) async {
print(text);
text = text.trim();
print(text);
}
}
The text was updated successfully, but these errors were encountered: