|
|
@@ -0,0 +1,585 @@
|
|
|
+package com.mes.util;
|
|
|
+
|
|
|
+import com.github.xingshuangs.iot.protocol.melsec.enums.EMcSeries;
|
|
|
+import com.github.xingshuangs.iot.protocol.melsec.service.McPLC;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.InetSocketAddress;
|
|
|
+import java.net.Socket;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
+import java.util.Scanner;
|
|
|
+
|
|
|
+public class PLCPointTestMain {
|
|
|
+
|
|
|
+ private static final int Q26_PORT = 8000;
|
|
|
+ private static final int FX5U_SLMP_PORT = 5001;
|
|
|
+ private static final int CONNECT_TIMEOUT_MS = 2000;
|
|
|
+ private static final List<StationPoint> STATIONS = new ArrayList<>();
|
|
|
+
|
|
|
+ static {
|
|
|
+ STATIONS.add(StationPoint.spot("OP40", "192.168.0.35", Q26_PORT, EMcSeries.QnA,
|
|
|
+ "M6601", "M6602", "M6603", "M6604", "M6605",
|
|
|
+ "M6700", "M6750", "M6800", "M6850",
|
|
|
+ "D7001", "D7002", "D7051", "D7061", "D7052", "D7062"));
|
|
|
+ STATIONS.add(StationPoint.bitOnly("OP70", "192.168.0.35", Q26_PORT, EMcSeries.QnA,
|
|
|
+ "M6611", "M6612", "M6613", "M6614", "M6615",
|
|
|
+ "M6900", "M6950", "M7000", "M7050"));
|
|
|
+ STATIONS.add(StationPoint.spot("OP30", "192.168.0.35", Q26_PORT, EMcSeries.QnA,
|
|
|
+ "M6621", "M6622", "M6623", "M6624", "M6625",
|
|
|
+ "M7100", "M7150", "M7200", "M7250",
|
|
|
+ "D7003", "D7004", "D7071", "D7081", "D7072", "D7082"));
|
|
|
+ STATIONS.add(StationPoint.bitOnly("OP80", "192.168.0.35", Q26_PORT, EMcSeries.QnA,
|
|
|
+ "M6631", "M6632", "M6633", "M6634", "M6635",
|
|
|
+ "M7300", "M7350", "M7400", "M7450"));
|
|
|
+ STATIONS.add(StationPoint.spot("OP20", "192.168.0.35", Q26_PORT, EMcSeries.QnA,
|
|
|
+ "M6641", "M6642", "M6643", "M6644", "M6645",
|
|
|
+ "M7500", "M7550", "M7600", "M7650",
|
|
|
+ "D7005", "D7006", "D7091", "D7101", "D7092", "D7102"));
|
|
|
+ STATIONS.add(StationPoint.bitOnly("OP90", "192.168.0.35", Q26_PORT, EMcSeries.QnA,
|
|
|
+ "M6651", "M6652", "M6653", "M6654", "M6655",
|
|
|
+ "M7700", "M7750", "M7800", "M7850"));
|
|
|
+ STATIONS.add(StationPoint.arc("OP10", "192.168.0.35", Q26_PORT, EMcSeries.QnA,
|
|
|
+ "M6661", "M6662", "M6663", "M6664", "M6665",
|
|
|
+ "4号机器人", "D7041", "D7042",
|
|
|
+ "3号机器人", "D7031", "D7032"));
|
|
|
+ STATIONS.add(StationPoint.simple("OP100", "192.168.0.35", Q26_PORT, EMcSeries.QnA,
|
|
|
+ "M6671", "M6672", "M6673", "M6674", "M6675"));
|
|
|
+ STATIONS.add(StationPoint.arc("OP120", "192.168.0.35", Q26_PORT, EMcSeries.QnA,
|
|
|
+ "M6681", "M6682", "M6683", "M6684", "M6685",
|
|
|
+ "2号机器人", "D7021", "D7022",
|
|
|
+ "1号机器人", "D7011", "D7012"));
|
|
|
+ STATIONS.add(StationPoint.simple("OP110", "192.168.0.35", Q26_PORT, EMcSeries.QnA,
|
|
|
+ "M6691", "M6692", "M6693", "M6694", "M6695"));
|
|
|
+
|
|
|
+ // 192.168.0.10 是 SLMP 通讯,现场测试 5001 端口可读。
|
|
|
+ STATIONS.add(StationPoint.spot("OP50", "192.168.0.10", FX5U_SLMP_PORT, EMcSeries.Q_L,
|
|
|
+ "M6001", "M6002", "M6003", "M6004", "M6005",
|
|
|
+ "M6100", "M6150", "M6300", "M6350",
|
|
|
+ "D6001", "D6011", "D6002", "D6012", "D6003", "D6013"));
|
|
|
+ STATIONS.add(StationPoint.bitOnly("OP60", "192.168.0.10", FX5U_SLMP_PORT, EMcSeries.Q_L,
|
|
|
+ "M6011", "M6012", "M6013", "M6014", "M6015",
|
|
|
+ "M6200", "M6250", "M6400", "M6450"));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ System.out.println("PLC点位测试工具启动:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
+ System.out.println("说明:输入工位号读取该工位点位;输入 ALL 读取全部;输入 Q 退出。");
|
|
|
+ printStationList();
|
|
|
+
|
|
|
+ Scanner scanner = new Scanner(System.in);
|
|
|
+ while (true) {
|
|
|
+ System.out.println();
|
|
|
+ System.out.print("请输入要测试的工位号,例如 OP40 / OP50 / ALL / Q:");
|
|
|
+ String input = scanner.nextLine();
|
|
|
+ if (input == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String command = input.trim().toUpperCase(Locale.ROOT);
|
|
|
+ if (command.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ("Q".equals(command) || "QUIT".equals(command) || "EXIT".equals(command)) {
|
|
|
+ System.out.println("已退出PLC点位测试。");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if ("ALL".equals(command) || "全部".equals(command)) {
|
|
|
+ for (StationPoint station : STATIONS) {
|
|
|
+ testStation(station);
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ StationPoint station = findStation(command);
|
|
|
+ if (station == null) {
|
|
|
+ System.out.println("未找到工位:" + command);
|
|
|
+ printStationList();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ handleStation(scanner, station);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void handleStation(Scanner scanner, StationPoint station) {
|
|
|
+ while (true) {
|
|
|
+ System.out.println();
|
|
|
+ System.out.println("已选择工位:" + station.code + "(PLC:" + station.ip + ":" + station.port
|
|
|
+ + ",系列:" + station.series + ",允许启动点位:" + station.allowStart + ")");
|
|
|
+ System.out.println("请选择操作:");
|
|
|
+ System.out.println(" 1:读取该工位全部点位");
|
|
|
+ System.out.println(" 2:手动写允许启动 = true");
|
|
|
+ System.out.println(" 3:手动写允许启动 = false");
|
|
|
+ System.out.println(" 4:测试该PLC常见端口");
|
|
|
+ System.out.println(" 5:临时修改该工位PLC端口");
|
|
|
+ System.out.println(" 6:临时切换该工位PLC系列");
|
|
|
+ System.out.println(" 7:诊断允许启动写入方式");
|
|
|
+ System.out.println(" B:返回工位选择");
|
|
|
+ System.out.print("请输入:");
|
|
|
+
|
|
|
+ String input = scanner.nextLine();
|
|
|
+ if (input == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String command = input.trim().toUpperCase(Locale.ROOT);
|
|
|
+ if (command.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ("B".equals(command) || "BACK".equals(command)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if ("1".equals(command) || "R".equals(command) || "READ".equals(command) || "读取".equals(command)) {
|
|
|
+ testStation(station);
|
|
|
+ } else if ("2".equals(command) || "T".equals(command) || "TRUE".equals(command)) {
|
|
|
+ writeAllowStart(station, true);
|
|
|
+ } else if ("3".equals(command) || "F".equals(command) || "FALSE".equals(command)) {
|
|
|
+ writeAllowStart(station, false);
|
|
|
+ } else if ("4".equals(command) || "PORT".equals(command)) {
|
|
|
+ testPorts(station.ip);
|
|
|
+ } else if ("5".equals(command) || "SETPORT".equals(command)) {
|
|
|
+ changeStationPort(scanner, station);
|
|
|
+ } else if ("6".equals(command) || "SETSERIES".equals(command)) {
|
|
|
+ changeStationSeries(scanner, station);
|
|
|
+ } else if ("7".equals(command) || "WRITEDEBUG".equals(command)) {
|
|
|
+ diagnoseAllowStartWrite(scanner, station);
|
|
|
+ } else {
|
|
|
+ System.out.println("输入无效,请输入 1 / 2 / 3 / 4 / 5 / 6 / 7 / B。");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void testStation(StationPoint station) {
|
|
|
+ printStationTitle(station);
|
|
|
+ printPlcConnectTip(station);
|
|
|
+
|
|
|
+ McPLC plc = createPlc(station);
|
|
|
+ try {
|
|
|
+ plc.setConnectTimeout(CONNECT_TIMEOUT_MS);
|
|
|
+ plc.setReceiveTimeout(3000);
|
|
|
+
|
|
|
+ readBoolean(plc, "允许启动", station.allowStart);
|
|
|
+ readBoolean(plc, "允许下料", station.allowDown);
|
|
|
+ readBoolean(plc, "开始加工", station.start);
|
|
|
+ readBoolean(plc, "加工结束", station.finish);
|
|
|
+ readBoolean(plc, "故障", station.fault);
|
|
|
+
|
|
|
+ if ("spot".equals(station.type) || "bitOnly".equals(station.type)) {
|
|
|
+ readBooleanRange(plc, "1号机器人焊接开始", station.robot1Start, 50);
|
|
|
+ readBooleanRange(plc, "1号机器人焊接完成", station.robot1Done, 50);
|
|
|
+ readBooleanRange(plc, "2号机器人焊接开始", station.robot2Start, 50);
|
|
|
+ readBooleanRange(plc, "2号机器人焊接完成", station.robot2Done, 50);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ("spot".equals(station.type)) {
|
|
|
+ readInt16(plc, "1号机器人压力", station.robot1Pressure);
|
|
|
+ readInt16(plc, "2号机器人压力", station.robot2Pressure);
|
|
|
+ readScaledInt16(plc, "1号机器人焊接电流(A)", station.robot1Current, 100, false);
|
|
|
+ readScaledInt16(plc, "2号机器人焊接电流(A)", station.robot2Current, 100, false);
|
|
|
+ readScaledInt16(plc, "1号机器人焊接时间(ms)", station.robot1Time, 20, true);
|
|
|
+ readScaledInt16(plc, "2号机器人焊接时间(ms)", station.robot2Time, 20, true);
|
|
|
+ } else if ("arc".equals(station.type)) {
|
|
|
+ readInt16(plc, station.upperRobotName + "电流", station.upperCurrent);
|
|
|
+ readScaledInt16(plc, station.upperRobotName + "电压(V)", station.upperVoltage, 10, false);
|
|
|
+ readInt16(plc, station.lowerRobotName + "电流", station.lowerCurrent);
|
|
|
+ readScaledInt16(plc, station.lowerRobotName + "电压(V)", station.lowerVoltage, 10, false);
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ plc.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void writeAllowStart(StationPoint station, boolean value) {
|
|
|
+ System.out.println();
|
|
|
+ System.out.println("准备写入:" + station.code + " 允许启动 " + station.allowStart + " = " + value);
|
|
|
+ printPlcConnectTip(station);
|
|
|
+
|
|
|
+ McPLC plc = createPlc(station);
|
|
|
+ try {
|
|
|
+ plc.setConnectTimeout(CONNECT_TIMEOUT_MS);
|
|
|
+ plc.setReceiveTimeout(3000);
|
|
|
+
|
|
|
+ System.out.println("写入方式:单点写。");
|
|
|
+ System.out.println(" " + station.allowStart + " = " + value);
|
|
|
+ plc.writeBoolean(station.allowStart, value);
|
|
|
+ System.out.println("写入命令已完成,正在重新连接读取确认:");
|
|
|
+ } catch (Exception e) {
|
|
|
+ printError("允许启动写入", station.allowStart, e);
|
|
|
+ } finally {
|
|
|
+ plc.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ sleep(300);
|
|
|
+ confirmAllowStart(station);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void diagnoseAllowStartWrite(Scanner scanner, StationPoint station) {
|
|
|
+ System.out.println();
|
|
|
+ System.out.println("写入诊断会直接写 " + station.allowStart + ",请确认设备处于允许测试状态。");
|
|
|
+ System.out.print("请输入要写入的值 true / false,或输入 B 返回:");
|
|
|
+ String input = scanner.nextLine();
|
|
|
+ if (input == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String command = input.trim().toUpperCase(Locale.ROOT);
|
|
|
+ if ("B".equals(command) || "BACK".equals(command)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!"TRUE".equals(command) && !"FALSE".equals(command)) {
|
|
|
+ System.out.println("输入无效,本次不写入。");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean value = Boolean.parseBoolean(command.toLowerCase(Locale.ROOT));
|
|
|
+ System.out.println("诊断目标:" + station.code + " " + station.ip + ":" + station.port
|
|
|
+ + ",系列:" + station.series + ",点位:" + station.allowStart + " = " + value);
|
|
|
+
|
|
|
+ System.out.println();
|
|
|
+ System.out.println("步骤1:写入前读取确认。");
|
|
|
+ confirmAllowStart(station);
|
|
|
+
|
|
|
+ System.out.println();
|
|
|
+ System.out.println("步骤2:单点写入测试。");
|
|
|
+ writeAllowStartSingle(station, value);
|
|
|
+ sleep(800);
|
|
|
+ confirmAllowStart(station);
|
|
|
+
|
|
|
+ System.out.println();
|
|
|
+ System.out.println("步骤3:连续2个位写入测试。");
|
|
|
+ writeAllowStartBatch(station, value);
|
|
|
+ sleep(800);
|
|
|
+ confirmAllowStart(station);
|
|
|
+
|
|
|
+ System.out.println();
|
|
|
+ System.out.println("诊断说明:如果单点写成功、连续写失败,菜单2/3应使用单点写;说明该PLC不适合用连续位写方式操作允许启动。");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void writeAllowStartSingle(StationPoint station, boolean value) {
|
|
|
+ printPlcConnectTip(station);
|
|
|
+ McPLC plc = createPlc(station);
|
|
|
+ try {
|
|
|
+ plc.setConnectTimeout(CONNECT_TIMEOUT_MS);
|
|
|
+ plc.setReceiveTimeout(3000);
|
|
|
+ System.out.println(" 单点写:" + station.allowStart + " = " + value);
|
|
|
+ plc.writeBoolean(station.allowStart, value);
|
|
|
+ System.out.println(" 单点写命令已完成。");
|
|
|
+ } catch (Exception e) {
|
|
|
+ printError("单点写允许启动", station.allowStart, e);
|
|
|
+ } finally {
|
|
|
+ plc.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void writeAllowStartBatch(StationPoint station, boolean value) {
|
|
|
+ printPlcConnectTip(station);
|
|
|
+ McPLC plc = createPlc(station);
|
|
|
+ try {
|
|
|
+ plc.setConnectTimeout(CONNECT_TIMEOUT_MS);
|
|
|
+ plc.setReceiveTimeout(3000);
|
|
|
+ boolean allowDownNow = plc.readBoolean(station.allowDown);
|
|
|
+ System.out.println(" 连续写2个位:" + station.allowStart + " = " + value
|
|
|
+ + "," + station.allowDown + " = " + allowDownNow + "(保持原值)");
|
|
|
+ plc.writeBoolean(station.allowStart, Arrays.asList(value, allowDownNow));
|
|
|
+ System.out.println(" 连续写命令已完成。");
|
|
|
+ } catch (Exception e) {
|
|
|
+ printError("连续写允许启动", station.allowStart, e);
|
|
|
+ } finally {
|
|
|
+ plc.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void confirmAllowStart(StationPoint station) {
|
|
|
+ McPLC plc = createPlc(station);
|
|
|
+ try {
|
|
|
+ plc.setConnectTimeout(CONNECT_TIMEOUT_MS);
|
|
|
+ plc.setReceiveTimeout(3000);
|
|
|
+ readBoolean(plc, "允许启动确认", station.allowStart);
|
|
|
+ readBoolean(plc, "允许下料确认", station.allowDown);
|
|
|
+ } catch (Exception e) {
|
|
|
+ printError("写入后确认读取", station.allowStart, e);
|
|
|
+ } finally {
|
|
|
+ plc.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static McPLC createPlc(StationPoint station) {
|
|
|
+ return new McPLC(station.series, station.ip, station.port);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void printPlcConnectTip(StationPoint station) {
|
|
|
+ System.out.println("准备通过SLMP/MC连接PLC:" + station.ip + ":" + station.port
|
|
|
+ + ",系列:" + station.series + ",超时 " + CONNECT_TIMEOUT_MS + "ms ...");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean checkConnection(String ip, int port) {
|
|
|
+ System.out.println("正在连接PLC:" + ip + ":" + port + ",超时 " + CONNECT_TIMEOUT_MS + "ms ...");
|
|
|
+ try (Socket socket = new Socket()) {
|
|
|
+ socket.connect(new InetSocketAddress(ip, port), CONNECT_TIMEOUT_MS);
|
|
|
+ System.out.println("PLC连接成功。");
|
|
|
+ return true;
|
|
|
+ } catch (IOException e) {
|
|
|
+ System.out.println("PLC连接失败:" + e.getMessage());
|
|
|
+ System.out.println("请检查:IP能ping通不等于SLMP/MC端口可用,需要确认PLC开放的TCP端口。");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void testPorts(String ip) {
|
|
|
+ int[] ports = {5000, 5001, 5002, 8000};
|
|
|
+ System.out.println("开始测试 " + ip + " 的常见SLMP/MC端口...");
|
|
|
+ for (int port : ports) {
|
|
|
+ boolean ok = checkConnection(ip, port);
|
|
|
+ System.out.println(" " + ip + ":" + port + " -> " + (ok ? "通" : "不通"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void changeStationPort(Scanner scanner, StationPoint station) {
|
|
|
+ System.out.println("当前工位 " + station.code + " 端口=" + station.port);
|
|
|
+ System.out.print("请输入新端口,例如 5000 / 5001 / 8000:");
|
|
|
+ String input = scanner.nextLine();
|
|
|
+ try {
|
|
|
+ int port = Integer.parseInt(input.trim());
|
|
|
+ station.port = port;
|
|
|
+ System.out.println("已将 " + station.code + " 端口改为 " + port + ",可立即输入 1 读取测试。");
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("端口输入无效。");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void changeStationSeries(Scanner scanner, StationPoint station) {
|
|
|
+ System.out.println("当前工位 " + station.code + " 系列=" + station.series);
|
|
|
+ System.out.println("可选:1=QnA,2=Q_L,3=IQ_R");
|
|
|
+ System.out.print("请输入:");
|
|
|
+ String input = scanner.nextLine();
|
|
|
+ if ("1".equals(input.trim())) {
|
|
|
+ station.series = EMcSeries.QnA;
|
|
|
+ } else if ("2".equals(input.trim())) {
|
|
|
+ station.series = EMcSeries.Q_L;
|
|
|
+ } else if ("3".equals(input.trim())) {
|
|
|
+ station.series = EMcSeries.IQ_R;
|
|
|
+ } else {
|
|
|
+ System.out.println("系列输入无效。");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ System.out.println("已将 " + station.code + " 系列改为 " + station.series + ",可立即输入 1 读取测试。");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void readBoolean(McPLC plc, String name, String address) {
|
|
|
+ try {
|
|
|
+ System.out.printf(" %-24s %-12s = %s%n", name, address, toChineseBoolean(plc.readBoolean(address)));
|
|
|
+ } catch (Exception e) {
|
|
|
+ printError(name, address, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void readBooleanRange(McPLC plc, String name, String startAddress, int count) {
|
|
|
+ try {
|
|
|
+ List<Boolean> values = plc.readBoolean(startAddress, count);
|
|
|
+ System.out.printf(" %-24s %-12s 置位数量=%d 明细=%s%n",
|
|
|
+ name, formatBitRange(startAddress, count), countTrue(values), toChineseBooleanList(values));
|
|
|
+ } catch (Exception e) {
|
|
|
+ printError(name, startAddress, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void readInt16(McPLC plc, String name, String address) {
|
|
|
+ try {
|
|
|
+ System.out.printf(" %-24s %-12s = %d%n", name, address, plc.readInt16(address));
|
|
|
+ } catch (Exception e) {
|
|
|
+ printError(name, address, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void readScaledInt16(McPLC plc, String name, String address, int factor, boolean multiply) {
|
|
|
+ try {
|
|
|
+ short raw = plc.readInt16(address);
|
|
|
+ double value = multiply ? raw * factor : raw * 1.0 / factor;
|
|
|
+ String formula = multiply ? "原始值*" + factor : "原始值/" + factor;
|
|
|
+ System.out.printf(Locale.ROOT, " %-24s %-12s 原始值=%d 换算值=%.2f(%s)%n",
|
|
|
+ name, address, raw, value, formula);
|
|
|
+ } catch (Exception e) {
|
|
|
+ printError(name, address, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static StationPoint findStation(String stationCode) {
|
|
|
+ for (StationPoint station : STATIONS) {
|
|
|
+ if (station.code.equalsIgnoreCase(stationCode)) {
|
|
|
+ return station;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void printStationList() {
|
|
|
+ System.out.println("可测试工位:");
|
|
|
+ for (StationPoint station : STATIONS) {
|
|
|
+ System.out.println(" " + station.code + "(PLC:" + station.ip + ":" + station.port
|
|
|
+ + ",系列:" + station.series + ",类型:" + station.typeName() + ")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static int countTrue(List<Boolean> values) {
|
|
|
+ int count = 0;
|
|
|
+ for (Boolean value : values) {
|
|
|
+ if (Boolean.TRUE.equals(value)) {
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String formatBitRange(String startAddress, int count) {
|
|
|
+ String prefix = startAddress.substring(0, 1);
|
|
|
+ int start = Integer.parseInt(startAddress.substring(1));
|
|
|
+ return prefix + start + "-" + prefix + (start + count - 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String toChineseBoolean(boolean value) {
|
|
|
+ return value ? "有信号(true)" : "无信号(false)";
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String toChineseBooleanList(List<Boolean> values) {
|
|
|
+ StringBuilder sb = new StringBuilder("[");
|
|
|
+ for (int i = 0; i < values.size(); i++) {
|
|
|
+ if (i > 0) {
|
|
|
+ sb.append(",");
|
|
|
+ }
|
|
|
+ sb.append(Boolean.TRUE.equals(values.get(i)) ? "1" : "0");
|
|
|
+ }
|
|
|
+ sb.append("]");
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void printStationTitle(StationPoint station) {
|
|
|
+ System.out.println();
|
|
|
+ System.out.println("============================================================");
|
|
|
+ System.out.println("开始读取:" + station.code + ",PLC:" + station.ip + ":" + station.port
|
|
|
+ + ",系列:" + station.series + ",类型:" + station.typeName());
|
|
|
+ System.out.println("============================================================");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void printError(String name, String address, Exception e) {
|
|
|
+ System.out.printf(" %-24s %-12s 操作失败:%s%n", name, address, e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void sleep(long millis) {
|
|
|
+ try {
|
|
|
+ Thread.sleep(millis);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static class StationPoint {
|
|
|
+ String code;
|
|
|
+ String ip;
|
|
|
+ int port;
|
|
|
+ EMcSeries series;
|
|
|
+ String type;
|
|
|
+ String allowStart;
|
|
|
+ String allowDown;
|
|
|
+ String start;
|
|
|
+ String finish;
|
|
|
+ String fault;
|
|
|
+ String robot1Start;
|
|
|
+ String robot1Done;
|
|
|
+ String robot2Start;
|
|
|
+ String robot2Done;
|
|
|
+ String robot1Pressure;
|
|
|
+ String robot2Pressure;
|
|
|
+ String robot1Current;
|
|
|
+ String robot2Current;
|
|
|
+ String robot1Time;
|
|
|
+ String robot2Time;
|
|
|
+ String upperRobotName;
|
|
|
+ String upperCurrent;
|
|
|
+ String upperVoltage;
|
|
|
+ String lowerRobotName;
|
|
|
+ String lowerCurrent;
|
|
|
+ String lowerVoltage;
|
|
|
+
|
|
|
+ static StationPoint simple(String code, String ip, int port, EMcSeries series,
|
|
|
+ String allowStart, String allowDown, String start,
|
|
|
+ String finish, String fault) {
|
|
|
+ return base(code, ip, port, series, "simple", allowStart, allowDown, start, finish, fault);
|
|
|
+ }
|
|
|
+
|
|
|
+ static StationPoint bitOnly(String code, String ip, int port, EMcSeries series,
|
|
|
+ String allowStart, String allowDown, String start,
|
|
|
+ String finish, String fault, String robot1Start, String robot1Done,
|
|
|
+ String robot2Start, String robot2Done) {
|
|
|
+ StationPoint point = base(code, ip, port, series, "bitOnly", allowStart, allowDown, start, finish, fault);
|
|
|
+ point.robot1Start = robot1Start;
|
|
|
+ point.robot1Done = robot1Done;
|
|
|
+ point.robot2Start = robot2Start;
|
|
|
+ point.robot2Done = robot2Done;
|
|
|
+ return point;
|
|
|
+ }
|
|
|
+
|
|
|
+ static StationPoint spot(String code, String ip, int port, EMcSeries series,
|
|
|
+ String allowStart, String allowDown, String start,
|
|
|
+ String finish, String fault, String robot1Start, String robot1Done,
|
|
|
+ String robot2Start, String robot2Done, String robot1Pressure, String robot2Pressure,
|
|
|
+ String robot1Current, String robot2Current, String robot1Time, String robot2Time) {
|
|
|
+ StationPoint point = bitOnly(code, ip, port, series, allowStart, allowDown, start, finish, fault,
|
|
|
+ robot1Start, robot1Done, robot2Start, robot2Done);
|
|
|
+ point.type = "spot";
|
|
|
+ point.robot1Pressure = robot1Pressure;
|
|
|
+ point.robot2Pressure = robot2Pressure;
|
|
|
+ point.robot1Current = robot1Current;
|
|
|
+ point.robot2Current = robot2Current;
|
|
|
+ point.robot1Time = robot1Time;
|
|
|
+ point.robot2Time = robot2Time;
|
|
|
+ return point;
|
|
|
+ }
|
|
|
+
|
|
|
+ static StationPoint arc(String code, String ip, int port, EMcSeries series,
|
|
|
+ String allowStart, String allowDown, String start,
|
|
|
+ String finish, String fault, String upperRobotName, String upperCurrent,
|
|
|
+ String upperVoltage, String lowerRobotName, String lowerCurrent, String lowerVoltage) {
|
|
|
+ StationPoint point = base(code, ip, port, series, "arc", allowStart, allowDown, start, finish, fault);
|
|
|
+ point.upperRobotName = upperRobotName;
|
|
|
+ point.upperCurrent = upperCurrent;
|
|
|
+ point.upperVoltage = upperVoltage;
|
|
|
+ point.lowerRobotName = lowerRobotName;
|
|
|
+ point.lowerCurrent = lowerCurrent;
|
|
|
+ point.lowerVoltage = lowerVoltage;
|
|
|
+ return point;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static StationPoint base(String code, String ip, int port, EMcSeries series, String type,
|
|
|
+ String allowStart, String allowDown,
|
|
|
+ String start, String finish, String fault) {
|
|
|
+ StationPoint point = new StationPoint();
|
|
|
+ point.code = code;
|
|
|
+ point.ip = ip;
|
|
|
+ point.port = port;
|
|
|
+ point.series = series;
|
|
|
+ point.type = type;
|
|
|
+ point.allowStart = allowStart;
|
|
|
+ point.allowDown = allowDown;
|
|
|
+ point.start = start;
|
|
|
+ point.finish = finish;
|
|
|
+ point.fault = fault;
|
|
|
+ return point;
|
|
|
+ }
|
|
|
+
|
|
|
+ String typeName() {
|
|
|
+ if ("spot".equals(type)) {
|
|
|
+ return "点焊";
|
|
|
+ }
|
|
|
+ if ("arc".equals(type)) {
|
|
|
+ return "弧焊";
|
|
|
+ }
|
|
|
+ if ("bitOnly".equals(type)) {
|
|
|
+ return "焊点信号";
|
|
|
+ }
|
|
|
+ return "基础信号";
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|