|
|
@@ -1,5 +1,7 @@
|
|
|
package com.jeesite.test;
|
|
|
|
|
|
+import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
|
|
|
+import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
|
|
|
import com.jeesite.common.config.Global;
|
|
|
import com.jeesite.common.lang.StringUtils;
|
|
|
import com.jeesite.common.tests.BaseSpringContextTests;
|
|
|
@@ -16,12 +18,13 @@ import org.springframework.test.context.ActiveProfiles;
|
|
|
/**
|
|
|
* 涂胶 / FSW 定时任务质量校验联调测试。
|
|
|
* <p>
|
|
|
- * 覆盖以下类的 {@code checkQualityCommon} 调用逻辑,不连接 PLC/Modbus:
|
|
|
+ * 覆盖以下类的 {@code checkQualityCommon} 调用逻辑:
|
|
|
* <ul>
|
|
|
* <li>{@link com.jeesite.modules.scheduling.ProductTjScheduling}(OP220)</li>
|
|
|
* <li>{@link com.jeesite.modules.scheduling.ProductTjBScheduling}(mes.tj.b.oprno)</li>
|
|
|
* <li>{@link com.jeesite.modules.scheduling.FswModbusScheduling}(mes.fsw.modbus.oprno)</li>
|
|
|
* </ul>
|
|
|
+ * 另含 ProductTjScheduling 写 DB1300.64.2 的 PLC 联调(需连涂胶 PLC)。
|
|
|
* <p>
|
|
|
* 使用方式:
|
|
|
* <ul>
|
|
|
@@ -36,7 +39,7 @@ public class ProductTjQualityCheckTest extends BaseSpringContextTests {
|
|
|
// ===================== 自行填写 =====================
|
|
|
|
|
|
/** 待测工件码(必填) */
|
|
|
- private static final String TEST_SN = "0050010200173E5240017067171A02";
|
|
|
+ private static final String TEST_SN = "0050010200173E5240017067251A22";
|
|
|
|
|
|
/** 产线编号,与 application.yml 中 mes.tj.lineSn / mes.tj.b.lineSn 一致 */
|
|
|
private static final String TEST_LINE_SN = "XT";
|
|
|
@@ -56,12 +59,20 @@ public class ProductTjQualityCheckTest extends BaseSpringContextTests {
|
|
|
*/
|
|
|
private static final String FSW_LINE_SN = "XT";
|
|
|
|
|
|
+ /**
|
|
|
+ * 涂胶 PLC IP;留空则读取 mes.tj.plc.ip,仍为空则使用 10.0.40.100
|
|
|
+ */
|
|
|
+ private static final String TJ_PLC_IP = "";
|
|
|
+
|
|
|
// ===================== 自行填写结束 =====================
|
|
|
|
|
|
/** ProductTjScheduling 固定工位号 */
|
|
|
private static final String TJ_A_OPRNO = "OP220";
|
|
|
|
|
|
- private static final String DEFAULT_TJ_B_OPRNO = "OP240B";
|
|
|
+ private static final String DEFAULT_TJ_B_OPRNO = "OP240";
|
|
|
+ private static final String DEFAULT_TJ_PLC_IP = "10.0.40.100";
|
|
|
+ /** 与 ProductTjScheduling.ADDR_QUALITY_PASS 一致 */
|
|
|
+ private static final String ADDR_QUALITY_PASS = "DB1300.64.2";
|
|
|
|
|
|
@Autowired
|
|
|
private MesProductRecordController mesProductRecordController;
|
|
|
@@ -105,7 +116,17 @@ public class ProductTjQualityCheckTest extends BaseSpringContextTests {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 手动联调:依次执行涂胶 A/B 与 FSW 质量校验。
|
|
|
+ * 模拟 ProductTjScheduling 写 DB1300.64.2=true(不做质量校验,直接写点位)。
|
|
|
+ * 需涂胶 PLC 可达(mes.tj.plc.ip)。
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testProductTjSchedulingWriteQualityPass64_2() {
|
|
|
+ boolean written = writeQualityPassLikeTjScheduling(true);
|
|
|
+ org.junit.Assert.assertTrue("写 DB1300.64.2=true 失败(检查 PLC 连通性)", written);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 手动联调:依次执行涂胶 A/B 与 FSW 质量校验,以及 A 侧写 64.2。
|
|
|
*/
|
|
|
public static void main(String[] args) {
|
|
|
if (StringUtils.isBlank(TEST_SN)) {
|
|
|
@@ -113,7 +134,7 @@ public class ProductTjQualityCheckTest extends BaseSpringContextTests {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- System.out.println("========== 涂胶/FSW 质量校验联调(不连 PLC/Modbus)==========");
|
|
|
+ System.out.println("========== 涂胶/FSW 质量校验联调 ==========");
|
|
|
ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
|
|
|
try {
|
|
|
MesProductRecordController controller = ctx.getBean(MesProductRecordController.class);
|
|
|
@@ -127,6 +148,10 @@ public class ProductTjQualityCheckTest extends BaseSpringContextTests {
|
|
|
QualityCheckResult aResult = tester.checkQualityLikeTjScheduling(sn, lineSn);
|
|
|
printResult("ProductTjScheduling", TJ_A_OPRNO, aResult, lineSn);
|
|
|
|
|
|
+ System.out.println("\n--- ProductTjScheduling 写 DB1300.64.2=true(跳过质量校验)---");
|
|
|
+ boolean ok = writeQualityPassLikeTjScheduling(true);
|
|
|
+ System.out.println(ok ? "写 64.2=true 成功" : "写 64.2=true 失败");
|
|
|
+
|
|
|
String bOprno = resolveTjBOprnoStatic();
|
|
|
System.out.println("\n--- ProductTjBScheduling (" + bOprno + ") ---");
|
|
|
QualityCheckResult bResult = tester.checkQualityLikeTjBScheduling(sn, lineSn, bOprno);
|
|
|
@@ -157,6 +182,47 @@ public class ProductTjQualityCheckTest extends BaseSpringContextTests {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 直接写 DB1300.64.2(不做质量校验),并回读确认。
|
|
|
+ *
|
|
|
+ * @param value true=质量通过反馈,false=复位
|
|
|
+ * @return true=写入并回读一致
|
|
|
+ */
|
|
|
+ static boolean writeQualityPassLikeTjScheduling(boolean value) {
|
|
|
+ String ip = resolveTjPlcIp();
|
|
|
+ S7PLC s7PLC = null;
|
|
|
+ try {
|
|
|
+ System.out.println("连接涂胶 PLC: " + ip);
|
|
|
+ s7PLC = new S7PLC(EPlcType.S1200, ip);
|
|
|
+ boolean before = s7PLC.readBoolean(ADDR_QUALITY_PASS);
|
|
|
+ System.out.println("写前 " + ADDR_QUALITY_PASS + "=" + before);
|
|
|
+
|
|
|
+ s7PLC.writeBoolean(ADDR_QUALITY_PASS, value);
|
|
|
+ boolean after = s7PLC.readBoolean(ADDR_QUALITY_PASS);
|
|
|
+ System.out.println("写后 " + ADDR_QUALITY_PASS + "=" + after + "(期望 " + value + ")");
|
|
|
+ return after == value;
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("写 " + ADDR_QUALITY_PASS + " 异常: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ return false;
|
|
|
+ } finally {
|
|
|
+ if (s7PLC != null) {
|
|
|
+ try {
|
|
|
+ s7PLC.close();
|
|
|
+ } catch (Exception ignore) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String resolveTjPlcIp() {
|
|
|
+ if (StringUtils.isNotBlank(TJ_PLC_IP)) {
|
|
|
+ return TJ_PLC_IP.trim();
|
|
|
+ }
|
|
|
+ String ip = Global.getConfig("mes.tj.plc.ip");
|
|
|
+ return StringUtils.isBlank(ip) ? DEFAULT_TJ_PLC_IP : ip.trim();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 与 ProductTjBScheduling.doQualityCheck 相同:5 位工位号补 A,6 位及以上原样传入。
|
|
|
*/
|
|
|
QualityCheckResult checkQualityLikeTjBScheduling(String sn, String lineSn, String oprno) {
|