Browse Source

1.自动复位信号功能修改 2.新增下发条码测试结果到plc的接口

master
NL000364 3 weeks ago
parent
commit
6c419768ae
  1. 109
      plcpluginsrc/atlPlcHandler/src/com/nlteck/plc/customer/base/BaseReadAndWriteUtilForUdpProtocol.java
  2. 24
      plcpluginsrc/atlPlcHandler/src/com/nlteck/plc/customer/base/PlcCoreDealService.java
  3. 7
      plcpluginsrc/atlPlcHandler/src/com/nlteck/plc/customer/handler/ATLCapacityMachinePlcHandlerImpl.java
  4. 17
      plcpluginsrc/atlPlcHandler/src/testMain.java
  5. 9
      plcpluginsrc/plcCore/src/com/nlteck/plc/core/handler/PlcBusinessHandler.java

109
plcpluginsrc/atlPlcHandler/src/com/nlteck/plc/customer/base/BaseReadAndWriteUtilForUdpProtocol.java

@ -2,18 +2,15 @@ package com.nlteck.plc.customer.base;
import com.nlteck.plc.common.util.CommonUtil; import com.nlteck.plc.common.util.CommonUtil;
import com.nlteck.plc.common.util.GsonUtil; import com.nlteck.plc.common.util.GsonUtil;
import com.nlteck.plc.customer.common.ATLPlcDefine; import com.nlteck.plc.common.util.LogUtil;
import com.nlteck.plc.finsUdp.BytesUtil; import com.nlteck.plc.finsUdp.BytesUtil;
import com.nlteck.plc.finsUdp.FinsUdpModel; import com.nlteck.plc.finsUdp.FinsUdpModel;
import com.nlteck.plc.finsUdp.FinsUdpProtocol; import com.nlteck.plc.finsUdp.FinsUdpProtocol;
import com.nlteck.plc.finsUdp.FinsUdpProtocol.DataArea; import com.nlteck.plc.finsUdp.FinsUdpProtocol.DataArea;
import com.nlteck.plc.finsUdp.UDPSocket; import com.nlteck.plc.finsUdp.UDPSocket;
import com.nltecklib.utils.BaseUtil;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.nlteck.plc.customer.common.CommonConstant.LOG_BASE_PATH; import static com.nlteck.plc.customer.common.CommonConstant.LOG_BASE_PATH;
@ -23,7 +20,7 @@ import static com.nlteck.plc.customer.common.CommonConstant.LOG_BASE_PATH;
*/ */
public class BaseReadAndWriteUtilForUdpProtocol { public class BaseReadAndWriteUtilForUdpProtocol {
private static Logger logger = Logger.getLogger(LOG_BASE_PATH + "BaseReadAndWriteUtil"); private static final Logger logger = LogUtil.getLogger(LOG_BASE_PATH + "BaseReadAndWriteUtil");
protected static boolean writeBoolValue(String address, boolean value, UDPSocket udpSocket) throws Exception { protected static boolean writeBoolValue(String address, boolean value, UDPSocket udpSocket) throws Exception {
if (udpSocket == null) { if (udpSocket == null) {
@ -31,10 +28,10 @@ public class BaseReadAndWriteUtilForUdpProtocol {
} }
// "W33.01" // "W33.01"
boolean rst = false; boolean rst;
String oriAdress = address; String oriAddress = address;
DataArea area = DataArea.DW; DataArea area = DataArea.DW;
int endIndex = oriAdress.indexOf("."); int endIndex = oriAddress.indexOf(".");
int offset = 0; int offset = 0;
if (address.startsWith("D")) { if (address.startsWith("D")) {
@ -42,97 +39,107 @@ public class BaseReadAndWriteUtilForUdpProtocol {
area = DataArea.WB; area = DataArea.WB;
} }
if (endIndex < 0) { if (endIndex < 0) {
address = oriAdress.substring(1); address = oriAddress.substring(1);
} else { } else {
address = oriAdress.substring(1, endIndex); address = oriAddress.substring(1, endIndex);
offset = Integer.parseInt(oriAdress.substring(endIndex)); offset = Integer.parseInt(oriAddress.substring(endIndex));
} }
FinsUdpProtocol finsUdpProtocol = new FinsUdpProtocol(0, 222); FinsUdpProtocol finsUdpProtocol = new FinsUdpProtocol(0, 222);
// W200.05 // W200.05
FinsUdpModel.writeBit(udpSocket, finsUdpProtocol, area, Integer.parseInt(address), offset, value); FinsUdpModel.writeBit(udpSocket, finsUdpProtocol, area, Integer.parseInt(address), offset, value);
logger.info("writeBoolValue - "+oriAdress + "写入值:" + value); logger.info("writeBoolValue - " + oriAddress + "写入值:" + value);
rst = true; rst = true;
return rst; return rst;
} }
protected static boolean writeByteValue(String address, int value, UDPSocket udpSocket) throws Exception { protected static void writeByteValue(String address, int value, UDPSocket udpSocket) {
if (udpSocket == null) { if (udpSocket == null) {
throw new RuntimeException("udpSocket对象不能为空,请检查!"); throw new RuntimeException("udpSocket对象不能为空,请检查!");
} }
String oriAddress = address;
// "W33.01"
boolean rst = false;
String oriAdress = address;
DataArea area = DataArea.DW; DataArea area = DataArea.DW;
int endIndex = oriAdress.indexOf("."); int endIndex = oriAddress.indexOf(".");
int offset = 0; if (address.startsWith("W")) {
if (address.startsWith("D")) {
} else if (address.startsWith("W")) {
area = DataArea.WB; area = DataArea.WB;
} }
if (endIndex < 0) { if (endIndex < 0) {
address = oriAdress.substring(1); address = oriAddress.substring(1);
} else { } else {
address = oriAdress.substring(1, endIndex); address = oriAddress.substring(1, endIndex);
offset = Integer.parseInt(oriAdress.substring(endIndex));
} }
FinsUdpProtocol finsUdpProtocol = new FinsUdpProtocol(0, 192); FinsUdpProtocol finsUdpProtocol = new FinsUdpProtocol(0, 192);
int[] data = new int[]{value}; int[] data = new int[]{value};
List<Byte> datas = finsUdpProtocol.writeEncode(FinsUdpModel.write(data, area, Integer.parseInt(address))); List<Byte> datum = finsUdpProtocol.writeEncode(FinsUdpModel.write(data, area, Integer.parseInt(address)));
byte[] result = null; byte[] result;
try { try {
result = udpSocket.sendMsg(BytesUtil.convertArray(datum));
result = udpSocket.sendMsg(BytesUtil.convertArray(datas));
int wCode = finsUdpProtocol.decodeWrite(result).getWriteResult(); int wCode = finsUdpProtocol.decodeWrite(result).getWriteResult();
logger.info("设定压力读取int[],结果:" + wCode); logger.info("写入读取int[],结果:" + wCode);
} catch (Exception e) { } catch (Exception e) {
logger.info(CommonUtil.getThrowableException(e)); logger.info(CommonUtil.getThrowableException(e));
} }
logger.info("writeByteValue."+oriAdress + "写入值:" + value); logger.info("writeByteValue." + oriAddress + "写入值:" + value);
rst = true;
return rst;
} }
// Function to read a single BIT value from the PLC
// Function to read a single BYTE value from the PLC
protected static byte readByteValue(String address, UDPSocket udpSocket) throws Exception { protected static byte readByteValue(String address, UDPSocket udpSocket) throws Exception {
if (udpSocket == null) { if (udpSocket == null) {
throw new RuntimeException("udpSocket对象不能为空,请检查!"); throw new RuntimeException("udpSocket对象不能为空,请检查!");
} }
String oriAddress = address;
boolean rst = false;
String oriAdress = address;
DataArea area = DataArea.DW; DataArea area = DataArea.DW;
int endIndex = oriAdress.indexOf("."); int endIndex = oriAddress.indexOf(".");
int offset = 0; if (address.startsWith("W")) {
if (address.startsWith("D")) {
} else if (address.startsWith("W")) {
area = DataArea.WB; area = DataArea.WB;
} }
if (endIndex < 0) { if (endIndex < 0) {
address = oriAdress.substring(1); address = oriAddress.substring(1);
} else { } else {
address = oriAdress.substring(1, endIndex); address = oriAddress.substring(1, endIndex);
offset = Integer.parseInt(oriAdress.substring(endIndex));
} }
FinsUdpProtocol finsUdpProtocol = new FinsUdpProtocol(0, 192); FinsUdpProtocol finsUdpProtocol = new FinsUdpProtocol(0, 192);
short info = (short) FinsUdpModel.read(udpSocket, finsUdpProtocol, area, Integer.parseInt(address)); short info = (short) FinsUdpModel.read(udpSocket, finsUdpProtocol, area, Integer.parseInt(address));
logger.info("readByteValue.info:"+ GsonUtil.toJson(info)); logger.info("readByteValue.info:" + GsonUtil.toJson(info));
return (byte) info; return (byte) info;
} }
// Function to read a list of BYTE values from the PLC protected static void writeBatchByteValue(String address, List<Integer> values, UDPSocket udpSocket) {
if (udpSocket == null) {
throw new RuntimeException("udpSocket对象不能为空,请检查!");
}
String oriAddress = address;
DataArea area = DataArea.DW;
int endIndex = oriAddress.indexOf(".");
if (address.startsWith("W")) {
area = DataArea.WB;
}
if (endIndex < 0) {
address = oriAddress.substring(1);
} else {
address = oriAddress.substring(1, endIndex);
}
FinsUdpProtocol finsUdpProtocol = new FinsUdpProtocol(0, 192);
int[] data = values.stream().mapToInt(Integer::intValue).toArray();
List<Byte> datum = finsUdpProtocol.writeEncode(FinsUdpModel.write(data, area, Integer.parseInt(address)));
byte[] result;
try {
result = udpSocket.sendMsg(BytesUtil.convertArray(datum));
int wCode = finsUdpProtocol.decodeWrite(result).getWriteResult();
logger.info("写入读取int[],结果:" + wCode);
} catch (Exception e) {
logger.info(CommonUtil.getThrowableException(e));
}
logger.info("writeByteValue." + oriAddress + "写入值:" + values);
}
} }

24
plcpluginsrc/atlPlcHandler/src/com/nlteck/plc/customer/base/PlcCoreDealService.java

@ -16,9 +16,11 @@ import org.apache.log4j.Logger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static com.nlteck.plc.customer.base.BaseReadAndWriteUtilForUdpProtocol.*; import static com.nlteck.plc.customer.base.BaseReadAndWriteUtilForUdpProtocol.*;
import static com.nlteck.plc.customer.common.CommonConstant.LOG_BASE_PATH; import static com.nlteck.plc.customer.common.CommonConstant.LOG_BASE_PATH;
@ -465,7 +467,10 @@ public class PlcCoreDealService {
//解析夹具状态信号 1:夹具压紧 0:夹具张开 //解析夹具状态信号 1:夹具压紧 0:夹具张开
fixture.open = vals.get(4) == 0; fixture.open = vals.get(4) == 0;
//流程完成信号 0:在测试中,未完成 1:化成完成; 2:夹具导出数据完成后; 3:导出数据完成后置为3
if (fixture.batExist1 && vals.get(5) == 0) {
this.dealResetComplete(fixtureIndex);
}
//解析夹具师傅有料 1:夹具有料 0:夹具无料 //解析夹具师傅有料 1:夹具有料 0:夹具无料
fixture.batExist1 = vals.get(5) == 1; fixture.batExist1 = vals.get(5) == 1;
@ -502,10 +507,7 @@ public class PlcCoreDealService {
} }
fixture.status = statusStr; fixture.status = statusStr;
//流程完成信号 0:在测试中,未完成 1:化成完成; 2:夹具导出数据完成后; 3:导出数据完成后置为3
if (fixture.batExist1 && vals.get(5) == 0) {
this.dealResetComplete(fixtureIndex);
}
fixture.complete = vals.get(13) == 1; fixture.complete = vals.get(13) == 1;
fixture.exportDateCompete = vals.get(13) == 3; fixture.exportDateCompete = vals.get(13) == 3;
@ -712,4 +714,16 @@ public class PlcCoreDealService {
writeByteValue(completeAddr, val, udpSocket); writeByteValue(completeAddr, val, udpSocket);
logger.info("复位夹具" + (fixtureIndex) + "完成信号"); logger.info("复位夹具" + (fixtureIndex) + "完成信号");
} }
public void writeBarcodeResult(int fixtureIndex, Map<Integer, Integer> map) {
Logger logger = LogUtil.getLogger(LOG_BASE_PATH + "writeBarcodeResults");
String barcodeResultAddr = "D" + (ATLPlcDefine.ADD_BARCODE_RESULT + fixtureIndex * ATLPlcDefine.FIXTURE_ADD_INTERVAL);
List<Integer> sortedValues = map.entrySet()
.stream()
.sorted(Map.Entry.comparingByKey()) // 按 key 排序
.map(Map.Entry::getValue) // 提取 value
.collect(Collectors.toList()); // 收集为 List
writeBatchByteValue(barcodeResultAddr, sortedValues, udpSocket);
logger.info("写入条码测试结果" + sortedValues);
}
} }

7
plcpluginsrc/atlPlcHandler/src/com/nlteck/plc/customer/handler/ATLCapacityMachinePlcHandlerImpl.java

@ -5,6 +5,8 @@ import com.nlteck.plc.core.enums.AlertType;
import com.nlteck.plc.core.handler.PlcBusinessHandler; import com.nlteck.plc.core.handler.PlcBusinessHandler;
import com.nlteck.plc.customer.base.PlcCoreDealService; import com.nlteck.plc.customer.base.PlcCoreDealService;
import java.util.Map;
public class ATLCapacityMachinePlcHandlerImpl implements PlcBusinessHandler { public class ATLCapacityMachinePlcHandlerImpl implements PlcBusinessHandler {
@ -187,4 +189,9 @@ public class ATLCapacityMachinePlcHandlerImpl implements PlcBusinessHandler {
coreDealService.dealStopSignalInteraction(fixtureIndex, val); coreDealService.dealStopSignalInteraction(fixtureIndex, val);
} }
@Override
public void issueBarcodeTestResult(int fixtureIndex, Map<Integer, Integer> map) {
coreDealService.writeBarcodeResult(fixtureIndex, map);
}
} }

17
plcpluginsrc/atlPlcHandler/src/testMain.java

@ -1,11 +1,26 @@
import com.nlteck.plc.customer.handler.ATLCapacityMachinePlcHandlerImpl; import com.nlteck.plc.customer.handler.ATLCapacityMachinePlcHandlerImpl;
import java.util.HashMap;
import java.util.Map;
public class testMain { public class testMain {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
ATLCapacityMachinePlcHandlerImpl plcHandler = new ATLCapacityMachinePlcHandlerImpl(); ATLCapacityMachinePlcHandlerImpl plcHandler = new ATLCapacityMachinePlcHandlerImpl();
plcHandler.startRun("127.0.0.1", "10.110.59.1"); plcHandler.startRun("127.0.0.1", "127.0.0.1");
Map<Integer, Integer> map = new HashMap<>();
map.put(3,3);
map.put(1,1);
map.put(4,4);
map.put(2,2);
map.put(5,5);
map.put(6,6);
map.put(10,10);
map.put(11,11);
map.put(7,7);
map.put(8,8);
plcHandler.issueBarcodeTestResult(0,map);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

9
plcpluginsrc/plcCore/src/com/nlteck/plc/core/handler/PlcBusinessHandler.java

@ -2,6 +2,8 @@ package com.nlteck.plc.core.handler;
import com.nlteck.plc.core.enums.AlertType; import com.nlteck.plc.core.enums.AlertType;
import java.util.Map;
/** /**
* plc业务处理接口定义一些规范接口底下需要有实现类实现接口 * plc业务处理接口定义一些规范接口底下需要有实现类实现接口
*/ */
@ -117,4 +119,11 @@ public interface PlcBusinessHandler {
* @throws Exception * @throws Exception
*/ */
void stopSignalInteraction(int fixtureIndex,int val) throws Exception; void stopSignalInteraction(int fixtureIndex,int val) throws Exception;
/**
* 下发所有通道电池测试结果到plc1.ok 2.ng
* @param fixtureIndex
* @param map
*/
void issueBarcodeTestResult(int fixtureIndex, Map<Integer, Integer> map);
} }

Loading…
Cancel
Save