|
|
@ -24,13 +24,11 @@ import org.nl.acs.route.service.RouteLineService; |
|
|
|
import org.nl.acs.task.service.TaskService; |
|
|
|
import org.nl.acs.task.service.dto.TaskDto; |
|
|
|
import org.nl.utils.SpringContextHolder; |
|
|
|
import org.nl.wql.core.bean.WQLObject; |
|
|
|
import org.openscada.opc.lib.da.Server; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* 晟华RGV |
|
|
@ -52,6 +50,13 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi |
|
|
|
DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); |
|
|
|
@Autowired |
|
|
|
DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); |
|
|
|
@Autowired |
|
|
|
DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppServiceImpl.class); |
|
|
|
|
|
|
|
//当前指令1
|
|
|
|
Instruction inst1 = null; |
|
|
|
//当前指令2
|
|
|
|
Instruction inst2 = null; |
|
|
|
|
|
|
|
int mode = 0; |
|
|
|
int error = 0; |
|
|
@ -73,6 +78,9 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi |
|
|
|
//暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域
|
|
|
|
int flag; |
|
|
|
|
|
|
|
Boolean requireSucess1 = false; |
|
|
|
Boolean requireSucess2 = false; |
|
|
|
|
|
|
|
String device_code; |
|
|
|
int status = 0; |
|
|
|
int last_status = 0; |
|
|
@ -191,12 +199,58 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (!this.itemProtocol.getIsonline()) { |
|
|
|
this.setIsonline(false); |
|
|
|
this.setIserror(true); |
|
|
|
message = "信号量同步异常"; |
|
|
|
//未联机
|
|
|
|
} else if (mode == 0) { |
|
|
|
if (task1 > 0) { |
|
|
|
//inst_message
|
|
|
|
inst1 = instructionService.findByCodeFromCache(String.valueOf(task1)); |
|
|
|
if (inst1 != null) { |
|
|
|
if (StrUtil.equals(inst1.getInstruction_status(), "0")) { |
|
|
|
inst1.setInstruction_status("1"); |
|
|
|
instructionService.update(inst1); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (action_1 == 4 && move_1 == 0 && task1 > 0) { |
|
|
|
//inst_message
|
|
|
|
inst1 = instructionService.findByCodeFromCache(String.valueOf(task1)); |
|
|
|
if (inst1 != null) { |
|
|
|
if (StrUtil.equals(inst1.getInstruction_status(), "1")) { |
|
|
|
finish_instruction(inst1); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (task2 > 0) { |
|
|
|
//inst_message
|
|
|
|
inst2 = instructionService.findByCodeFromCache(String.valueOf(task2)); |
|
|
|
if (inst2 != null) { |
|
|
|
if (StrUtil.equals(inst2.getInstruction_status(), "0")) { |
|
|
|
inst2.setInstruction_status("1"); |
|
|
|
instructionService.update(inst2); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (action_2 == 4 && move_2 == 0 && task2 > 0) { |
|
|
|
//inst_message
|
|
|
|
inst2 = instructionService.findByCodeFromCache(String.valueOf(task2)); |
|
|
|
if (inst2 != null) { |
|
|
|
if (StrUtil.equals(inst2.getInstruction_status(), "1")) { |
|
|
|
finish_instruction(inst2); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//给后工位下发空盘放货信号
|
|
|
|
if (mode == 3 && action_1 == 2 && action_2 == 2 && move_1 == 1 && move_2 == 1 && task1 > 0 && task2 > 0) { |
|
|
|
writing("to_command2", "2"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//给前工位下发放货信号
|
|
|
|
if (mode == 3 && action_2 == 4 && move_1 == 1 && move_2 == 0 && task1 > 0) { |
|
|
|
writing("to_command1", "2"); |
|
|
|
} |
|
|
|
|
|
|
|
if (mode == 0) { |
|
|
|
this.setIsonline(false); |
|
|
|
this.setIserror(true); |
|
|
|
message = "未联机"; |
|
|
@ -217,25 +271,29 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi |
|
|
|
log.debug("设备运转模式:等待工作"); |
|
|
|
return; |
|
|
|
case 2: |
|
|
|
//申请任务
|
|
|
|
if (walk_y == 1 && move_1 == 0 && !requireSucess ) { |
|
|
|
instruction_apply(); |
|
|
|
//后工位申请任务
|
|
|
|
if (mode == 2 && move_2 == 0 && action_2 == 0 && !requireSucess2) { |
|
|
|
instruction_require2(); |
|
|
|
} |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
//前工位申请任务
|
|
|
|
if (mode == 3 && move_2 == 1 && action_2 == 1 && move_1 == 0 && !requireSucess1) { |
|
|
|
instruction_require(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
switch (flag) { |
|
|
|
//取货完成
|
|
|
|
case 1: |
|
|
|
writing(2); |
|
|
|
writing1(2); |
|
|
|
return; |
|
|
|
//放货完成
|
|
|
|
case 2: |
|
|
|
writing(3); |
|
|
|
writing1(3); |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
last_mode = mode; |
|
|
|
last_error = error; |
|
|
@ -263,29 +321,42 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 请求指令 |
|
|
|
*/ |
|
|
|
public synchronized boolean instruction_apply() throws Exception { |
|
|
|
|
|
|
|
public void writing1(int command) { |
|
|
|
String to_command1 = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|
|
|
+ "." + ItemProtocol.item_to_command1; |
|
|
|
|
|
|
|
String opcservcerid = this.getDevice().getOpc_server_id(); |
|
|
|
Server server = ReadUtil.getServer(opcservcerid); |
|
|
|
Map<String, Object> itemMap = new HashMap<String, Object>(); |
|
|
|
itemMap.put(to_command1, command); |
|
|
|
ReadUtil.write(itemMap, server); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public synchronized boolean finish_instruction(Instruction inst) throws Exception { |
|
|
|
instructionService.finish(inst); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
//申请前工位任务
|
|
|
|
public synchronized boolean instruction_require() throws Exception { |
|
|
|
Date date = new Date(); |
|
|
|
if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { |
|
|
|
if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { |
|
|
|
log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); |
|
|
|
return false; |
|
|
|
} else { |
|
|
|
this.instruction_require_time = date; |
|
|
|
|
|
|
|
Object[] value = (Object[]) this.device.getExtraValue().get("get_device_code"); |
|
|
|
Object[] value2 = (Object[]) this.device.getExtraValue().get("load_device_code"); |
|
|
|
Object[] value3 = (Object[]) this.device.getExtraValue().get("put_device_code"); |
|
|
|
|
|
|
|
for (int i = 0; i < value.length; i++) { |
|
|
|
String get_device_code = value[i].toString(); |
|
|
|
//Device device = appService.findDeviceByCode(get_device_code);
|
|
|
|
TaskDto task = taskserver.findByStartCode(get_device_code); |
|
|
|
this.instruction_apply_time = date; |
|
|
|
String linkobj = (String)this.getDevice().getExtraValue().get("get_device_code1"); |
|
|
|
String demosub = linkobj.substring(1,linkobj.length()-1); |
|
|
|
String demoArray[] = demosub.split(","); |
|
|
|
List<String> device_code_list = Arrays.asList(demoArray); |
|
|
|
TaskDto task = null; |
|
|
|
for(int i=0;i<device_code_list.size();i++){ |
|
|
|
task = taskserver.queryTaskByDeviceCode(device_code_list.get(i).replace("\"","")).get(0); |
|
|
|
if(ObjectUtil.isNotEmpty(task)) break; |
|
|
|
} |
|
|
|
if (!ObjectUtil.isEmpty(task)) { |
|
|
|
for (int j = 0; j < value2.length; j++) { |
|
|
|
String putdevice_code = value2[j].toString(); |
|
|
|
if (StrUtil.equals(task.getNext_device_code(), putdevice_code)) { |
|
|
|
String taskid = task.getTask_id(); |
|
|
|
String taskcode = task.getTask_code(); |
|
|
|
String vehiclecode = task.getVehicle_code(); |
|
|
@ -293,6 +364,10 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi |
|
|
|
String start_point_code = task.getStart_point_code(); |
|
|
|
String start_device_code = task.getStart_device_code(); |
|
|
|
String route_plan_code = task.getRoute_plan_code(); |
|
|
|
String next_point_code = task.getNext_point_code(); |
|
|
|
String next_device_code = task.getNext_device_code(); |
|
|
|
Device startdevice = deviceAppservice.findDeviceByCode(start_device_code); |
|
|
|
Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code); |
|
|
|
|
|
|
|
Instruction instdto = new Instruction(); |
|
|
|
instdto.setInstruction_id(IdUtil.simpleUUID()); |
|
|
@ -307,36 +382,62 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi |
|
|
|
instdto.setCreate_time(now); |
|
|
|
instdto.setCreate_by("auto"); |
|
|
|
instdto.setStart_device_code(start_device_code); |
|
|
|
instdto.setNext_device_code(putdevice_code); |
|
|
|
instdto.setNext_device_code(next_device_code); |
|
|
|
instdto.setStart_point_code(start_point_code); |
|
|
|
instdto.setNext_point_code(putdevice_code); |
|
|
|
instdto.setNext_point_code(next_point_code); |
|
|
|
instdto.setPriority(priority); |
|
|
|
instdto.setInstruction_status("0"); |
|
|
|
instdto.setExecute_device_code(start_point_code); |
|
|
|
|
|
|
|
try { |
|
|
|
instructionService.create(instdto); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
//创建指令后修改任务状态
|
|
|
|
WQLObject taskwo = WQLObject.getWQLObject("acs_task"); |
|
|
|
task.setTask_status("1"); |
|
|
|
//创建指令后修改任务状态
|
|
|
|
task.setTask_status("1"); |
|
|
|
taskserver.update(task); |
|
|
|
requireSucess = true; |
|
|
|
writing(instdto); |
|
|
|
break; |
|
|
|
requireSucess1 = true; |
|
|
|
|
|
|
|
|
|
|
|
String start_addr = startdevice.getAddress(); |
|
|
|
String next_addr = nextdevice.getAddress(); |
|
|
|
|
|
|
|
writing("to_command1","1"); |
|
|
|
writing("to_onset1",start_addr); |
|
|
|
writing("to_target1",next_addr); |
|
|
|
writing("to_task1",instdto.getInstruction_code()); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (requireSucess) { |
|
|
|
break; |
|
|
|
} |
|
|
|
//申请后工位任务
|
|
|
|
public synchronized boolean instruction_require2() throws Exception { |
|
|
|
Date date = new Date(); |
|
|
|
if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { |
|
|
|
log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); |
|
|
|
return false; |
|
|
|
} else { |
|
|
|
this.instruction_apply_time = date; |
|
|
|
String linkobj = (String)this.getDevice().getExtraValue().get("get_device_code2"); |
|
|
|
String demosub = linkobj.substring(1,linkobj.length()-1); |
|
|
|
String demoArray[] = demosub.split(","); |
|
|
|
List<String> device_code_list = Arrays.asList(demoArray); |
|
|
|
TaskDto task = null; |
|
|
|
for(int i=0;i<device_code_list.size();i++){ |
|
|
|
task = taskserver.queryTaskByDeviceCode(device_code_list.get(i).replace("\"","")).get(0); |
|
|
|
if(ObjectUtil.isNotEmpty(task)) break; |
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < value2.length; i++) { |
|
|
|
String load_device_code = value2[i].toString(); |
|
|
|
//Device device = appService.findDeviceByCode(get_device_code);
|
|
|
|
TaskDto task = taskserver.findByStartCode(load_device_code); |
|
|
|
if (!ObjectUtil.isEmpty(task)) { |
|
|
|
for (int j = 0; j < value3.length; j++) { |
|
|
|
String putdevice_code = value3[j].toString(); |
|
|
|
if (StrUtil.equals(task.getNext_device_code(), putdevice_code)) { |
|
|
|
String taskid = task.getTask_id(); |
|
|
|
String taskcode = task.getTask_code(); |
|
|
|
String vehiclecode = task.getVehicle_code(); |
|
|
@ -344,6 +445,10 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi |
|
|
|
String start_point_code = task.getStart_point_code(); |
|
|
|
String start_device_code = task.getStart_device_code(); |
|
|
|
String route_plan_code = task.getRoute_plan_code(); |
|
|
|
String next_point_code = task.getNext_point_code(); |
|
|
|
String next_device_code = task.getNext_device_code(); |
|
|
|
Device startdevice = deviceAppservice.findDeviceByCode(start_device_code); |
|
|
|
Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code); |
|
|
|
|
|
|
|
Instruction instdto = new Instruction(); |
|
|
|
instdto.setInstruction_id(IdUtil.simpleUUID()); |
|
|
@ -358,31 +463,45 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi |
|
|
|
instdto.setCreate_time(now); |
|
|
|
instdto.setCreate_by("auto"); |
|
|
|
instdto.setStart_device_code(start_device_code); |
|
|
|
instdto.setNext_device_code(putdevice_code); |
|
|
|
instdto.setNext_device_code(next_device_code); |
|
|
|
instdto.setStart_point_code(start_point_code); |
|
|
|
instdto.setNext_point_code(putdevice_code); |
|
|
|
instdto.setNext_point_code(next_point_code); |
|
|
|
instdto.setPriority(priority); |
|
|
|
instdto.setInstruction_status("0"); |
|
|
|
instdto.setExecute_device_code(start_point_code); |
|
|
|
|
|
|
|
try { |
|
|
|
instructionService.create(instdto); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
//创建指令后修改任务状态
|
|
|
|
WQLObject taskwo = WQLObject.getWQLObject("acs_task"); |
|
|
|
task.setTask_status("1"); |
|
|
|
//创建指令后修改任务状态
|
|
|
|
task.setTask_status("1"); |
|
|
|
taskserver.update(task); |
|
|
|
requireSucess = true; |
|
|
|
writing(instdto); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
requireSucess2 = true; |
|
|
|
|
|
|
|
|
|
|
|
String start_addr = startdevice.getAddress(); |
|
|
|
String next_addr = nextdevice.getAddress(); |
|
|
|
|
|
|
|
writing("to_command2","1"); |
|
|
|
writing("to_onset2",start_addr); |
|
|
|
writing("to_target2",next_addr); |
|
|
|
writing("to_task2",instdto.getInstruction_code()); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (requireSucess) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean exe_business() { |
|
|
|
return true; |
|
|
|
} |
|
|
@ -433,10 +552,16 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi |
|
|
|
log.info("设备:{},下发作业命令:{},起始站{},目标站:{},任务号:{}", device_code, to_command,to_onset ,to_target, to_task); |
|
|
|
} |
|
|
|
|
|
|
|
public void writing(int type, int command) { |
|
|
|
|
|
|
|
public void writing(String param, String value) { |
|
|
|
|
|
|
|
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|
|
|
+ "." + param; |
|
|
|
String opcservcerid = this.getDevice().getOpc_server_id(); |
|
|
|
Server server = ReadUtil.getServer(opcservcerid); |
|
|
|
Map<String, Object> itemMap = new HashMap<String, Object>(); |
|
|
|
itemMap.put(to_param, value); |
|
|
|
|
|
|
|
ReadUtil.write(itemMap, server); |
|
|
|
} |
|
|
|
} |
|
|
|