| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package com.mes.util;
- import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
- import com.mes.ui.MesClient;
- public class PLCUtils {
- // 写入允许启动方法
- public static boolean writeStartMethod(S7PLC plc) {
- // 对plc写入ture
- plc.writeBoolean("V90.0",true);
- return true;
- }
- // 将允许启动置空
- public static boolean writeStopMethod(S7PLC plc) {
- plc.writeBoolean("V90.0",false);
- return true;
- }
- // 读取PLC结束加工信号
- public static boolean readStopMethod(S7PLC plc) {
- return plc.readBoolean("M4.0");
- }
- // 获取参数
- public static QmParam getParameter(S7PLC plc) {
- // TODO
- String leakageValue = "0.0";
- // 结果
- String result = getResult(plc);
- // 检测压
- String pressure = plc.readFloat32("VD852")+"";
- // 预充时间
- String preChargeTime = plc.readInt16("VW2048")+"";
- // 充气时间
- String chargeTime = Math.round(plc.readInt16("VW504") / 10.0) + "";
- // 平衡时间
- String balanceTime = Math.round(plc.readInt16("VW506") / 10.0) + "";
- // 检测时间
- String detectTime = Math.round(plc.readInt16("VW508") / 10.0) + "";
- //循环时间
- String loopTime = Math.round(plc.readInt16("VW850") / 10.0) + "";
- QmParam qmParam = new QmParam();
- qmParam.setLeakRateUnit("kPa");
- qmParam.setLeakValUnit("kPa");
- qmParam.setTestPressure(pressure);
- qmParam.setTestPressureUnit("kPa");
- qmParam.setTestResult(result);
- qmParam.setCqDuration(chargeTime);
- qmParam.setByDuration(balanceTime);
- qmParam.setCsDuration(detectTime);
- qmParam.setDeviceType(MesClient.csyq);
- qmParam.setTestPace(loopTime);
- long start = System.currentTimeMillis();
- final long MAX_WAIT = 5000;
- while (true){
- leakageValue = plc.readString("VB307", 7);
- // 条件1:读取到非空,直接跳出循环
- if (leakageValue != null && !leakageValue.trim().isEmpty()) {
- break;
- }
- long now = System.currentTimeMillis();
- if (now - start >= MAX_WAIT) {
- break;
- }
- try {
- Thread.sleep(50);
- } catch (InterruptedException e) {
- break;
- }
- }
- qmParam.setLeakVal(leakageValue);
- return qmParam;
- }
- public static String getResult(S7PLC plc){
- byte data = plc.readByte("VB503");
- switch (data) {
- case 2:
- return "OK";
- case 3:
- return "NG";
- default:
- return "未知状态";
- }
- }
- }
|