|
|
@@ -2,32 +2,20 @@ package com.mes.component;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
-import com.github.s7connector.api.DaveArea;
|
|
|
-import com.github.s7connector.api.S7Connector;
|
|
|
-import com.github.s7connector.api.S7Serializer;
|
|
|
-import com.github.s7connector.api.factory.S7ConnectorFactory;
|
|
|
-import com.github.s7connector.api.factory.S7SerializerFactory;
|
|
|
import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
|
|
|
import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
|
|
|
import com.mes.ui.CacheData;
|
|
|
import com.mes.ui.DataUtil;
|
|
|
import com.mes.ui.MesClient;
|
|
|
-import com.mes.util.DateLocalUtils;
|
|
|
import com.mes.util.JdbcUtils;
|
|
|
-import com.mes.util.S7Util;
|
|
|
-import com.mes.util.TCPClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import javax.swing.*;
|
|
|
import java.awt.*;
|
|
|
import java.awt.event.*;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
import java.util.Timer;
|
|
|
import java.util.TimerTask;
|
|
|
-import java.util.concurrent.ExecutorService;
|
|
|
-import java.util.concurrent.Executors;
|
|
|
|
|
|
public class WorkJPanelOP30 extends JPanel {
|
|
|
|
|
|
@@ -72,19 +60,8 @@ public class WorkJPanelOP30 extends JPanel {
|
|
|
public String plcIp1 = "192.168.90.81"; // plc1 西侧
|
|
|
public String plcIp2 = "192.168.90.82"; // plc2 东侧
|
|
|
|
|
|
- public String deviceIp = "";
|
|
|
- public String deviceIp1 = "80.20.10.42";
|
|
|
- public String deviceIp2 = "80.20.10.43";
|
|
|
- public String deviceIp3 = "80.21.10.42";
|
|
|
- public String deviceIp4 = "80.21.10.43";
|
|
|
- // FSW3 机床IP 按现有规律暂定,待现场确认
|
|
|
- public String deviceIp5 = "80.20.10.44"; // 西侧 FSW3
|
|
|
- public String deviceIp6 = "80.21.10.44"; // 东侧 FSW3
|
|
|
-
|
|
|
public S7PLC s7PLC = null;
|
|
|
|
|
|
- public S7PLC s7PLCFSW = null;
|
|
|
-
|
|
|
public Integer workWidth = 470;
|
|
|
public Integer workHeight = 300;
|
|
|
|
|
|
@@ -92,14 +69,12 @@ public class WorkJPanelOP30 extends JPanel {
|
|
|
|
|
|
public String plcIp = ""; // 当前连接的 PLC IP
|
|
|
|
|
|
- public JLabel ipLabel; // 界面显示 PLC/DB/机床IP
|
|
|
+ public JLabel ipLabel; // 界面显示 PLC/DB
|
|
|
|
|
|
public String plcDb2 = "DB7010";
|
|
|
|
|
|
public String preSn = ""; // 扫码内容
|
|
|
|
|
|
- public S7Connector s7Connector;
|
|
|
-
|
|
|
public Integer tjFeedingFlag = 0; // 上料状态标识
|
|
|
public Integer tjFlag = 0; // 1=可加工 2=设备运行中 3=加工结束
|
|
|
public Integer tjStatus = 0; // 提交标识
|
|
|
@@ -113,14 +88,9 @@ public class WorkJPanelOP30 extends JPanel {
|
|
|
|
|
|
public String finallySn = "";
|
|
|
|
|
|
- public Boolean fswOnline = true;
|
|
|
-
|
|
|
- public Integer errflag = 0; // 1=报警 0=正常
|
|
|
-
|
|
|
- public Integer errflag2 = 0; // 1=报警 0=正常
|
|
|
+ public Integer errflag2 = 0; // PLC 故障报警标识 1=报警 0=正常
|
|
|
|
|
|
public String fswDeviceName = "";
|
|
|
- public List<String> hjparams = new ArrayList<>();
|
|
|
|
|
|
public JLabel oprnoLabel;
|
|
|
public JLabel oprnoLabel2;
|
|
|
@@ -169,21 +139,17 @@ public class WorkJPanelOP30 extends JPanel {
|
|
|
s7PLC.setConnectTimeout(800);
|
|
|
s7PLC.setReceiveTimeout(800);
|
|
|
|
|
|
- // 子工位 -> DB块 / 机床IP / 设备名(西侧 A/B/E,东侧 C/D/F,E/F 为新增 FSW3)
|
|
|
+ // 子工位 -> DB块 / 设备名(西侧 A/B/E,东侧 C/D/F,E/F 为新增 FSW3)
|
|
|
switch (pos) {
|
|
|
- case "A": plcDb = "DB7010"; deviceIp = deviceIp1; fswDeviceName = "西侧正面1号机"; break;
|
|
|
- case "B": plcDb = "DB7011"; deviceIp = deviceIp2; fswDeviceName = "西侧正面2号机"; break;
|
|
|
- case "E": plcDb = "DB7014"; deviceIp = deviceIp5; fswDeviceName = "西侧正面3号机"; break;
|
|
|
- case "C": plcDb = "DB7010"; deviceIp = deviceIp3; fswDeviceName = "东侧正面1号机"; break;
|
|
|
- case "D": plcDb = "DB7011"; deviceIp = deviceIp4; fswDeviceName = "东侧正面2号机"; break;
|
|
|
- case "F": plcDb = "DB7014"; deviceIp = deviceIp6; fswDeviceName = "东侧正面3号机"; break;
|
|
|
+ case "A": plcDb = "DB7010"; fswDeviceName = "西侧正面1号机"; break;
|
|
|
+ case "B": plcDb = "DB7011"; fswDeviceName = "西侧正面2号机"; break;
|
|
|
+ case "E": plcDb = "DB7014"; fswDeviceName = "西侧正面3号机"; break;
|
|
|
+ case "C": plcDb = "DB7010"; fswDeviceName = "东侧正面1号机"; break;
|
|
|
+ case "D": plcDb = "DB7011"; fswDeviceName = "东侧正面2号机"; break;
|
|
|
+ case "F": plcDb = "DB7014"; fswDeviceName = "东侧正面3号机"; break;
|
|
|
default: log.error("未知子工位:" + pos); break;
|
|
|
}
|
|
|
|
|
|
- s7PLCFSW = new S7PLC(EPlcType.SINUMERIK_828D, deviceIp);
|
|
|
- s7PLCFSW.setConnectTimeout(800);
|
|
|
- s7PLCFSW.setReceiveTimeout(800);
|
|
|
-
|
|
|
oprnoLabel = new JLabel(oprno+pos);
|
|
|
oprnoLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
oprnoLabel.setForeground(Color.BLACK);
|
|
|
@@ -198,8 +164,8 @@ public class WorkJPanelOP30 extends JPanel {
|
|
|
oprnoLabel2.setBounds(0, 12, workWidth / 5, 40);
|
|
|
this.add(oprnoLabel2);
|
|
|
|
|
|
- // 底部显示 PLC/DB/机床IP,机床离线时变红
|
|
|
- ipLabel = new JLabel("PLC " + plcIp + " | " + plcDb + " | 机床 " + deviceIp);
|
|
|
+ // 底部显示 PLC/DB
|
|
|
+ ipLabel = new JLabel("PLC " + plcIp + " | " + plcDb);
|
|
|
ipLabel.setFont(new Font("微软雅黑", Font.PLAIN, 12));
|
|
|
ipLabel.setForeground(Color.DARK_GRAY);
|
|
|
ipLabel.setBounds(5, 230, workWidth*2/3 + 55, 26);
|
|
|
@@ -417,6 +383,7 @@ public class WorkJPanelOP30 extends JPanel {
|
|
|
}, 1000,1000);
|
|
|
}
|
|
|
|
|
|
+ // PLC 故障报警监控(安全门/急停/光栅/夹紧,读 PLC DB 块 .6.0~.6.3)
|
|
|
public Timer cjTimerText3;
|
|
|
public void monitorDeviceStatus() {
|
|
|
if(cjTimerText3!=null) {
|
|
|
@@ -427,33 +394,6 @@ public class WorkJPanelOP30 extends JPanel {
|
|
|
public void run() {
|
|
|
if(MesClient.isLogin == 1 && isLocal == 0){
|
|
|
try{
|
|
|
- initS7();
|
|
|
- monitorDevice();
|
|
|
- boolean ret = S7Util.getFswAlarm(s7Connector);
|
|
|
- if(ret){
|
|
|
- errflag = 0;
|
|
|
- }
|
|
|
- if(!ret && errflag == 0 ){
|
|
|
- errflag = 1;
|
|
|
- DataUtil.deviceAlarm(oprno+pos,productSn.getText(),oprno+pos+"随动夹具报警",MesClient.user_menu.getText());
|
|
|
- }
|
|
|
- fswOnline = true;
|
|
|
- }catch (Exception e){
|
|
|
- log.info(e.getMessage());
|
|
|
- fswOnline = false;
|
|
|
- }
|
|
|
-
|
|
|
- if(fswOnline){
|
|
|
- oprnoLabel.setForeground(Color.BLACK);
|
|
|
- oprnoLabel2.setForeground(Color.BLACK);
|
|
|
- ipLabel.setForeground(Color.DARK_GRAY);
|
|
|
- }else{
|
|
|
- oprnoLabel.setForeground(Color.RED);
|
|
|
- oprnoLabel2.setForeground(Color.RED);
|
|
|
- ipLabel.setForeground(Color.RED);
|
|
|
- }
|
|
|
-
|
|
|
- try{
|
|
|
int ret = getAlarm();
|
|
|
if(ret == 0){
|
|
|
errflag2 = 0;
|
|
|
@@ -600,13 +540,6 @@ public class WorkJPanelOP30 extends JPanel {
|
|
|
productSnFeeding.setText(sn);
|
|
|
lastSn = sn;
|
|
|
|
|
|
- // 判断刀具寿命
|
|
|
-// Integer hjjs = S7Util.formatS7Int(s7Connector.read(DaveArea.DB, 9051, 2, 26));
|
|
|
-// if(hjjs > 320){
|
|
|
-// this.setMenuStatus("搅拌头达到使用寿命,请换搅拌头", -1);
|
|
|
-// return;
|
|
|
-// }
|
|
|
-
|
|
|
// 查询工件质量
|
|
|
JSONObject retObj = DataUtil.checkQuality(sn,oprno+pos,MesClient.user_menu.getText());
|
|
|
if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
@@ -811,67 +744,6 @@ public class WorkJPanelOP30 extends JPanel {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- public void monitorDevice(){
|
|
|
- log.info("monitorDevice");
|
|
|
- if(tjFlag == 2){
|
|
|
- try{
|
|
|
- String zzzs = String.valueOf(s7PLCFSW.readSpindleRate());
|
|
|
- String jgsd = String.valueOf(s7PLCFSW.readFeedRate());
|
|
|
-// String zzzs = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 0));
|
|
|
-// String jgsd = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 4));
|
|
|
- String zzzb = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 8));
|
|
|
- String ylz = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 12));
|
|
|
- Integer hjjs = S7Util.formatS7Int(s7Connector.read(DaveArea.DB, 9051, 2, 26));
|
|
|
- String hjcd = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 28));
|
|
|
- String hjms = S7Util.formatS7Val(s7Connector.read(DaveArea.DB, 9051, 4, 32));
|
|
|
- String record_time = DateLocalUtils.getCurrentTime();
|
|
|
- hjparams.add(zzzs+"|"+jgsd+"|"+zzzb+"|"+ylz+"|"+hjjs+"|"+hjcd+"|"+hjms+"|"+record_time);
|
|
|
- if (hjparams.size() == 60 && productSn.getText() != null && !productSn.getText().trim().isEmpty() ) {
|
|
|
- JdbcUtils.insertParamData(oprno+pos,MesClient.mes_line_sn,productSn.getText(), JSON.toJSONString(hjparams));
|
|
|
- hjparams = new ArrayList<>();
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- s7Connector = null;
|
|
|
- }
|
|
|
- log.info("monitorDevice:"+JSON.toJSONString(hjparams));
|
|
|
- }else{
|
|
|
- if(hjparams.size() > 0){
|
|
|
- JdbcUtils.insertParamData(oprno,MesClient.mes_line_sn,lastSn, JSON.toJSONString(hjparams));
|
|
|
- hjparams = new ArrayList<>();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public void initS7(){
|
|
|
- try {
|
|
|
- if(s7Connector == null) {
|
|
|
- //PLC地址
|
|
|
- String ipAddress = deviceIp;
|
|
|
- log.info("deviceIp2:"+deviceIp);
|
|
|
- //默认端口
|
|
|
- int port = 102;
|
|
|
- int rack=0;
|
|
|
- int slot=3;
|
|
|
- int timeout=5000;
|
|
|
- s7Connector=
|
|
|
- S7ConnectorFactory
|
|
|
- .buildTCPConnector()
|
|
|
- .withHost(ipAddress)
|
|
|
- .withPort(port) //optional
|
|
|
-// .withRack(rack) //optional
|
|
|
-// .withSlot(slot) //optional
|
|
|
- .withTimeout(timeout) //连接超时时间
|
|
|
- .build();
|
|
|
- S7Serializer s7Serializer2L = S7SerializerFactory.buildSerializer(s7Connector);
|
|
|
- }
|
|
|
- } catch (Exception e) { // 如果连接失败保存失败再次尝试连接一次
|
|
|
- s7Connector = null;
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public int getAlarm(){
|
|
|
boolean ret0 = readBoolean(plcDb+".6.0");
|
|
|
if(ret0){
|