yangys
2024-01-30 518766738fcf0c8086775056fd3fe935581a94f5
mdc-parent/mdc-collect/src/main/java/com/qianwen/mdc/service/scanet/ScanetClient.java
@@ -1,336 +1,282 @@
/*     */ package com.qianwen.mdc.service.scanet;
/*     */ 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.s7connector.exception.S7Exception;
import com.qianwen.mdc.service.scanet.PlcByteValue;
package com.qianwen.mdc.service.scanet;
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.s7connector.exception.S7Exception;
import com.qianwen.mdc.utils.MdcException;
/*     */ import java.io.IOException;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */
/*     */
/*     */
/*     */ public class ScanetClient
/*     */ {
/*     */   private String ip;
/*     */
/*     */   public void connectServer() {
/*  22 */     if (null == this.connector) {
/*     */       try {
/*  24 */         this.connector = S7ConnectorFactory.buildTCPConnector().withHost(this.ip).build();
/*  25 */         this.serializer = S7SerializerFactory.buildSerializer(this.connector);
/*  26 */         if (null != this.connector) {
/*  27 */           this.count = 0;
/*  28 */           this.connected = true;
/*     */         } else {
/*  30 */           this.connected = false;
/*  31 */           throw new MdcException();
/*     */         }
/*  33 */       } catch (Exception e) {
/*  34 */         this.connected = false;
/*  35 */         throw new MdcException();
/*     */       }
/*     */     }
/*     */   }
/*     */
/*     */   public void disconnectServer() {
/*  41 */     if (this.serializer != null) {
/*     */       try {
/*  43 */         this.connector.close();
/*  44 */         this.connector = null;
/*  45 */         this.serializer = null;
/*  46 */       } catch (IOException e) {
/*  47 */         throw new MdcException();
/*     */       }
/*     */     }
/*     */
/*  51 */     this.count = 0;
/*  52 */     this.connected = false;
/*     */   }
/*     */
/*     */   public void reconnectServer() {
/*     */     try {
/*  57 */       disconnectServer();
/*  58 */       connectServer();
/*  59 */     } catch (Exception exception) {}
/*     */   }
/*     */
/*     */
/*     */   public void checkConnection() {
/*  64 */     int dbNum = 21;
/*  65 */     int byteOffset = 35;
/*     */
/*     */
/*     */     try {
/*  69 */       byte[] read = this.connector.read(DaveArea.DB, dbNum, 50, byteOffset);
/*     */       int i;
/*  71 */       for (i = 1; i < read.length; i++) {
/*  72 */         if (read[i] != 0) {
/*  73 */           this.connected = true;
/*     */           break;
/*     */         }
/*     */       }
/*  77 */       if (i == read.length) {
/*  78 */         this.connected = false;
/*     */       }
/*  80 */       if (!this.connected) {
/*     */
/*  82 */         reconnectServer();
/*  83 */         throw new MdcException();
/*     */       }
/*  85 */     } catch (S7Exception e) {
/*     */
/*  87 */       this.connected = false;
/*  88 */       reconnectServer();
/*  89 */     } catch (Exception e) {
/*     */
/*  91 */       if (++this.count >= 3) {
/*  92 */         this.connected = false;
/*     */       }
/*  94 */       throw new MdcException();
/*     */     }
/*     */   }
/*     */
/*     */   public int readOpMode() {
/*  99 */     int dbNum = 11;
/* 100 */     int byteOffset1 = 6;
/* 101 */     int byteOffset2 = 7;
/* 102 */     byte autoMask = 1;
/* 103 */     byte mdaMask = 2;
/* 104 */     byte jogMask = 4;
/* 105 */     byte refMask = 4;
/*     */
/*     */
/*     */
/*     */
/* 110 */     int ret = 9000;
/*     */
/*     */     try {
/* 113 */       PlcByteValue opModeValue1 = (PlcByteValue)this.serializer.dispense(PlcByteValue.class, dbNum, byteOffset1);
/* 114 */       boolean autoValue = ((opModeValue1.value & autoMask) != 0);
/* 115 */       boolean mdaValue = ((opModeValue1.value & mdaMask) != 0);
/* 116 */       boolean jogValue = ((opModeValue1.value & jogMask) != 0);
/* 117 */       PlcByteValue opModeValue2 = (PlcByteValue)this.serializer.dispense(PlcByteValue.class, dbNum, byteOffset2);
/* 118 */       boolean refValue = ((opModeValue2.value & refMask) != 0);
/* 119 */       ret = autoValue ? 200 : (mdaValue ? 100 : (jogValue ? 0 : (refValue ? 300 : 9000)));
/*     */
/* 121 */       this.count = 0;
/* 122 */       this.connected = true;
/* 123 */     } catch (S7Exception e) {
/* 124 */       this.connected = false;
/* 125 */       reconnectServer();
/* 126 */     } catch (Exception e) {
/* 127 */       if (++this.count >= 3) {
/* 128 */         this.connected = false;
/*     */       }
/* 130 */       throw new MdcException();
/*     */     }
/*     */
/* 133 */     return ret;
/*     */   }
/*     */
/*     */   public int readNCState() {
/* 137 */     int dbNum = 21;
/* 138 */     int byteOffset = 35;
/* 139 */     byte ncStartMask = 1;
/* 140 */     byte ncStopMask = 4;
/*     */
/*     */
/* 143 */     int ret = 9000;
/*     */
/*     */     try {
/* 146 */       PlcByteValue ncValue = (PlcByteValue)this.serializer.dispense(PlcByteValue.class, dbNum, byteOffset);
/* 147 */       boolean ncStartValue = ((ncValue.value & ncStartMask) != 0);
/* 148 */       boolean ncStopValue = ((ncValue.value & ncStopMask) != 0);
/* 149 */       ret = ncStartValue ? 0 : (ncStopValue ? 100 : 8000);
/*     */
/* 151 */       this.count = 0;
/* 152 */       this.connected = true;
/* 153 */     } catch (S7Exception e) {
/* 154 */       this.connected = false;
/* 155 */       reconnectServer();
/* 156 */     } catch (Exception e) {
/* 157 */       if (++this.count >= 3) {
/* 158 */         this.connected = false;
/*     */       }
/* 160 */       throw new MdcException();
/*     */     }
/*     */
/* 163 */     return ret;
/*     */   }
/*     */
/*     */   public int readSpState() {
/* 167 */     int dbNum = 34;
/* 168 */     int byteOffset = 64;
/* 169 */     byte forwardMask = 64;
/* 170 */     byte reverseMask = Byte.MIN_VALUE;
/*     */
/*     */
/* 173 */     int ret = 9000;
/*     */
/*     */     try {
/* 176 */       PlcByteValue spStateValue = (PlcByteValue)this.serializer.dispense(PlcByteValue.class, dbNum, byteOffset);
/* 177 */       boolean forwardValue = ((spStateValue.value & forwardMask) != 0);
/* 178 */       boolean reverseValue = ((spStateValue.value & reverseMask) != 0);
/* 179 */       ret = (forwardValue | reverseValue) ? 0 : 8000;
/*     */
/* 181 */       this.count = 0;
/* 182 */       this.connected = true;
/* 183 */     } catch (S7Exception e) {
/* 184 */       this.connected = false;
/* 185 */       reconnectServer();
/* 186 */     } catch (Exception e) {
/* 187 */       if (++this.count >= 3) {
/* 188 */         this.connected = false;
/*     */       }
/* 190 */       throw new MdcException();
/*     */     }
/*     */
/* 193 */     return ret;
/*     */   }
/*     */
/*     */   public int readSpRate() {
/* 197 */     int dbNum = 34;
/* 198 */     int byteOffset = 19;
/* 199 */     int ret = 0;
/*     */
/*     */     try {
/* 202 */       PlcByteValue spRateValue = (PlcByteValue)this.serializer.dispense(PlcByteValue.class, dbNum, byteOffset);
/* 203 */       ret = spRateValue.value;
/*     */
/* 205 */       this.count = 0;
/* 206 */       this.connected = true;
/* 207 */     } catch (S7Exception e) {
/* 208 */       this.connected = false;
/* 209 */       reconnectServer();
/* 210 */     } catch (Exception e) {
/* 211 */       if (++this.count >= 3) {
/* 212 */         this.connected = false;
/*     */       }
/* 214 */       throw new MdcException();
/*     */     }
/*     */
/* 217 */     return ret;
/*     */   }
/*     */
/*     */   public int readSpSpeed() {
/* 221 */     int dbNum = 34;
/* 222 */     int byteOffset = 88;
/* 223 */     int ret = 0;
/*     */
/*     */     try {
/* 226 */       PlcByteValue spRateValue = (PlcByteValue)this.serializer.dispense(PlcByteValue.class, dbNum, byteOffset);
/* 227 */       ret = spRateValue.value;
/*     */
/* 229 */       this.count = 0;
/* 230 */       this.connected = true;
/* 231 */     } catch (S7Exception e) {
/* 232 */       this.connected = false;
/* 233 */       reconnectServer();
/* 234 */     } catch (Exception e) {
/* 235 */       if (++this.count >= 3) {
/* 236 */         this.connected = false;
/*     */       }
/* 238 */       throw new MdcException();
/*     */     }
/*     */
/* 241 */     return ret;
/*     */   }
/*     */
/*     */   public int readFeedRate() {
/* 245 */     int dbNum = 21;
/* 246 */     int byteOffset = 4;
/* 247 */     int ret = 0;
/*     */
/*     */     try {
/* 250 */       PlcByteValue feedRateValue = (PlcByteValue)this.serializer.dispense(PlcByteValue.class, dbNum, byteOffset);
/* 251 */       ret = feedRateValue.value;
/*     */
/* 253 */       this.count = 0;
/* 254 */       this.connected = true;
/* 255 */     } catch (S7Exception e) {
/* 256 */       this.connected = false;
/* 257 */       reconnectServer();
/* 258 */     } catch (Exception e) {
/* 259 */       if (++this.count >= 3) {
/* 260 */         this.connected = false;
/*     */       }
/* 262 */       throw new MdcException();
/*     */     }
/*     */
/* 265 */     return ret;
/*     */   }
/*     */
/*     */   public int readAlarmState() {
/* 269 */     int dbNum = 2;
/* 270 */     int[] userAlarmOffset = { 180, 181, 182, 183, 184, 195, 186, 187 };
/*     */
/* 272 */     int ret = 0;
/*     */
/*     */     try {
/* 275 */       for (int i : userAlarmOffset) {
/* 276 */         PlcByteValue alarmState = (PlcByteValue)this.serializer.dispense(PlcByteValue.class, dbNum, i);
/* 277 */         if (alarmState.value != 0) {
/* 278 */           ret = 1;
/*     */
/*     */           break;
/*     */         }
/*     */       }
/* 283 */       this.count = 0;
/* 284 */       this.connected = true;
/* 285 */     } catch (S7Exception e) {
/* 286 */       this.connected = false;
/* 287 */       reconnectServer();
/* 288 */     } catch (Exception e) {
/* 289 */       if (++this.count >= 3) {
/* 290 */         this.connected = false;
/*     */       }
/* 292 */       throw new MdcException();
/*     */     }
/*     */
/* 295 */     return ret;
/*     */   }
/*     */
/*     */   public String readALARMState() {
/* 299 */     return null;
/*     */   }
/*     */
/*     */   public String readSPState() {
/* 303 */     return null;
/*     */   }
/*     */
/*     */   public String getIp() {
/* 307 */     return this.ip;
/*     */   }
/*     */
/*     */   public void setIp(String ip) {
/* 311 */     this.ip = ip;
/*     */   }
/*     */
/*     */   public boolean isConnected() {
/* 315 */     return this.connected;
/*     */   }
/*     */
/*     */   public void setConnected(boolean connected) {
/* 319 */     this.connected = connected;
/*     */   }
/*     */
/*     */
/* 323 */   private S7Connector connector = null;
/* 324 */   private S7Serializer serializer = null;
/*     */
/* 326 */   private int count = 0;
/*     */
/*     */   private boolean connected = false;
/* 329 */   private final Logger logger = LoggerFactory.getLogger(getClass());
/*     */ }
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ScanetClient {
   private String ip;
   private S7Connector connector = null;
/* Location:              D:\yangys\mdm\老代码\mdcplugin\mdc-plugin-0.0.1-SNAPSHOT-删除lib.jar!\BOOT-INF\classes\cn\net\hx\mdc\service\scanet\ScanetClient.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */
   private S7Serializer serializer = null;
   private int count = 0;
   private boolean connected = false;
   private final Logger logger = LoggerFactory.getLogger(getClass());
   public void connectServer() {
      if (null == this.connector)
         try {
            this.connector = S7ConnectorFactory.buildTCPConnector().withHost(this.ip).build();
            this.serializer = S7SerializerFactory.buildSerializer(this.connector);
            if (null != this.connector) {
               this.count = 0;
               this.connected = true;
            } else {
               this.connected = false;
               throw new MdcException();
            }
         } catch (Exception e) {
            this.connected = false;
            throw new MdcException();
         }
   }
   public void disconnectServer() {
      if (this.serializer != null)
         try {
            this.connector.close();
            this.connector = null;
            this.serializer = null;
         } catch (IOException e) {
            throw new MdcException();
         }
      this.count = 0;
      this.connected = false;
   }
   public void reconnectServer() {
      try {
         disconnectServer();
         connectServer();
      } catch (Exception exception) {
      }
   }
   public void checkConnection() {
      int dbNum = 21;
      int byteOffset = 35;
      try {
         byte[] read = this.connector.read(DaveArea.DB, dbNum, 50, byteOffset);
         int i;
         for (i = 1; i < read.length; i++) {
            if (read[i] != 0) {
               this.connected = true;
               break;
            }
         }
         if (i == read.length)
            this.connected = false;
         if (!this.connected) {
            reconnectServer();
            throw new MdcException();
         }
      } catch (S7Exception e) {
         this.connected = false;
         reconnectServer();
      } catch (Exception e) {
         if (++this.count >= 3)
            this.connected = false;
         throw new MdcException();
      }
   }
   public int readOpMode() {
      int dbNum = 11;
      int byteOffset1 = 6;
      int byteOffset2 = 7;
      byte autoMask = 1;
      byte mdaMask = 2;
      byte jogMask = 4;
      byte refMask = 4;
      int ret = 9000;
      try {
         PlcByteValue opModeValue1 = (PlcByteValue) this.serializer.dispense(PlcByteValue.class, dbNum, byteOffset1);
         boolean autoValue = ((opModeValue1.value & autoMask) != 0);
         boolean mdaValue = ((opModeValue1.value & mdaMask) != 0);
         boolean jogValue = ((opModeValue1.value & jogMask) != 0);
         PlcByteValue opModeValue2 = (PlcByteValue) this.serializer.dispense(PlcByteValue.class, dbNum, byteOffset2);
         boolean refValue = ((opModeValue2.value & refMask) != 0);
         ret = autoValue ? 200 : (mdaValue ? 100 : (jogValue ? 0 : (refValue ? 300 : 9000)));
         this.count = 0;
         this.connected = true;
      } catch (S7Exception e) {
         this.connected = false;
         reconnectServer();
      } catch (Exception e) {
         if (++this.count >= 3)
            this.connected = false;
         throw new MdcException();
      }
      return ret;
   }
   public int readNCState() {
      int dbNum = 21;
      int byteOffset = 35;
      byte ncStartMask = 1;
      byte ncStopMask = 4;
      int ret = 9000;
      try {
         PlcByteValue ncValue = (PlcByteValue) this.serializer.dispense(PlcByteValue.class, dbNum, byteOffset);
         boolean ncStartValue = ((ncValue.value & ncStartMask) != 0);
         boolean ncStopValue = ((ncValue.value & ncStopMask) != 0);
         ret = ncStartValue ? 0 : (ncStopValue ? 100 : 8000);
         this.count = 0;
         this.connected = true;
      } catch (S7Exception e) {
         this.connected = false;
         reconnectServer();
      } catch (Exception e) {
         if (++this.count >= 3)
            this.connected = false;
         throw new MdcException();
      }
      return ret;
   }
   public int readSpState() {
      int dbNum = 34;
      int byteOffset = 64;
      byte forwardMask = 64;
      byte reverseMask = Byte.MIN_VALUE;
      int ret = 9000;
      try {
         PlcByteValue spStateValue = (PlcByteValue) this.serializer.dispense(PlcByteValue.class, dbNum, byteOffset);
         boolean forwardValue = ((spStateValue.value & forwardMask) != 0);
         boolean reverseValue = ((spStateValue.value & reverseMask) != 0);
         ret = (forwardValue | reverseValue) ? 0 : 8000;
         this.count = 0;
         this.connected = true;
      } catch (S7Exception e) {
         this.connected = false;
         reconnectServer();
      } catch (Exception e) {
         if (++this.count >= 3)
            this.connected = false;
         throw new MdcException();
      }
      return ret;
   }
   public int readSpRate() {
      int dbNum = 34;
      int byteOffset = 19;
      int ret = 0;
      try {
         PlcByteValue spRateValue = (PlcByteValue) this.serializer.dispense(PlcByteValue.class, dbNum, byteOffset);
         ret = spRateValue.value;
         this.count = 0;
         this.connected = true;
      } catch (S7Exception e) {
         this.connected = false;
         reconnectServer();
      } catch (Exception e) {
         if (++this.count >= 3)
            this.connected = false;
         throw new MdcException();
      }
      return ret;
   }
   public int readSpSpeed() {
      int dbNum = 34;
      int byteOffset = 88;
      int ret = 0;
      try {
         PlcByteValue spRateValue = (PlcByteValue) this.serializer.dispense(PlcByteValue.class, dbNum, byteOffset);
         ret = spRateValue.value;
         this.count = 0;
         this.connected = true;
      } catch (S7Exception e) {
         this.connected = false;
         reconnectServer();
      } catch (Exception e) {
         if (++this.count >= 3)
            this.connected = false;
         throw new MdcException();
      }
      return ret;
   }
   public int readFeedRate() {
      int dbNum = 21;
      int byteOffset = 4;
      int ret = 0;
      try {
         PlcByteValue feedRateValue = (PlcByteValue) this.serializer.dispense(PlcByteValue.class, dbNum, byteOffset);
         ret = feedRateValue.value;
         this.count = 0;
         this.connected = true;
      } catch (S7Exception e) {
         this.connected = false;
         reconnectServer();
      } catch (Exception e) {
         if (++this.count >= 3)
            this.connected = false;
         throw new MdcException();
      }
      return ret;
   }
   public int readAlarmState() {
      int dbNum = 2;
      int[] userAlarmOffset = { 180, 181, 182, 183, 184, 195, 186, 187 };
      int ret = 0;
      try {
         for (int i : userAlarmOffset) {
            PlcByteValue alarmState = (PlcByteValue) this.serializer.dispense(PlcByteValue.class, dbNum, i);
            if (alarmState.value != 0) {
               ret = 1;
               break;
            }
         }
         this.count = 0;
         this.connected = true;
      } catch (S7Exception e) {
         this.connected = false;
         reconnectServer();
      } catch (Exception e) {
         if (++this.count >= 3)
            this.connected = false;
         throw new MdcException();
      }
      return ret;
   }
   public String readALARMState() {
      return null;
   }
   public String readSPState() {
      return null;
   }
   public String getIp() {
      return this.ip;
   }
   public void setIp(String ip) {
      this.ip = ip;
   }
   public boolean isConnected() {
      return this.connected;
   }
   public void setConnected(boolean connected) {
      this.connected = connected;
   }
}