@@ -1,7 +1,7 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||
<project version="4"> | <project version="4"> | ||||
<component name="ExternalStorageConfigurationManager" enabled="true" /> | <component name="ExternalStorageConfigurationManager" enabled="true" /> | ||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK"> | |||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK"> | |||||
<output url="file://$PROJECT_DIR$/build/classes" /> | <output url="file://$PROJECT_DIR$/build/classes" /> | ||||
</component> | </component> | ||||
<component name="ProjectType"> | <component name="ProjectType"> | ||||
@@ -3,6 +3,7 @@ package com.example.bpa.app; | |||||
import com.example.bpa.Model.IReadCallBack; | import com.example.bpa.Model.IReadCallBack; | ||||
import com.example.bpa.Model.IWriteCallBack; | import com.example.bpa.Model.IWriteCallBack; | ||||
import com.example.bpa.config.DataBus; | |||||
import com.example.bpa.helper.MessageLog; | import com.example.bpa.helper.MessageLog; | ||||
import com.licheedev.modbus4android.ModbusCallback; | import com.licheedev.modbus4android.ModbusCallback; | ||||
import com.licheedev.modbus4android.ModbusParam; | import com.licheedev.modbus4android.ModbusParam; | ||||
@@ -116,6 +117,7 @@ public class ModbusTcpServer { | |||||
@Override | @Override | ||||
public void onSuccess(ModbusMaster modbusMaster) { | public void onSuccess(ModbusMaster modbusMaster) { | ||||
MessageLog.ShowInfo("设备 " + host + " 连接成功"); | MessageLog.ShowInfo("设备 " + host + " 连接成功"); | ||||
DataBus.getInstance().PlcIsConnect=true; | |||||
//1.数据中心 | //1.数据中心 | ||||
DeviceData.Get().Init(); | DeviceData.Get().Init(); | ||||
//2.业务线程 | //2.业务线程 | ||||
@@ -124,6 +126,7 @@ public class ModbusTcpServer { | |||||
@Override | @Override | ||||
public void onFailure(Throwable tr) { | public void onFailure(Throwable tr) { | ||||
DataBus.getInstance().PlcIsConnect=false; | |||||
MessageLog.ShowError("设备 " + host + " 连接失败:" + tr.getMessage()); | MessageLog.ShowError("设备 " + host + " 连接失败:" + tr.getMessage()); | ||||
} | } | ||||
@@ -35,6 +35,13 @@ public class DataBus { | |||||
} | } | ||||
//endregion | //endregion | ||||
//region 连接状态 | |||||
/** | |||||
* Plc是否连接 | |||||
*/ | |||||
public boolean PlcIsConnect=false; | |||||
//endregion | |||||
//region 数据中心 | //region 数据中心 | ||||
/** | /** | ||||
* 主界面商品列表 | * 主界面商品列表 | ||||
@@ -0,0 +1,100 @@ | |||||
package com.example.bpa.helper; | |||||
import android.util.Log; | |||||
import android.view.View; | |||||
import android.view.animation.AlphaAnimation; | |||||
import android.view.animation.Animation; | |||||
import android.view.animation.LinearInterpolator; | |||||
import android.widget.EditText; | |||||
import java.security.Key; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
/** | |||||
* Title:控件闪烁帮助类 | |||||
* Description: | |||||
* <p> | |||||
* Created by pei | |||||
* Date: 2018/4/22 | |||||
*/ | |||||
public class FlashHelper { | |||||
private FlashHelper() {} | |||||
private static class Holder { | |||||
private static FlashHelper instance = new FlashHelper(); | |||||
} | |||||
public static FlashHelper getInstance() { | |||||
return FlashHelper.Holder.instance; | |||||
} | |||||
public List<Integer> listviews = new ArrayList<Integer>(); | |||||
public List<Integer> listviews1 = new ArrayList<Integer>(); | |||||
/**开启View闪烁效果**/ | |||||
public void startFlick( View view ,Integer key) { | |||||
if (null == view) { | |||||
return; | |||||
} | |||||
if(!listviews.contains(key)) | |||||
{ | |||||
view.setVisibility(View.VISIBLE); | |||||
Log.e("213", "VISIBLE: "); | |||||
Animation alphaAnimation = new AlphaAnimation(1, 0); | |||||
alphaAnimation.setDuration(300); | |||||
alphaAnimation.setInterpolator(new LinearInterpolator()); | |||||
alphaAnimation.setRepeatCount(Animation.INFINITE); | |||||
alphaAnimation.setRepeatMode(Animation.REVERSE); | |||||
view.startAnimation(alphaAnimation); | |||||
listviews.add(key); | |||||
} | |||||
} | |||||
/**取消View闪烁效果**/ | |||||
public void stopFlick( View view ,Integer key ) { | |||||
if (null == view) { | |||||
return; | |||||
} | |||||
if(listviews.contains(key)) | |||||
{ | |||||
view.setVisibility(View.GONE); | |||||
view.clearAnimation(); | |||||
listviews.remove(key); | |||||
} | |||||
} | |||||
/**开启View闪烁效果**/ | |||||
public void startFlick1( View view ,Integer key) { | |||||
if (null == view) { | |||||
return; | |||||
} | |||||
if(!listviews1.contains(key)) | |||||
{ | |||||
view.setVisibility(View.VISIBLE); | |||||
Log.e("213", "VISIBLE: "); | |||||
Animation alphaAnimation = new AlphaAnimation(1, 0); | |||||
alphaAnimation.setDuration(300); | |||||
alphaAnimation.setInterpolator(new LinearInterpolator()); | |||||
alphaAnimation.setRepeatCount(Animation.INFINITE); | |||||
alphaAnimation.setRepeatMode(Animation.REVERSE); | |||||
view.startAnimation(alphaAnimation); | |||||
listviews1.add(key); | |||||
} | |||||
} | |||||
/**取消View闪烁效果**/ | |||||
public void stopFlick1( View view ,Integer key ) { | |||||
if (null == view) { | |||||
return; | |||||
} | |||||
if(listviews1.contains(key)) | |||||
{ | |||||
view.setVisibility(View.GONE); | |||||
view.clearAnimation(); | |||||
listviews1.remove(key); | |||||
} | |||||
} | |||||
} |
@@ -8,6 +8,7 @@ import android.view.ViewGroup; | |||||
import android.widget.AdapterView; | import android.widget.AdapterView; | ||||
import android.widget.ArrayAdapter; | import android.widget.ArrayAdapter; | ||||
import android.widget.ImageView; | import android.widget.ImageView; | ||||
import android.widget.RelativeLayout; | |||||
import android.widget.Spinner; | import android.widget.Spinner; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
@@ -73,24 +74,35 @@ public class lc_item_adapter extends RecyclerView.Adapter<RecyclerView.ViewHolde | |||||
/**、 | /**、 | ||||
* 料仓仓号 | * 料仓仓号 | ||||
*/ | */ | ||||
TextView num; | |||||
public TextView num; | |||||
/** | /** | ||||
* 料仓余量 | * 料仓余量 | ||||
*/ | */ | ||||
TextView silosmargin; | |||||
public TextView silosmargin; | |||||
/** | |||||
* 预警标识 | |||||
*/ | |||||
public RelativeLayout image_yj; | |||||
/** | |||||
* 告警标识 | |||||
*/ | |||||
public RelativeLayout image_gj; | |||||
/** | |||||
* 物料ID | |||||
*/ | |||||
public String id; | public String id; | ||||
/** | |||||
* 物料名称 | |||||
*/ | |||||
public String MaterialName; | public String MaterialName; | ||||
// public String id; | |||||
public MyLCViewHolder(View view) { | public MyLCViewHolder(View view) { | ||||
super(view); | super(view); | ||||
materialName = (TextView) view.findViewById(R.id.lc_item_materialName); | materialName = (TextView) view.findViewById(R.id.lc_item_materialName); | ||||
num = (TextView) view.findViewById(R.id.lc_item_num); | num = (TextView) view.findViewById(R.id.lc_item_num); | ||||
silosmargin = (TextView) view.findViewById(R.id.lc_item_silosmargin); | silosmargin = (TextView) view.findViewById(R.id.lc_item_silosmargin); | ||||
image_yj = (RelativeLayout) view.findViewById(R.id.image_yj); | |||||
image_gj = (RelativeLayout) view.findViewById(R.id.image_gj); | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -18,11 +18,15 @@ import android.widget.TextView; | |||||
import com.example.bpa.Model.IReadCallBack; | import com.example.bpa.Model.IReadCallBack; | ||||
import com.example.bpa.Model.IThread; | import com.example.bpa.Model.IThread; | ||||
import com.example.bpa.R; | import com.example.bpa.R; | ||||
import com.example.bpa.app.DeviceData; | |||||
import com.example.bpa.app.ModbusTcpServer; | import com.example.bpa.app.ModbusTcpServer; | ||||
import com.example.bpa.config.ConfigName; | |||||
import com.example.bpa.config.DataBus; | |||||
import com.example.bpa.db.QueryDB; | import com.example.bpa.db.QueryDB; | ||||
import com.example.bpa.db.mode.BPA_MATERIAL; | import com.example.bpa.db.mode.BPA_MATERIAL; | ||||
import com.example.bpa.db.mode.BPA_SILOS; | import com.example.bpa.db.mode.BPA_SILOS; | ||||
import com.example.bpa.db.mode.BPA_SILOSANDMATERIAL; | import com.example.bpa.db.mode.BPA_SILOSANDMATERIAL; | ||||
import com.example.bpa.helper.FlashHelper; | |||||
import com.example.bpa.helper.T; | import com.example.bpa.helper.T; | ||||
import com.example.bpa.helper.ThreadManager; | import com.example.bpa.helper.ThreadManager; | ||||
import com.example.bpa.view.adapter.lc_item_adapter; | import com.example.bpa.view.adapter.lc_item_adapter; | ||||
@@ -58,7 +62,8 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList | |||||
ArrayList<BPA_MATERIAL> bpa_materials=new ArrayList<>(); | ArrayList<BPA_MATERIAL> bpa_materials=new ArrayList<>(); | ||||
//当前选中的料仓id | //当前选中的料仓id | ||||
lc_item_adapter.MyLCViewHolder currentSilo; | lc_item_adapter.MyLCViewHolder currentSilo; | ||||
//当前料仓集合 | |||||
List<lcMode> datas = new ArrayList<lcMode>(); | |||||
//region 私有函数 | //region 私有函数 | ||||
@Override | @Override | ||||
protected void onCreate(Bundle savedInstanceState) { | protected void onCreate(Bundle savedInstanceState) { | ||||
@@ -66,6 +71,7 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList | |||||
setContentView(R.layout.activity_lcsz); | setContentView(R.layout.activity_lcsz); | ||||
Init(); | Init(); | ||||
initEvents(); | initEvents(); | ||||
Run(); | |||||
} | } | ||||
//endregion | //endregion | ||||
@@ -90,7 +96,6 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList | |||||
//必须,防止recyclerview高度为wrap时测量item高度0 | //必须,防止recyclerview高度为wrap时测量item高度0 | ||||
layout.setAutoMeasureEnabled(true); | layout.setAutoMeasureEnabled(true); | ||||
recyclerView.setLayoutManager(layout); | recyclerView.setLayoutManager(layout); | ||||
List<lcMode> datas = new ArrayList<lcMode>(); | |||||
//获取料仓数据 | //获取料仓数据 | ||||
ArrayList<BPA_SILOS> bpa_silos =QueryDB.GetSilosALL(); | ArrayList<BPA_SILOS> bpa_silos =QueryDB.GetSilosALL(); | ||||
//加载materials数据 | //加载materials数据 | ||||
@@ -145,13 +150,11 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList | |||||
listViewParent.setVisibility(View.VISIBLE); | listViewParent.setVisibility(View.VISIBLE); | ||||
currentSilo = null; | currentSilo = null; | ||||
currentSilo = (lc_item_adapter.MyLCViewHolder) viewHolder; | currentSilo = (lc_item_adapter.MyLCViewHolder) viewHolder; | ||||
} | } | ||||
} | } | ||||
@Override | @Override | ||||
public void onItemLongClick(View view, int position) { | public void onItemLongClick(View view, int position) { | ||||
} | } | ||||
})); | })); | ||||
//endregion | //endregion | ||||
@@ -207,22 +210,59 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList | |||||
//endregion | //endregion | ||||
//region | |||||
//region 线程 | |||||
/** | |||||
* 实时显示线程 | |||||
*/ | |||||
public void Run() | public void Run() | ||||
{ | { | ||||
ThreadManager.Get().StartLong("Plc设备数据监听", true, new IThread() { | |||||
new Thread(new Runnable() { | |||||
@Override | @Override | ||||
public void Run() throws InterruptedException { | |||||
//获取实时值 | |||||
public void run() { | |||||
while (DataBus.getInstance().PlcIsConnect) { | |||||
try { | |||||
lcsz_activity.this.runOnUiThread(new Runnable() { | |||||
@Override | |||||
public void run() { | |||||
for (int i=0;i<datas.size();i++) | |||||
{ | |||||
int num=datas.get(i).num; | |||||
float val= DeviceData.Get().getCallCurrentWeight(num); | |||||
RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(i); | |||||
if(viewHolder!=null) | |||||
{ | |||||
lc_item_adapter.MyLCViewHolder hold = (lc_item_adapter.MyLCViewHolder) viewHolder; | |||||
//hold.silosmargin.setText(new java.text.DecimalFormat("#.00").format(val)+"g"); | |||||
hold.silosmargin.setText(val+"g"); | |||||
Thread.sleep(10); | |||||
} | |||||
@Override | |||||
public void RunComplete() throws InterruptedException { | |||||
if(val<datas.get(i).warningValue)//补料 | |||||
{ | |||||
FlashHelper.getInstance().startFlick1(hold.image_yj,num); | |||||
}else | |||||
{ | |||||
FlashHelper.getInstance().stopFlick1(hold.image_yj,num); | |||||
} | |||||
if(val<datas.get(i).thrsoleValue)//告警 | |||||
{ | |||||
FlashHelper.getInstance().startFlick(hold.image_gj,num); | |||||
}else | |||||
{ | |||||
FlashHelper.getInstance().stopFlick(hold.image_gj,num); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
}); | |||||
Thread.sleep(100); | |||||
} catch (InterruptedException e) { | |||||
throw new RuntimeException(e); | |||||
} | |||||
} | |||||
} | } | ||||
}); | |||||
}).start(); | |||||
} | } | ||||
//endreion | //endreion | ||||
} | } |
@@ -8,6 +8,7 @@ import android.widget.ImageView; | |||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import com.example.bpa.R; | import com.example.bpa.R; | ||||
import com.example.bpa.config.DataBus; | |||||
/** | /** | ||||
* 研发出料 | * 研发出料 | ||||
@@ -31,6 +32,8 @@ public class yfcl_activity extends AppCompatActivity implements View.OnClickList | |||||
setContentView(R.layout.activity_yfcl); | setContentView(R.layout.activity_yfcl); | ||||
Init(); | Init(); | ||||
initEvents(); | initEvents(); | ||||
DataBus.getInstance().PlcIsConnect=true; | |||||
} | } | ||||
//endregion | //endregion | ||||
@@ -44,5 +44,27 @@ | |||||
android:gravity="center" | android:gravity="center" | ||||
android:textColor="@color/white" | android:textColor="@color/white" | ||||
android:text="未设置" /> | android:text="未设置" /> | ||||
<RelativeLayout | |||||
android:id="@+id/image_yj" | |||||
android:layout_width="20dp" | |||||
android:layout_marginTop="10dp" | |||||
android:layout_marginRight="5dp" | |||||
android:layout_alignParentRight="true" | |||||
android:layout_height="20dp" | |||||
android:visibility="gone" | |||||
android:background="@mipmap/bl"> | |||||
</RelativeLayout> | |||||
<RelativeLayout | |||||
android:id="@+id/image_gj" | |||||
android:layout_width="20dp" | |||||
android:layout_marginTop="30dp" | |||||
android:layout_marginRight="5dp" | |||||
android:visibility="gone" | |||||
android:layout_alignParentRight="true" | |||||
android:layout_height="20dp" | |||||
android:background="@mipmap/gj"> | |||||
</RelativeLayout> | |||||
</RelativeLayout> | </RelativeLayout> | ||||
</LinearLayout> | </LinearLayout> |