From cdcee5e2fd5f3f6ac38e7ad6bb3260742e836bc6 Mon Sep 17 00:00:00 2001 From: lyw <刘耀文@DESKTOP-E1TI268> Date: Tue, 26 Mar 2024 18:24:50 +0800 Subject: [PATCH] cypf --- app/src/main/AndroidManifest.xml | 2 ++ .../modules/home/fragment/MakeGoodFragment.java | 8 ++++++-- .../modules/home/fragment/mode/ShaoMaSave.java | 15 +++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ef9c78ee..9fb80475 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,6 +18,7 @@ + + \ No newline at end of file diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java index 481e3f2d..0de71e8a 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java @@ -73,6 +73,7 @@ import com.bonait.bnframework.modules.home.adapter.loadinggood_adapter; import com.bonait.bnframework.modules.home.adapter.wl_adapter; import com.bonait.bnframework.modules.home.fragment.mode.SerialInter; import com.bonait.bnframework.modules.home.fragment.mode.SerialManage; +import com.bonait.bnframework.modules.home.fragment.mode.ShaomaTest; import com.bonait.bnframework.modules.home.fragment.mode.add_makegood_control; import com.bonait.bnframework.modules.home.fragment.mode.add_manguan_control; import com.bonait.bnframework.modules.home.fragment.mode.add_pf_control; @@ -191,7 +192,10 @@ public class MakeGoodFragment extends BaseFragment { initTopBar(); Initdata(); Run(); - SerialManage.GetInstance().init(new SerialInter() { + + + ShaomaTest.Getinstance().Open(activity,this.context); + /* SerialManage.GetInstance().init(new SerialInter() { @Override public void connectMsg(String path, boolean isSucc) { activity.runOnUiThread(new Runnable() { @@ -219,7 +223,7 @@ public class MakeGoodFragment extends BaseFragment { } }); //扫码串口连接 - SerialManage.GetInstance().Open("/dev/ttyS4",9600,true); + SerialManage.GetInstance().Open("/dev/ttyS4",9600,true);*/ } public List Fdata = new ArrayList<>(); diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/ShaoMaSave.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/ShaoMaSave.java index 53d6f96c..adae439b 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/ShaoMaSave.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/ShaoMaSave.java @@ -5,12 +5,14 @@ import android.serialport.SerialPort; import android.util.Log; import com.serotonin.modbus4j.serial.SerialMessage; +import com.serotonin.modbus4j.sero.util.ArrayUtils; import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.reflect.Array; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -99,10 +101,15 @@ public class ShaoMaSave implements Runnable{ /*int available = inputStream.available(); if (available == 0) continue;*/ if (inputStream == null) continue; - byte[] received = new byte[1024]; - int size = inputStream.read(received); - if (size>0&&serialInter!=null) - serialInter.readData(path,received,size); + byte[] received = new byte[1]; + String x=""; + int t = 1; + while (t>0){ + t= inputStream.read(received); + x+=new String(received); + } + if (x!="") + serialInter.readData(path,received,t); Thread.sleep(20); }catch (InterruptedException e){ Log.e(Tag,"线程异常"+e.toString());