admin管理员组文章数量:1025227
before the problem, i already tested/debug using window application and open/read like COM3 or COM5 and it worked perfectly but as ANDROID platform which was installed in a android device it returned "SerialPortError: No such file or directory, errno = 2", before initialized surely i listed the open ports first such as /dev/ttyS3.
my androidmanifest.xml
<manifest xmlns:android=";>
<!-- Add USB permission before the <application> element -->
<uses-permission android:name="android.permission.SERIAL_PORT"/>
<uses-permission android:name="android.permission.USB" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.USB_PERMISSION" />
<uses-feature android:name="android.hardware.usb.host" android:required="true" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="com.google.android.things.permission.USE_PERIPHERAL_IO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
...
my main
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")),
);
}
before the problem, i already tested/debug using window application and open/read like COM3 or COM5 and it worked perfectly but as ANDROID platform which was installed in a android device it returned "SerialPortError: No such file or directory, errno = 2", before initialized surely i listed the open ports first such as /dev/ttyS3.
my androidmanifest.xml
<manifest xmlns:android=";>
<!-- Add USB permission before the <application> element -->
<uses-permission android:name="android.permission.SERIAL_PORT"/>
<uses-permission android:name="android.permission.USB" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.USB_PERMISSION" />
<uses-feature android:name="android.hardware.usb.host" android:required="true" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="com.google.android.things.permission.USE_PERIPHERAL_IO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
...
my main
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")),
);
}
本文标签:
版权声明:本文标题:Android, flutter,dart, flutter, flutter_libserialport 0.4, error : SerialPortError: No such file or directory, errno = 2 - Stack 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1737164245a1447954.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论