meine androidmanifest.xml
Code: Select all
...
Code: Select all
Communication(String testPort) {
port = SerialPort(testPort);
port.config = SerialPortConfig()
..baudRate = 38400
..stopBits = 1
..parity = SerialPortParity.none
..bits = 8;
}
try {
// Ensure the Communication initialization is async and handle errors properly
communication = await Communication(portName); // Ensure async initialization
// if (communication.port) {
print("Communication initialized with port: ${communication!.port}");
print("Port name: ${communication!.port.name}"); // Output port name (e.g., COM5)
// Try opening the port
try {
bool isOpened = communication!.port.openReadWrite(); // Attempt to open the port for reading and writing
if (isOpened) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Port opened successfully")),
);
print("Port opened successfully.");
} else {
print("Failed to open port.");
_showErrorDialog();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Failed to open port: ${communication!.port.name}")),
);
}
} catch (e) {
print("Error opening port: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Error opening port: $e")),
);
}
Mobile version