最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Android, flutter,dart, flutter, flutter_libserialport 0.4, error : SerialPortError: No such file or directory, errno = 2 - Stack

programmeradmin9浏览0评论

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")),
            );
          }

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论