Explorar el Código

现场调试改动1003333

调味吧台(白底)
fyf hace 1 año
padre
commit
974635dcd9
Se han modificado 4 ficheros con 129 adiciones y 6 borrados
  1. +5
    -1
      app/src/main/java/com/example/bpa/helper/ByteHelper.java
  2. +33
    -1
      app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java
  3. +29
    -1
      app/src/main/java/com/example/bpa/service/DeviceData.java
  4. +62
    -3
      app/src/main/java/com/example/bpa/view/fragment/SsjkFragment.java

+ 5
- 1
app/src/main/java/com/example/bpa/helper/ByteHelper.java Ver fichero

@@ -127,6 +127,10 @@ public class ByteHelper {
}
return byteArray;
}

//b为传入的字节,i为第几位(范围0-7),如要获取bit0,则i=0
public static int getBit(byte b,int i) {
int bit = (int) ((b >> i) & 0x1);
return bit;
}

}

+ 33
- 1
app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java Ver fichero

@@ -284,7 +284,39 @@ public class ModbusTcpServer {
}

/***
*读取整形数据
*读取实时状态
* @param Address the address
* @param length 读取的长度 3
* @param callback 读取成功的回调
*/
public void ReadStatus(String Address, int length, IReadCallBack<byte[]> callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length);
byte[] data = res.getData();
byte[] tempData=new byte[6];
tempData[0]=data[1];
tempData[1]=data[0];
tempData[2]=data[3];
tempData[3]=data[2];
tempData[4]=data[5];
tempData[5]=data[4];
if(callback!=null) callback.onSuccess(tempData);
} catch (InterruptedException e) {
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
} catch (ExecutionException e) {
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
} catch (ModbusTransportException e) {
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
} catch (ModbusInitException e) {
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
} catch (ModbusRespException e) {
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
}
}
/***
*读取扫码数据
* @param Address the address
* @param length 读取的长度
* @param callback 读取成功的回调


+ 29
- 1
app/src/main/java/com/example/bpa/service/DeviceData.java Ver fichero

@@ -4,6 +4,7 @@ import com.example.bpa.Model.IRun;
import com.example.bpa.Model.IRunT;
import com.example.bpa.Model.IThread;
import com.example.bpa.Model.IWriteCallBack;
import com.example.bpa.helper.ByteHelper;
import com.example.bpa.helper.MessageLog;
import com.example.bpa.helper.ModbusTcpServer;
import com.example.bpa.helper.RTrig;
@@ -108,6 +109,11 @@ public class DeviceData {
WeightCalibrationMode = booleans[0];
});

ModbusTcpServer.get().ReadBool("M6.5", 1, booleans -> {
WeightCalibrationMode = booleans[0];
});
//IoStatus

//读取1号果糖机按钮状态
ModbusTcpServer.get().ReadBool("M51.7", 1, booleans -> {
ReheatSwitch1 = booleans[0];
@@ -136,6 +142,17 @@ public class DeviceData {
//4.回馈订单信息
});

//读取实时状态
ModbusTcpServer.get().ReadStatus("VW200", 3, data -> {
for (int i = 0; i < data.length; i++) {
byte status=data[i];//0x92
IoStatus.put(i*4+1, ByteHelper.getBit(status,0)==1);
IoStatus.put(i*4+2, ByteHelper.getBit(status,1)==1);
IoStatus.put(i*4+3, ByteHelper.getBit(status,2)==1);
IoStatus.put(i*4+4, ByteHelper.getBit(status,3)==1);
}
});

//配料完成 M0.3
CompleteListen("M0.3", "配料完成", OnChargeMixtureCompleteNotify);

@@ -856,7 +873,18 @@ public class DeviceData {
/**
* 实时状态
*/
ConcurrentHashMap<Integer, Boolean> IoStatus = new ConcurrentHashMap<Integer, Boolean>();
public ConcurrentHashMap<Integer, Boolean> IoStatus = new ConcurrentHashMap<Integer, Boolean>();
/**
* 获取实时状态
* @param ch
* @return
*/
public boolean getConcurrentHash(int ch) {
if (!IoStatus.containsKey(ch)) {
return false;
}
return IoStatus.get(ch);
}
//endregion
/**
* 设置8路称校准砝码重量


+ 62
- 3
app/src/main/java/com/example/bpa/view/fragment/SsjkFragment.java Ver fichero

@@ -9,14 +9,20 @@ import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.bpa.R;
import com.example.bpa.config.ConfigName;
import com.example.bpa.config.DataBus;
import com.example.bpa.helper.MessageLog;
import com.example.bpa.helper.WrapContentLinearLayoutManager;
import com.example.bpa.service.DeviceData;
import com.example.bpa.view.adapter.devstatus_adapter;
import com.example.bpa.view.adapter.maingoods_adapter;
import com.example.bpa.view.adapter.makegood_adapter;
@@ -24,12 +30,14 @@ import com.example.bpa.view.control.MyLayoutManager;
import com.example.bpa.view.fragment.setting.mqttparameter;
import com.example.bpa.view.fragment.setting.ovarparameter;
import com.example.bpa.view.fragment.setting.systemparameter;
import com.example.bpa.view.from.lsjy_activity;
import com.example.bpa.view.mode.StatusMode;

import java.util.ArrayList;

public class SsjkFragment extends Fragment implements View.OnClickListener {

Activity activity=null;
View view;
RecyclerView recyclerView;

@@ -52,9 +60,12 @@ public class SsjkFragment extends Fragment implements View.OnClickListener {
recyclerView.setLayoutManager(layout);
adapter = new devstatus_adapter(getContext());
recyclerView.setAdapter(adapter);

activity=findActivity(view.getContext());
}

private void initEvent() {
//

}
/**
@@ -64,19 +75,19 @@ public class SsjkFragment extends Fragment implements View.OnClickListener {
{
try{
DataBus.getInstance().statusModes=new ArrayList<>();
DataBus.getInstance().statusModes.add(new StatusMode("杯子检测",R.mipmap.gd1,R.mipmap.gd2,true));
DataBus.getInstance().statusModes.add(new StatusMode("杯子检测",R.mipmap.gd1,R.mipmap.gd2,false));
DataBus.getInstance().statusModes.add(new StatusMode("蠕动泵(一)",R.mipmap.rdl1,R.mipmap.rdl2,false));
DataBus.getInstance().statusModes.add(new StatusMode("蠕动泵(二)",R.mipmap.rdl1,R.mipmap.rdl2,false));
DataBus.getInstance().statusModes.add(new StatusMode("蠕动泵(三)",R.mipmap.rdl1,R.mipmap.rdl2,false));
DataBus.getInstance().statusModes.add(new StatusMode("蠕动泵(四)",R.mipmap.rdl1,R.mipmap.rdl2,false));
DataBus.getInstance().statusModes.add(new StatusMode("蠕动泵(五)",R.mipmap.rdl1,R.mipmap.rdl2,false));
DataBus.getInstance().statusModes.add(new StatusMode("果糖泵(左)",R.mipmap.rdl1,R.mipmap.rdl2,true));
DataBus.getInstance().statusModes.add(new StatusMode("果糖泵(左)",R.mipmap.rdl1,R.mipmap.rdl2,false));
DataBus.getInstance().statusModes.add(new StatusMode("果糖泵(右)",R.mipmap.rdl1,R.mipmap.rdl2,false));

DataBus.getInstance().statusModes.add(new StatusMode("离心泵(一)",R.mipmap.lxl1,R.mipmap.lxl2,false));
DataBus.getInstance().statusModes.add(new StatusMode("离心泵(二)",R.mipmap.lxl1,R.mipmap.lxl2,false));
DataBus.getInstance().statusModes.add(new StatusMode("离心泵(三)",R.mipmap.lxl1,R.mipmap.lxl2,false));
DataBus.getInstance().statusModes.add(new StatusMode("离心泵(四)",R.mipmap.lxl1,R.mipmap.lxl2,true));
DataBus.getInstance().statusModes.add(new StatusMode("离心泵(四)",R.mipmap.lxl1,R.mipmap.lxl2,false));
DataBus.getInstance().statusModes.add(new StatusMode("离心泵(五)",R.mipmap.lxl1,R.mipmap.lxl2,false));

DataBus.getInstance().statusModes.add(new StatusMode("出水阀",R.mipmap.csf1,R.mipmap.csf2,false));
@@ -97,8 +108,56 @@ public class SsjkFragment extends Fragment implements View.OnClickListener {
}
}

public void SetStatus(int i,Boolean bool)
{
if(DataBus.getInstance().statusModes.size()>=i)
{
StatusMode mode= DataBus.getInstance().statusModes.get(i);
mode.Status=bool;
DataBus.getInstance().statusModes.set(i,mode);
}
}
@Override
public void onClick(View v) {

}
private Activity findActivity(@NonNull Context context) {
if (context instanceof Activity) {
return (Activity) context;
} else if (context instanceof ContextWrapper) {
return findActivity(((ContextWrapper) context).getBaseContext());
} else {
return null;
}
}
/**
* 实时显示线程
*/
public void Run() {
new Thread(new Runnable() {
@Override
public void run() {
while (DataBus.getInstance().PlcIsConnect) {
try {
if(activity!=null)
{
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
// SetStatus(0,DeviceData.getConcurrentHash(1));
} catch (Exception e) {
MessageLog.ShowInfo("状态显示解析异常!"+e.getMessage());
}
}
});
}
Thread.sleep(500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}).start();
}
}

Cargando…
Cancelar
Guardar