|
@@ -7,6 +7,7 @@ import com.google.gson.Gson;
|
|
|
import com.naz.sdkdemo.bean.UserDetail;
|
|
|
import com.naz.sdkdemo.comm.Constants;
|
|
|
import com.naz.sdkdemo.utils.SPUtils;
|
|
|
+import java.io.File;
|
|
|
|
|
|
import android_serialport_api.SerialPortFinder;
|
|
|
|
|
@@ -90,7 +91,10 @@ public class UserCache extends SPUtils {
|
|
|
}
|
|
|
|
|
|
public static String getSerialName() {
|
|
|
+
|
|
|
SerialPortFinder finder = new SerialPortFinder();
|
|
|
+
|
|
|
+ searchDevDirectory(new File("/dev"));
|
|
|
if (finder.getAllDevicesPath().length>0){
|
|
|
for (int i = 0; i < finder.getAllDevicesPath().length; i++) {
|
|
|
Log.e("------------>","---------->finder.getAllDevicesPath("+i+")="+finder.getAllDevicesPath()[i]);
|
|
@@ -101,4 +105,23 @@ public class UserCache extends SPUtils {
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
+
|
|
|
+ private static void searchDevDirectory(File directory) {
|
|
|
+ if (directory.isDirectory()) {
|
|
|
+ File[] files = directory.listFiles();
|
|
|
+ if (files != null) {
|
|
|
+ for (File file : files) {
|
|
|
+ if (file.isDirectory()) {
|
|
|
+ // 递归搜索子目录
|
|
|
+ searchDevDirectory(file);
|
|
|
+ } else {
|
|
|
+ // 检查是否是串口设备文件
|
|
|
+ if (file.getAbsolutePath().startsWith("/dev/tty")) {
|
|
|
+ System.out.println("Serial port found: " + file.getAbsolutePath());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|