no message
parent
d47e09fdec
commit
0903643bf3
|
|
@ -15,10 +15,13 @@
|
||||||
*/
|
*/
|
||||||
package com.youchain.businessdata.rest;
|
package com.youchain.businessdata.rest;
|
||||||
|
|
||||||
|
import com.youchain.annotation.AnonymousAccess;
|
||||||
import com.youchain.annotation.Log;
|
import com.youchain.annotation.Log;
|
||||||
import com.youchain.businessdata.domain.Mo;
|
import com.youchain.businessdata.domain.Mo;
|
||||||
|
import com.youchain.businessdata.inputJson.IssueInfo;
|
||||||
import com.youchain.businessdata.service.MoService;
|
import com.youchain.businessdata.service.MoService;
|
||||||
import com.youchain.businessdata.service.dto.MoQueryCriteria;
|
import com.youchain.businessdata.service.dto.MoQueryCriteria;
|
||||||
|
import com.youchain.exception.handler.ApiResult;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
@ -27,12 +30,16 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||||
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @website https://eladmin.vip
|
|
||||||
* @author huojin
|
* @author huojin
|
||||||
|
* @website https://eladmin.vip
|
||||||
* @date 2024-04-10
|
* @date 2024-04-10
|
||||||
**/
|
**/
|
||||||
@RestController
|
@RestController
|
||||||
|
|
@ -84,4 +91,5 @@ public class MoController {
|
||||||
moService.deleteAll(ids);
|
moService.deleteAll(ids);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.youchain.businessdata.rest;
|
||||||
|
|
||||||
|
import com.github.s7connector.api.S7Connector;
|
||||||
|
import com.youchain.annotation.AnonymousAccess;
|
||||||
|
import com.youchain.annotation.Log;
|
||||||
|
import com.youchain.businessdata.service.MoService;
|
||||||
|
import com.youchain.exception.handler.ApiResult;
|
||||||
|
import com.youchain.utils.S7ConnectorUtils;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||||
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author huojin
|
||||||
|
* @website
|
||||||
|
* @date 2024-04-10
|
||||||
|
**/
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Api(tags = "plc管理")
|
||||||
|
@RequestMapping("/api/plc")
|
||||||
|
public class PlcController {
|
||||||
|
|
||||||
|
private final MoService moService;
|
||||||
|
|
||||||
|
@PostMapping("/scanMo")
|
||||||
|
@AnonymousAccess
|
||||||
|
@Log("PLC扫描容器")
|
||||||
|
@ApiOperation("PLC扫描容器")
|
||||||
|
public ResponseEntity<Object> scanMo(@RequestBody String mo) {
|
||||||
|
try {
|
||||||
|
moService.scanMo(mo);
|
||||||
|
S7Connector s7Connector = S7ConnectorUtils.connect();
|
||||||
|
S7ConnectorUtils.write(s7Connector,1);
|
||||||
|
return new ResponseEntity<>(ApiResult.success(OK.value(), "", ""), HttpStatus.OK);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new ResponseEntity<>(ApiResult.success(BAD_REQUEST.value(), e.getMessage(), ""), HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -89,4 +89,10 @@ public interface MoService {
|
||||||
* @return 转换后的对象
|
* @return 转换后的对象
|
||||||
*/
|
*/
|
||||||
Mo toEntity(MoDto moDto);
|
Mo toEntity(MoDto moDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扫描MO
|
||||||
|
* @param mo MO票
|
||||||
|
*/
|
||||||
|
void scanMo(String mo);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,13 @@ public interface OrderService {
|
||||||
*/
|
*/
|
||||||
OrderDto findById(Integer id);
|
OrderDto findById(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据deliveryLineId查询
|
||||||
|
* @param deliveryLineId deliveryLineId
|
||||||
|
* @return OrderDto
|
||||||
|
*/
|
||||||
|
OrderDto findBydeliveryLineId(Integer deliveryLineId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据barcodeNumber查询
|
* 根据barcodeNumber查询
|
||||||
* @param barcodeNumber
|
* @param barcodeNumber
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import com.youchain.businessdata.inputJson.*;
|
||||||
import com.youchain.businessdata.service.*;
|
import com.youchain.businessdata.service.*;
|
||||||
import com.youchain.businessdata.service.dto.MoDto;
|
import com.youchain.businessdata.service.dto.MoDto;
|
||||||
import com.youchain.businessdata.service.dto.OrderDto;
|
import com.youchain.businessdata.service.dto.OrderDto;
|
||||||
|
import com.youchain.exception.handler.ApiResult;
|
||||||
import com.youchain.modules.system.domain.Dept;
|
import com.youchain.modules.system.domain.Dept;
|
||||||
import com.youchain.modules.system.service.DeptService;
|
import com.youchain.modules.system.service.DeptService;
|
||||||
import com.youchain.modules.system.service.dto.DeptDto;
|
import com.youchain.modules.system.service.dto.DeptDto;
|
||||||
|
|
@ -37,10 +38,13 @@ public class MlsServiceImpl implements MlsService {
|
||||||
private final ItemService itemService;
|
private final ItemService itemService;
|
||||||
private final DeptService deptService;
|
private final DeptService deptService;
|
||||||
private final MoService moService;
|
private final MoService moService;
|
||||||
|
private final TaskService taskService;
|
||||||
private final PointService pointService;
|
private final PointService pointService;
|
||||||
|
private final AgvTaskService agvTaskService;
|
||||||
private final PickDetailService pickDetailService;
|
private final PickDetailService pickDetailService;
|
||||||
private final InventoryService inventoryService;
|
private final InventoryService inventoryService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取Token
|
* 获取Token
|
||||||
*
|
*
|
||||||
|
|
@ -292,9 +296,11 @@ public class MlsServiceImpl implements MlsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public synchronized void getIssueInfo(IssueInfo issueInfo) {
|
public synchronized void getIssueInfo(IssueInfo issueInfo) {
|
||||||
Set workOrderNameSet = issueInfo.getWorkOrderName();
|
// 指定Set的类型
|
||||||
if (workOrderNameSet.size() == 0) {
|
Set<String> workOrderNameSet = issueInfo.getWorkOrderName();
|
||||||
|
if (workOrderNameSet.isEmpty()) {
|
||||||
throw new RuntimeException("没有获取到工单号!");
|
throw new RuntimeException("没有获取到工单号!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -304,16 +310,17 @@ public class MlsServiceImpl implements MlsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
//目标点
|
//目标点
|
||||||
Point endPoint = pointService.findByCode("",null,null,null,null);
|
Point endPoint = pointService.findByCode(null, null, null, "出库接驳口", null);
|
||||||
for (Inventory inv : inventoryList) {
|
for (Inventory inv : inventoryList) {
|
||||||
//根据库存信息生成叫料任务
|
//根据库存信息生成叫料任务
|
||||||
Stock stock = inv.getStock();//容器
|
Stock stock = inv.getStock();//容器
|
||||||
Point startPoint = inv.getPoint();//起始点位
|
Point startPoint = inv.getPoint();//起始点位
|
||||||
|
Item item = inv.getItemKey().getItem();
|
||||||
|
|
||||||
inv.setQueuedQty(inv.getQueuedQty());
|
inv.setQueuedQty(inv.getQueuedQty());
|
||||||
inventoryService.update(inv);
|
inventoryService.update(inv);
|
||||||
PickDetail pd = new PickDetail();
|
PickDetail pd = new PickDetail();
|
||||||
pd.setItem(inv.getItemKey().getItem());
|
pd.setItem(item);
|
||||||
pd.setPo(inv.getBillCode());
|
pd.setPo(inv.getBillCode());
|
||||||
|
|
||||||
pd.setOrderQty(inv.getQuantity());
|
pd.setOrderQty(inv.getQuantity());
|
||||||
|
|
@ -321,9 +328,9 @@ public class MlsServiceImpl implements MlsService {
|
||||||
pd.setStatus(BizStatus.ALLOCATE);
|
pd.setStatus(BizStatus.ALLOCATE);
|
||||||
pickDetailService.create(pd);
|
pickDetailService.create(pd);
|
||||||
|
|
||||||
/*//生成搬运任务
|
//生成搬运任务
|
||||||
AgvTask agvTask = new AgvTask(BizStatus.PICK, stock.getCode(), startPoint.getCode(), endPoint.getCode(), BizStatus.OPEN, "01");
|
AgvTask agvTask = new AgvTask(BizStatus.PICK, stock.getCode(), startPoint.getCode(), endPoint.getCode(), BizStatus.OPEN, "01");
|
||||||
agvTaskRepository.save(agvTask);
|
agvTaskService.create(agvTask);
|
||||||
//生成Task
|
//生成Task
|
||||||
Task task = new Task();
|
Task task = new Task();
|
||||||
task.setItem(item);
|
task.setItem(item);
|
||||||
|
|
@ -339,11 +346,11 @@ public class MlsServiceImpl implements MlsService {
|
||||||
task.setDstPointCode(endPoint.getCode());
|
task.setDstPointCode(endPoint.getCode());
|
||||||
task.setInvStatus(inv.getStatus());
|
task.setInvStatus(inv.getStatus());
|
||||||
task.setTaskStatus(BizStatus.OPEN);
|
task.setTaskStatus(BizStatus.OPEN);
|
||||||
task.setPlanQty(allocateQty);
|
task.setPlanQty(inv.getQuantity());
|
||||||
task.setInvId(inv.getId());
|
task.setInvId(inv.getId());
|
||||||
task.setDept(dept);
|
task.setDept(item.getDept());
|
||||||
task.setAgvTask(agvTask);
|
task.setAgvTask(agvTask);
|
||||||
taskRepository.save(task);*/
|
taskService.create(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,33 +15,42 @@
|
||||||
*/
|
*/
|
||||||
package com.youchain.businessdata.service.impl;
|
package com.youchain.businessdata.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.youchain.basicdata.domain.Item;
|
import com.youchain.basicdata.domain.Item;
|
||||||
import com.youchain.businessdata.domain.Mo;
|
import com.youchain.basicdata.domain.Point;
|
||||||
|
import com.youchain.basicdata.domain.Stock;
|
||||||
|
import com.youchain.basicdata.service.ItemService;
|
||||||
|
import com.youchain.basicdata.service.PointService;
|
||||||
|
import com.youchain.basicdata.service.StockService;
|
||||||
|
import com.youchain.businessdata.domain.*;
|
||||||
|
import com.youchain.businessdata.service.*;
|
||||||
|
import com.youchain.businessdata.service.dto.OrderDto;
|
||||||
import com.youchain.exception.EntityExistException;
|
import com.youchain.exception.EntityExistException;
|
||||||
import com.youchain.utils.FileUtil;
|
import com.youchain.exception.handler.ApiResult;
|
||||||
import com.youchain.utils.PageUtil;
|
import com.youchain.modules.system.service.DictService;
|
||||||
import com.youchain.utils.QueryHelp;
|
import com.youchain.utils.*;
|
||||||
import com.youchain.utils.ValidationUtil;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import com.youchain.businessdata.repository.MoRepository;
|
import com.youchain.businessdata.repository.MoRepository;
|
||||||
import com.youchain.businessdata.service.MoService;
|
|
||||||
import com.youchain.businessdata.service.dto.MoDto;
|
import com.youchain.businessdata.service.dto.MoDto;
|
||||||
import com.youchain.businessdata.service.dto.MoQueryCriteria;
|
import com.youchain.businessdata.service.dto.MoQueryCriteria;
|
||||||
import com.youchain.businessdata.service.mapstruct.MoMapper;
|
import com.youchain.businessdata.service.mapstruct.MoMapper;
|
||||||
import org.springframework.data.domain.Example;
|
import org.springframework.data.domain.Example;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedHashMap;
|
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author huojin
|
* @author huojin
|
||||||
|
|
@ -56,6 +65,16 @@ public class MoServiceImpl implements MoService {
|
||||||
private final MoRepository moRepository;
|
private final MoRepository moRepository;
|
||||||
private final MoMapper moMapper;
|
private final MoMapper moMapper;
|
||||||
private final EntityManager entityManager;
|
private final EntityManager entityManager;
|
||||||
|
private final OrderService orderService;
|
||||||
|
private final ItemService itemService;
|
||||||
|
private final StockService stockService;
|
||||||
|
private final InventoryService inventoryService;
|
||||||
|
private final PointService pointService;
|
||||||
|
private final AgvTaskService agvTaskService;
|
||||||
|
private final TaskService taskService;
|
||||||
|
private final AsnDetailService asnDetailService;
|
||||||
|
private final ItemKeyService itemKeyService;
|
||||||
|
private final DictService dictService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> queryAll(MoQueryCriteria criteria, Pageable pageable) {
|
public Map<String, Object> queryAll(MoQueryCriteria criteria, Pageable pageable) {
|
||||||
|
|
@ -127,4 +146,79 @@ public class MoServiceImpl implements MoService {
|
||||||
public Mo toEntity(MoDto moDto) {
|
public Mo toEntity(MoDto moDto) {
|
||||||
return moMapper.toEntity(moDto);
|
return moMapper.toEntity(moDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void scanMo(String mo) {
|
||||||
|
String agv_on_off = "OFF";
|
||||||
|
String code = "0";
|
||||||
|
String message = "";
|
||||||
|
agv_on_off = dictService.getDictDescription("agv_on_off") == null ? "OFF" : dictService.getDictDescription("agv_on_off").getDescription();
|
||||||
|
|
||||||
|
MoDto moDto = this.findByLabelNo(mo);
|
||||||
|
if (moDto == null) {
|
||||||
|
throw new RuntimeException(mo + "系统无此标签!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!moDto.getLabelState().equals("PRINTED")) {
|
||||||
|
throw new RuntimeException(mo + "标签已被接收(已接收状态)!");
|
||||||
|
}
|
||||||
|
|
||||||
|
OrderDto orderDto = orderService.findBydeliveryLineId(moDto.getDeliveryHeaderId());
|
||||||
|
if (orderDto == null) {
|
||||||
|
throw new RuntimeException(moDto.getDeliveryHeaderId() + "系统无此订单!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!orderDto.getDeliveryStatus().equals("lm_initial")) {
|
||||||
|
throw new RuntimeException(orderDto.getBarcodeNumber() + "标签背后的送货单已取消(标签失效)!");
|
||||||
|
}
|
||||||
|
|
||||||
|
String itemCode = "";//物料编号
|
||||||
|
String stockCode = "";//容器编号
|
||||||
|
Item item = itemService.existItem(itemCode);
|
||||||
|
if (item == null) {
|
||||||
|
throw new RuntimeException(itemCode + "系统无此物料!");
|
||||||
|
}
|
||||||
|
|
||||||
|
Stock stock = stockService.findByCode(stockCode, null);
|
||||||
|
if (stock == null) {
|
||||||
|
throw new RuntimeException(stockCode + "系统无此容器!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inventoryService.queryInventory(stock).size() > 0) {
|
||||||
|
throw new RuntimeException(stockCode + "箱码已经有绑定关系!");
|
||||||
|
}
|
||||||
|
|
||||||
|
Point srcPoint = pointService.findByCode(null, null, null, "入库接驳口", null);
|
||||||
|
if (srcPoint == null) {
|
||||||
|
throw new RuntimeException("系统无入库接驳口!");
|
||||||
|
}
|
||||||
|
Point endPoint = pointService.findByCode(null, BaseStatus.FREE, BaseStatus.STORAGE, "存储区", null);
|
||||||
|
if (endPoint == null) {
|
||||||
|
throw new RuntimeException("存储区没有空闲点位!");
|
||||||
|
}
|
||||||
|
|
||||||
|
//生成AGV任务
|
||||||
|
AgvTask agvTask = new AgvTask(BizStatus.ASN, stock.getCode(), srcPoint.getCode(), endPoint.getCode(), BizStatus.OPEN, "RACK_MOVE_FULL");
|
||||||
|
agvTaskService.create(agvTask);
|
||||||
|
|
||||||
|
//生成入库任务
|
||||||
|
Date date = cn.hutool.core.date.DateUtil.date();
|
||||||
|
String propC1 = DateUtil.format(date, "yyyyMMdd");
|
||||||
|
AsnDetail asnDetail = asnDetailService.createAsnDetail(item, stock, srcPoint, propC1, null);
|
||||||
|
asnDetail.setOrderQty(item.getExtendD1());
|
||||||
|
asnDetail.setPo(orderDto.getBarcodeNumber());
|
||||||
|
asnDetailService.create(asnDetail);
|
||||||
|
//生成Itemkey
|
||||||
|
ItemKey itemKey = itemKeyService.getItemKey(item, asnDetail.getPropC1(), asnDetail.getOrderNumber());
|
||||||
|
|
||||||
|
//生成收货记录
|
||||||
|
Task task = new Task(item, itemKey, asnDetail.getOrderNumber(), BizStatus.ASN, asnDetail, null, null, null, stock, stock, srcPoint, endPoint, stock.getCode(), stock.getCode(), srcPoint.getCode(), endPoint.getCode(), null, BizStatus.OPEN, asnDetail.getOrderQty(), null, null, item.getDept(), agvTask);
|
||||||
|
taskService.create(task);
|
||||||
|
|
||||||
|
//容器改为占用,目标点位占用
|
||||||
|
stock.setStatus(BaseStatus.USED);
|
||||||
|
stockService.update(stock);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,14 @@ public class OrderServiceImpl implements OrderService {
|
||||||
return orderMapper.toDto(order);
|
return orderMapper.toDto(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public OrderDto findBydeliveryLineId(Integer deliveryLineId) {
|
||||||
|
Order order = orderRepository.findById(deliveryLineId).orElseGet(Order::new);
|
||||||
|
ValidationUtil.isNull(order.getDeliveryHeaderId(), "Order", "deliveryLineId", deliveryLineId);
|
||||||
|
return orderMapper.toDto(order);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OrderDto findByBarcodeNumber(String barcodeNumber) {
|
public OrderDto findByBarcodeNumber(String barcodeNumber) {
|
||||||
String hql = "from Order o where o.barcodeNumber = :barcodeNumber";
|
String hql = "from Order o where o.barcodeNumber = :barcodeNumber";
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.youchain.modules.quartz.task;
|
||||||
|
|
||||||
|
import com.github.s7connector.api.S7Connector;
|
||||||
|
import com.youchain.businessdata.rest.MoController;
|
||||||
|
import com.youchain.businessdata.rest.PlcController;
|
||||||
|
import com.youchain.utils.S7ConnectorUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class plcTask {
|
||||||
|
|
||||||
|
private final PlcController plcController;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public plcTask(PlcController plcController) {
|
||||||
|
this.plcController = plcController;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void plcTask() {
|
||||||
|
try {
|
||||||
|
S7Connector connector = S7ConnectorUtils.connect();
|
||||||
|
String mo = S7ConnectorUtils.readMo(connector);
|
||||||
|
plcController.scanMo(mo);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("异常信息" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -20,12 +20,12 @@ import java.nio.ByteBuffer;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class S7ConnectorUtils {
|
public class S7ConnectorUtils {
|
||||||
|
|
||||||
public S7Connector connect() {
|
public static S7Connector connect() {
|
||||||
S7Connector s7Connector = null;
|
S7Connector s7Connector = null;
|
||||||
try {
|
try {
|
||||||
s7Connector = S7ConnectorFactory
|
s7Connector = S7ConnectorFactory
|
||||||
.buildTCPConnector()
|
.buildTCPConnector()
|
||||||
.withHost("192.168.0.21")//设置PLC的IP地址
|
.withHost("192.168.56.188")//设置PLC的IP地址
|
||||||
.withPort(102)//设置PLC的端口号
|
.withPort(102)//设置PLC的端口号
|
||||||
.withTimeout(10000)//设置连接超时时间
|
.withTimeout(10000)//设置连接超时时间
|
||||||
.withRack(0)//设置PLC的机架号
|
.withRack(0)//设置PLC的机架号
|
||||||
|
|
@ -44,7 +44,8 @@ public class S7ConnectorUtils {
|
||||||
*
|
*
|
||||||
* @param connector 连接器
|
* @param connector 连接器
|
||||||
*/
|
*/
|
||||||
public void readMo(S7Connector connector) {
|
public static String readMo(S7Connector connector) {
|
||||||
|
String mo = null;
|
||||||
if (connector == null) {
|
if (connector == null) {
|
||||||
throw new RuntimeException("PLC连接失败,请检查!");
|
throw new RuntimeException("PLC连接失败,请检查!");
|
||||||
}
|
}
|
||||||
|
|
@ -64,13 +65,15 @@ public class S7ConnectorUtils {
|
||||||
String str1 = "";
|
String str1 = "";
|
||||||
StringConverter converter = new StringConverter();
|
StringConverter converter = new StringConverter();
|
||||||
|
|
||||||
String extract1 = converter.extract(str1.getClass(), PlcData, 0, 0);
|
mo = converter.extract(str1.getClass(), PlcData, 0, 0);
|
||||||
log.info("内置方法转换str=" + extract1);
|
log.info("内置方法转换str=" + mo);
|
||||||
try {
|
try {
|
||||||
connector.close();
|
connector.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return mo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -79,7 +82,7 @@ public class S7ConnectorUtils {
|
||||||
*
|
*
|
||||||
* @param connector 连接器
|
* @param connector 连接器
|
||||||
*/
|
*/
|
||||||
public Integer readStock(S7Connector connector) throws IOException {
|
public static Integer readStock(S7Connector connector) throws IOException {
|
||||||
Integer status = null;
|
Integer status = null;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
@ -117,7 +120,7 @@ public class S7ConnectorUtils {
|
||||||
* @param connector 连接器
|
* @param connector 连接器
|
||||||
* @param instruct 写入的数据;上位机给PLC发扫码合格指令,不合格写1,合格写2,0无效,上位机写,PLC清
|
* @param instruct 写入的数据;上位机给PLC发扫码合格指令,不合格写1,合格写2,0无效,上位机写,PLC清
|
||||||
*/
|
*/
|
||||||
public void write(S7Connector connector, Integer instruct) {
|
public static void write(S7Connector connector, Integer instruct) {
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES);
|
ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES);
|
||||||
buffer.putInt(instruct);
|
buffer.putInt(instruct);
|
||||||
|
|
@ -128,5 +131,4 @@ public class S7ConnectorUtils {
|
||||||
System.out.print("写入成功");
|
System.out.print("写入成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue