|
|
@@ -116,6 +116,14 @@ public class PLCUtils {
|
|
|
}
|
|
|
|
|
|
public static StationStatus readStationStatus(StationConfig config) {
|
|
|
+ if (PlcProxyClient.isEnabled()) {
|
|
|
+ return new StationStatus(
|
|
|
+ readBoolean(config, config.getAllowStart()),
|
|
|
+ readBoolean(config, config.getAllowDown()),
|
|
|
+ readBoolean(config, config.getStartMethod()),
|
|
|
+ readBoolean(config, config.getStopMethod()),
|
|
|
+ readBoolean(config, config.getFault()));
|
|
|
+ }
|
|
|
synchronized (getPlcLock(config)) {
|
|
|
McPLC plc = getCachedPlc(config);
|
|
|
try {
|
|
|
@@ -205,6 +213,25 @@ public class PLCUtils {
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
+ if (PlcProxyClient.isEnabled()) {
|
|
|
+ try {
|
|
|
+ if ("arc".equalsIgnoreCase(type)) {
|
|
|
+ return buildArcWeldContent(null, config).toJSONString();
|
|
|
+ }
|
|
|
+ if ("spot".equalsIgnoreCase(type)) {
|
|
|
+ return buildSpotWeldContent(null, config).toJSONString();
|
|
|
+ }
|
|
|
+ if ("signal".equalsIgnoreCase(type)) {
|
|
|
+ return buildSignalContent(null, config).toJSONString();
|
|
|
+ }
|
|
|
+ log.info("鏈厤缃宸ヤ綅鐨凱LC鍙傛暟鐐逛綅锛屽伐浣?{}", config.getGw());
|
|
|
+ return "";
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("璇诲彇PLC鍙傛暟澶辫触锛屽伐浣?" + config.getGw(), e);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
synchronized (getPlcLock(config)) {
|
|
|
McPLC plc = getCachedPlc(config);
|
|
|
try {
|
|
|
@@ -287,6 +314,11 @@ public class PLCUtils {
|
|
|
private void sampleLoop() {
|
|
|
while (running) {
|
|
|
try {
|
|
|
+ if (PlcProxyClient.isEnabled()) {
|
|
|
+ addSample(readWeldingSample(null, config));
|
|
|
+ sleepQuietly(sampleIntervalMs);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
synchronized (getPlcLock(config)) {
|
|
|
McPLC plc = getCachedPlc(config);
|
|
|
try {
|
|
|
@@ -319,6 +351,10 @@ public class PLCUtils {
|
|
|
}
|
|
|
}
|
|
|
try {
|
|
|
+ if (PlcProxyClient.isEnabled()) {
|
|
|
+ addSample(readWeldingSample(null, config));
|
|
|
+ return;
|
|
|
+ }
|
|
|
synchronized (getPlcLock(config)) {
|
|
|
McPLC plc = getCachedPlc(config);
|
|
|
try {
|
|
|
@@ -373,6 +409,16 @@ public class PLCUtils {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ if (PlcProxyClient.isEnabled()) {
|
|
|
+ try {
|
|
|
+ PlcProxyClient.writeBoolean(config, address, value);
|
|
|
+ return;
|
|
|
+ } catch (RuntimeException e) {
|
|
|
+ logPlcFailure("proxyWriteBoolean", config, address, null, e);
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
synchronized (getPlcLock(config)) {
|
|
|
McPLC plc = getCachedPlc(config);
|
|
|
try {
|
|
|
@@ -388,6 +434,18 @@ public class PLCUtils {
|
|
|
|
|
|
// 读取单个 M 点状态,例如开始加工、加工结束。
|
|
|
private static boolean readBoolean(StationConfig config, String address) {
|
|
|
+ if (isEmpty(address)) {
|
|
|
+ log.warn("PLC璇诲彇璺宠繃锛氱偣浣嶅湴鍧€涓虹┖锛屽伐浣?{}", config == null ? "" : config.getGw());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (PlcProxyClient.isEnabled()) {
|
|
|
+ try {
|
|
|
+ return PlcProxyClient.readBoolean(config, address);
|
|
|
+ } catch (RuntimeException e) {
|
|
|
+ logPlcFailure("proxyReadBoolean", config, address, null, e);
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ }
|
|
|
synchronized (getPlcLock(config)) {
|
|
|
McPLC plc = getCachedPlc(config);
|
|
|
try {
|
|
|
@@ -460,34 +518,34 @@ public class PLCUtils {
|
|
|
private static JSONObject buildArcWeldSample(McPLC plc, StationConfig config) {
|
|
|
JSONObject sample = new JSONObject();
|
|
|
sample.put("time", currentTime());
|
|
|
- addScaledNumber(plc, sample, "robot1Current", config.getRobot1Current(), 1, false);
|
|
|
- addScaledNumber(plc, sample, "robot1Voltage", config.getRobot1Voltage(), 10, false);
|
|
|
- addScaledNumber(plc, sample, "robot1WeldTime", config.getRobot1Time(), 20, true);
|
|
|
- addScaledNumber(plc, sample, "robot2Current", config.getRobot2Current(), 1, false);
|
|
|
- addScaledNumber(plc, sample, "robot2Voltage", config.getRobot2Voltage(), 10, false);
|
|
|
- addScaledNumber(plc, sample, "robot2WeldTime", config.getRobot2Time(), 20, true);
|
|
|
+ addScaledNumber(plc, config, sample, "robot1Current", config.getRobot1Current(), 1, false);
|
|
|
+ addScaledNumber(plc, config, sample, "robot1Voltage", config.getRobot1Voltage(), 10, false);
|
|
|
+ addScaledNumber(plc, config, sample, "robot1WeldTime", config.getRobot1Time(), 20, true);
|
|
|
+ addScaledNumber(plc, config, sample, "robot2Current", config.getRobot2Current(), 1, false);
|
|
|
+ addScaledNumber(plc, config, sample, "robot2Voltage", config.getRobot2Voltage(), 10, false);
|
|
|
+ addScaledNumber(plc, config, sample, "robot2WeldTime", config.getRobot2Time(), 20, true);
|
|
|
return sample;
|
|
|
}
|
|
|
|
|
|
private static JSONObject buildSpotWeldSample(McPLC plc, StationConfig config) {
|
|
|
JSONObject sample = new JSONObject();
|
|
|
sample.put("time", currentTime());
|
|
|
- addIntNumber(plc, sample, "robot1Pressure", config.getRobot1Pressure());
|
|
|
- addIntNumber(plc, sample, "robot2Pressure", config.getRobot2Pressure());
|
|
|
- addScaledNumber(plc, sample, "robot1Current", config.getRobot1Current(), 100, false);
|
|
|
- addScaledNumber(plc, sample, "robot1Voltage", config.getRobot1Voltage(), 10, false);
|
|
|
- addScaledNumber(plc, sample, "robot1WeldTime", config.getRobot1Time(), 20, true);
|
|
|
- addScaledNumber(plc, sample, "robot2Current", config.getRobot2Current(), 100, false);
|
|
|
- addScaledNumber(plc, sample, "robot2Voltage", config.getRobot2Voltage(), 10, false);
|
|
|
- addScaledNumber(plc, sample, "robot2WeldTime", config.getRobot2Time(), 20, true);
|
|
|
+ addIntNumber(plc, config, sample, "robot1Pressure", config.getRobot1Pressure());
|
|
|
+ addIntNumber(plc, config, sample, "robot2Pressure", config.getRobot2Pressure());
|
|
|
+ addScaledNumber(plc, config, sample, "robot1Current", config.getRobot1Current(), 100, false);
|
|
|
+ addScaledNumber(plc, config, sample, "robot1Voltage", config.getRobot1Voltage(), 10, false);
|
|
|
+ addScaledNumber(plc, config, sample, "robot1WeldTime", config.getRobot1Time(), 20, true);
|
|
|
+ addScaledNumber(plc, config, sample, "robot2Current", config.getRobot2Current(), 100, false);
|
|
|
+ addScaledNumber(plc, config, sample, "robot2Voltage", config.getRobot2Voltage(), 10, false);
|
|
|
+ addScaledNumber(plc, config, sample, "robot2WeldTime", config.getRobot2Time(), 20, true);
|
|
|
|
|
|
JSONObject spot = new JSONObject();
|
|
|
JSONObject robot1 = new JSONObject();
|
|
|
- robot1.put("startPoints", readPointNumbers(plc, config.getRobot1Start(), 50));
|
|
|
- robot1.put("finishPoints", readPointNumbers(plc, config.getRobot1Done(), 50));
|
|
|
+ robot1.put("startPoints", readPointNumbers(plc, config, config.getRobot1Start(), 50));
|
|
|
+ robot1.put("finishPoints", readPointNumbers(plc, config, config.getRobot1Done(), 50));
|
|
|
JSONObject robot2 = new JSONObject();
|
|
|
- robot2.put("startPoints", readPointNumbers(plc, config.getRobot2Start(), 50));
|
|
|
- robot2.put("finishPoints", readPointNumbers(plc, config.getRobot2Done(), 50));
|
|
|
+ robot2.put("startPoints", readPointNumbers(plc, config, config.getRobot2Start(), 50));
|
|
|
+ robot2.put("finishPoints", readPointNumbers(plc, config, config.getRobot2Done(), 50));
|
|
|
spot.put("robot1", robot1);
|
|
|
spot.put("robot2", robot2);
|
|
|
sample.put("spot", spot);
|
|
|
@@ -500,21 +558,24 @@ public class PLCUtils {
|
|
|
|
|
|
JSONObject spot = new JSONObject();
|
|
|
JSONObject robot1 = new JSONObject();
|
|
|
- robot1.put("startPoints", readPointNumbers(plc, config.getRobot1Start(), 50));
|
|
|
- robot1.put("finishPoints", readPointNumbers(plc, config.getRobot1Done(), 50));
|
|
|
+ robot1.put("startPoints", readPointNumbers(plc, config, config.getRobot1Start(), 50));
|
|
|
+ robot1.put("finishPoints", readPointNumbers(plc, config, config.getRobot1Done(), 50));
|
|
|
JSONObject robot2 = new JSONObject();
|
|
|
- robot2.put("startPoints", readPointNumbers(plc, config.getRobot2Start(), 50));
|
|
|
- robot2.put("finishPoints", readPointNumbers(plc, config.getRobot2Done(), 50));
|
|
|
+ robot2.put("startPoints", readPointNumbers(plc, config, config.getRobot2Start(), 50));
|
|
|
+ robot2.put("finishPoints", readPointNumbers(plc, config, config.getRobot2Done(), 50));
|
|
|
spot.put("robot1", robot1);
|
|
|
spot.put("robot2", robot2);
|
|
|
sample.put("spot", spot);
|
|
|
return sample;
|
|
|
}
|
|
|
|
|
|
- private static JSONArray readPointNumbers(McPLC plc, String address, int count) {
|
|
|
+ private static JSONArray readPointNumbers(McPLC plc, StationConfig config, String address, int count) {
|
|
|
if (isEmpty(address)) {
|
|
|
return new JSONArray();
|
|
|
}
|
|
|
+ if (PlcProxyClient.isEnabled()) {
|
|
|
+ return toPointNumbers(PlcProxyClient.readBooleans(config, address, count));
|
|
|
+ }
|
|
|
return toPointNumbers(plc.readBoolean(address, count));
|
|
|
}
|
|
|
|
|
|
@@ -586,7 +647,7 @@ public class PLCUtils {
|
|
|
|
|
|
private static void addInt16(McPLC plc, List<String> values, String name, String address) {
|
|
|
if (!isEmpty(address)) {
|
|
|
- values.add(name + "=" + plc.readInt16(address));
|
|
|
+ values.add(name + "=" + readInt16(plc, null, address));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -594,27 +655,34 @@ public class PLCUtils {
|
|
|
if (isEmpty(address)) {
|
|
|
return;
|
|
|
}
|
|
|
- short raw = plc.readInt16(address);
|
|
|
+ short raw = readInt16(plc, null, address);
|
|
|
values.add(name + "原始值=" + raw);
|
|
|
double value = multiply ? raw * factor : raw * 1.0 / factor;
|
|
|
values.add(name + "=" + String.format(Locale.ROOT, "%.2f", value));
|
|
|
}
|
|
|
|
|
|
- private static void addIntNumber(McPLC plc, JSONObject sample, String name, String address) {
|
|
|
+ private static void addIntNumber(McPLC plc, StationConfig config, JSONObject sample, String name, String address) {
|
|
|
if (!isEmpty(address)) {
|
|
|
- sample.put(name, plc.readInt16(address));
|
|
|
+ sample.put(name, readInt16(plc, config, address));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static void addScaledNumber(McPLC plc, JSONObject sample, String name, String address, int factor, boolean multiply) {
|
|
|
+ private static void addScaledNumber(McPLC plc, StationConfig config, JSONObject sample, String name, String address, int factor, boolean multiply) {
|
|
|
if (isEmpty(address)) {
|
|
|
return;
|
|
|
}
|
|
|
- short raw = plc.readInt16(address);
|
|
|
+ short raw = readInt16(plc, config, address);
|
|
|
double value = multiply ? raw * factor : raw * 1.0 / factor;
|
|
|
sample.put(name, value);
|
|
|
}
|
|
|
|
|
|
+ private static short readInt16(McPLC plc, StationConfig config, String address) {
|
|
|
+ if (PlcProxyClient.isEnabled()) {
|
|
|
+ return PlcProxyClient.readInt16(config, address);
|
|
|
+ }
|
|
|
+ return plc.readInt16(address);
|
|
|
+ }
|
|
|
+
|
|
|
private static JSONArray toPointNumbers(List<Boolean> values) {
|
|
|
JSONArray points = new JSONArray();
|
|
|
for (int i = 0; i < values.size(); i++) {
|