private async void btn_toDest_Click(object sender, EventArgs e) { var selected_row = dgv_current_in_line_carrier.SelectedRows[0]; if (selected_row.Index < 0) { MessageBox.Show("No select remove carrier.", "Carrier To AGV", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string carrier_current_location = selected_row.Cells[DGV_CURRENT_IN_LINE_CARRIER_INFO_INDEX_LOCATION].Value as string; string carrier_id = selected_row.Cells[DGV_CURRENT_IN_LINE_CARRIER_INFO_INDEX_ID].Value as string; var check_is_in_vh = IsCstInVh(carrier_id, carrier_current_location); if (!check_is_in_vh.isIn) { MessageBox.Show(check_is_in_vh.result, "Carrier To AGV St.", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string dest_port_id = selected_row.Cells[DGV_CURRENT_IN_LINE_CARRIER_INFO_INDEX_DEST].Value as string; var port_station = scApp.PortStationBLL.OperateCatch.getPortStation(dest_port_id); sc.BLL.CMDBLL.CommandCheckResult check_result_info = null; await Task.Run(() => { scApp.VehicleService.Command.Unload(check_is_in_vh.vh.VEHICLE_ID, carrier_id, port_station.ADR_ID, port_station.PORT_ID); check_result_info = sc.BLL.CMDBLL.getCallContext <sc.BLL.CMDBLL.CommandCheckResult> (sc.BLL.CMDBLL.CALL_CONTEXT_KEY_WORD_OHTC_CMD_CHECK_RESULT); }); if (check_result_info != null && !check_result_info.IsSuccess) { MessageBox.Show(check_result_info.ToString(), "Command create fail.", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private async void btn_force_assign_Click(object sender, EventArgs e) { string selected_vh_id = cmb_force_assign.Text; try { if (selection_index == -1) { MessageBox.Show("Please select transfer command. ", "Command create fail.", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } btn_force_finish.Enabled = false; var mcs_cmd = cmdMCSshowList[selection_index]; AVEHICLE excute_cmd_of_vh = mainform.BCApp.SCApplication.VehicleBLL.cache.getVehicle(selected_vh_id); ATRANSFER transfer = mainform.BCApp.SCApplication.CMDBLL.GetTransferByID(mcs_cmd.CMD_ID); sc.BLL.CMDBLL.CommandCheckResult check_result_info = null; string force_assign_st_port = ""; bool is_selected_agv_station_port = cmb_st_port_ids.Visible; if (is_selected_agv_station_port) { force_assign_st_port = cmb_st_port_ids.Text; } await Task.Run(() => { try { mainform.BCApp.SCApplication.TransferService.AssignTransferToVehicle(transfer, excute_cmd_of_vh, force_assign_st_port); check_result_info = sc.BLL.CMDBLL.getCallContext <sc.BLL.CMDBLL.CommandCheckResult> (sc.BLL.CMDBLL.CALL_CONTEXT_KEY_WORD_OHTC_CMD_CHECK_RESULT); } catch { } } ); updateTransferCommand(); if (check_result_info != null && !check_result_info.IsSuccess) { MessageBox.Show(check_result_info.ToString(), "Command create fail. ", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show("Command create success.", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch { } finally { btn_force_finish.Enabled = true; } }
private (bool isSuccess, string result) excuteCommandNew(E_CMD_TYPE cmdType, string fromAddess, string toAddress, string cstID, string vhID) { try { Console.WriteLine(Thread.CurrentThread.ManagedThreadId.ToString()); var source_info = getAdrPortID(fromAddess); var dest_info = getAdrPortID(toAddress); string cst_id = cstID; string vehicleId = vhID; if (BCFUtility.isEmpty(vehicleId)) { return(false, "No find idle vehile."); } switch (cmdType) { case E_CMD_TYPE.Move: scApp.VehicleService.Command.Move(vehicleId, dest_info.adrID); break; //case E_CMD_TYPE.Move_Charger: scApp.VehicleService.Command.MoveToCharge(vehicleId, dest_info.adrID); break; case E_CMD_TYPE.Move_Charger: scApp.VehicleChargerModule.askVhToChargerForWaitByManual(vehicleId); break; case E_CMD_TYPE.LoadUnload: scApp.VehicleService.Command.Loadunload(vehicleId, cst_id, source_info.adrID, dest_info.adrID, source_info.portID, dest_info.portID); break; case E_CMD_TYPE.Load: scApp.VehicleService.Command.Load(vehicleId, cst_id, source_info.adrID, source_info.portID); break; case E_CMD_TYPE.Unload: scApp.VehicleService.Command.Unload(vehicleId, cst_id, dest_info.adrID, dest_info.portID); break; case E_CMD_TYPE.Home: string cmdID = scApp.SequenceBLL.getCommandID(SCAppConstants.GenOHxCCommandType.Manual); scApp.VehicleService.Send.CommandHome(vehicleId, cmdID); break; } sc.BLL.CMDBLL.CommandCheckResult check_result_info = sc.BLL.CMDBLL.getCallContext <sc.BLL.CMDBLL.CommandCheckResult> (sc.BLL.CMDBLL.CALL_CONTEXT_KEY_WORD_OHTC_CMD_CHECK_RESULT); if (check_result_info == null) { return(false, ""); } else { return(check_result_info.IsSuccess, check_result_info.ToString()); } } catch (Exception ex) { logger.Error(ex, "Exception"); return(false, "Exception happend"); } }
private Task excuteCommand(E_CMD_TYPE cmdType) { var source_info = getAdrPortID(cmb_fromAddress.Text); var dest_info = getAdrPortID(cmb_toAddress.Text); string cst_id = txt_cst_id.Text; string vehicleId = cmb_Vehicle.Text; if (BCFUtility.isEmpty(vehicleId)) { MessageBox.Show("No find idle vehile."); return(Task.CompletedTask); } switch (cmdType) { case E_CMD_TYPE.Move: scApp.VehicleService.Command.Move(vehicleId, dest_info.adrID); break; //case E_CMD_TYPE.Move_Charger: scApp.VehicleService.Command.MoveToCharge(vehicleId, dest_info.adrID); break; case E_CMD_TYPE.Move_Charger: scApp.VehicleChargerModule.askVhToChargerForWaitByManual(vehicleId); break; case E_CMD_TYPE.LoadUnload: scApp.VehicleService.Command.Loadunload(vehicleId, cst_id, source_info.adrID, dest_info.adrID, source_info.portID, dest_info.portID); break; case E_CMD_TYPE.Load: scApp.VehicleService.Command.Load(vehicleId, cst_id, source_info.adrID, source_info.portID); break; case E_CMD_TYPE.Unload: scApp.VehicleService.Command.Unload(vehicleId, cst_id, dest_info.adrID, dest_info.portID); break; case E_CMD_TYPE.Home: string cmdID = scApp.SequenceBLL.getCommandID(SCAppConstants.GenOHxCCommandType.Manual); scApp.VehicleService.Send.CommandHome(vehicleId, cmdID); break; } sc.BLL.CMDBLL.CommandCheckResult check_result_info = sc.BLL.CMDBLL.getCallContext <sc.BLL.CMDBLL.CommandCheckResult> (sc.BLL.CMDBLL.CALL_CONTEXT_KEY_WORD_OHTC_CMD_CHECK_RESULT); if (check_result_info != null && !check_result_info.IsSuccess) { MessageBox.Show(check_result_info.ToString(), "Command create fail.", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(Task.CompletedTask); }
private void RegisterVehilceEvent() { Get["AVEHICLES/{ID}"] = (p) => { string vh_id = p.ID; AVEHICLE vh = SCApplication.getInstance().VehicleBLL.cache.getVehicle(vh_id); var response = (Response)vh.ToString(); response.ContentType = restfulContentType; return(response); }; Get["AVEHICLES"] = (p) => { string vh_id = p.ID; List <AVEHICLE> vhs = SCApplication.getInstance().getEQObjCacheManager().getAllVehicle(); var response = (Response)JsonConvert.SerializeObject(vhs); response.ContentType = restfulContentType; return(response); }; //Get["AVEHICLES/(?<all>)"] = (p) => Get["AVEHICLES/_search"] = (p) => { List <AVEHICLE> vhs = null; foreach (string name in Request.Query) { switch (name) { case "SectionID": string sec_id = Request.Query[name] ?? string.Empty; vhs = SCApplication.getInstance().VehicleBLL.cache.loadVehicleBySEC_ID(sec_id); break; } } var response = (Response)JsonConvert.SerializeObject(vhs); response.ContentType = restfulContentType; return(response); }; Get["metrics"] = (p) => { int total_idle_vh_clean = SCApplication.getInstance().VehicleBLL.cache.getNoExcuteMcsCmdVhCount(E_VH_TYPE.Clean); int total_idle_vh_Dirty = SCApplication.getInstance().VehicleBLL.cache.getNoExcuteMcsCmdVhCount(E_VH_TYPE.Dirty); int total_cmd_is_queue_count = SCApplication.getInstance().CMDBLL.getCMD_MCSIsQueueCount(); int total_cmd_is_running_count = SCApplication.getInstance().CMDBLL.getCMD_MCSIsRunningCount(); string ohxc_excute_info = string.Empty; StringBuilder sb = new StringBuilder(); setOhxCContent(sb, nameof(total_idle_vh_clean), total_idle_vh_clean, "current idle clean car"); setOhxCContent(sb, nameof(total_idle_vh_Dirty), total_idle_vh_Dirty, "current idle dirty car"); setOhxCContent(sb, nameof(total_cmd_is_queue_count), total_cmd_is_queue_count, "cmd number being queued"); setOhxCContent(sb, nameof(total_cmd_is_running_count), total_cmd_is_running_count, "cmd number being executed"); var response = (Response)sb.ToString(); response.ContentType = restfulContentType; return(response); }; Post["AVEHICLES/ViewerUpdate"] = (p) => { SCApplication scApp = SCApplication.getInstance(); List <AVEHICLE> vhs = scApp.getEQObjCacheManager().getAllVehicle(); //foreach (AVEHICLE vh in vhs) //{ // scApp.VehicleService.PublishVhInfo(vh, null); // SpinWait.SpinUntil(() => false, 10); //} var response = (Response)"OK"; response.ContentType = restfulContentType; return(response); }; //Post["api/io/T2STK100T01/waitin/CST01"] = (p) => //{ // var response = (Response)"OK"; // response.ContentType = restfulContentType; // return response; //}; Post["AVEHICLES/SendCommand"] = (p) => { var scApp = SCApplication.getInstance(); bool isSuccess = true; string vh_id = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty; string carrier_id = Request.Query.carrier_id.Value ?? Request.Form.carrier_id.Value ?? string.Empty; string from_port_id = Request.Query.from_port_id.Value ?? Request.Form.from_port_id.Value ?? string.Empty; string to_port_id = Request.Query.to_port_id.Value ?? Request.Form.to_port_id.Value ?? string.Empty; E_CMD_TYPE e_cmd_type = default(E_CMD_TYPE); string cmd_type = Request.Query.cmd_type.Value ?? Request.Form.cmd_type.Value ?? string.Empty; string result = string.Empty; try { ACMD cmd_obj = null; AVEHICLE assignVH = null; assignVH = scApp.VehicleBLL.cache.getVehicle(vh_id); isSuccess = assignVH != null; if (isSuccess) { isSuccess = Enum.TryParse(cmd_type, out e_cmd_type); if (isSuccess) { switch (e_cmd_type) { case E_CMD_TYPE.Move: case E_CMD_TYPE.Load: case E_CMD_TYPE.Unload: case E_CMD_TYPE.LoadUnload: string from_adr = from_port_id; string to_adr = to_port_id; //scApp.MapBLL.getAddressID(from_port_id, out from_adr); //scApp.MapBLL.getAddressID(to_port_id, out to_adr); scApp.CMDBLL.doCreatCommand(vh_id, out cmd_obj, cmd_type: e_cmd_type, source: from_adr, destination: to_adr, carrier_id: carrier_id, gen_cmd_type: SCAppConstants.GenOHxCCommandType.Manual); sc.BLL.CMDBLL.CommandCheckResult check_result_info = sc.BLL.CMDBLL.getCallContext <sc.BLL.CMDBLL.CommandCheckResult> (sc.BLL.CMDBLL.CALL_CONTEXT_KEY_WORD_OHTC_CMD_CHECK_RESULT); isSuccess = check_result_info.IsSuccess; result = check_result_info.ToString(); if (isSuccess) { //isSuccess = scApp.VehicleService.doSendCommandToVh(assignVH, cmd_obj); isSuccess = scApp.VehicleService.Send.Command(assignVH, cmd_obj); if (isSuccess) { result = "OK"; } else { result = "Send command to vehicle failed!"; } } else { result = "Command create failed!"; //bcf.App.BCFApplication.onWarningMsg(this, new bcf.Common.LogEventArgs("Command create fail.", check_result_info.Num)); } break; case E_CMD_TYPE.Teaching: isSuccess = scApp.VehicleService.Send.Teaching(vh_id, from_port_id, to_port_id); break; } } else { result = $"Try parse Command Type:[{cmd_type}] failed!"; } } else { result = $"Vehicle :[{vh_id}] not found!"; } } catch (Exception ex) { isSuccess = false; result = "Execption happend!"; logger.Error(ex, "Execption:"); } var response = (Response)result; response.ContentType = restfulContentType; return(response); }; Post["AVEHICLES/SendReset"] = (p) => { var scApp = SCApplication.getInstance(); bool isSuccess = true; string vh_id = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty; string result = string.Empty; try { AVEHICLE assignVH = null; assignVH = scApp.VehicleBLL.cache.getVehicle(vh_id); isSuccess = assignVH != null; if (isSuccess) { isSuccess = scApp.VehicleService.Send.StatusRequest(vh_id, true); if (isSuccess) { result = "OK"; } else { result = "Send vehicle status request failed."; } } else { result = $"Vehicle :[{vh_id}] not found!"; } } catch (Exception ex) { isSuccess = false; result = "Execption happend!"; logger.Error(ex, "Execption:"); } var response = (Response)result; response.ContentType = restfulContentType; return(response); }; Post["AVEHICLES/SendCancelAbort"] = (p) => { var scApp = SCApplication.getInstance(); bool isSuccess = true; string vh_id = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty; string cmd_id = "";//todo kevin 需要指定cmd id string result = string.Empty; try { ACMD cmd = scApp.CMDBLL.GetCMD_OHTCByID(cmd_id); if (cmd == null) { result = $"Can't find command:[{cmd_id}] in database."; isSuccess = false; } AVEHICLE assignVH = null; if (isSuccess) { assignVH = scApp.VehicleBLL.cache.getVehicle(vh_id); isSuccess = assignVH != null; } if (isSuccess) { string mcs_cmd_id = cmd_id; if (!string.IsNullOrWhiteSpace(mcs_cmd_id)) { ATRANSFER mcs_cmd = scApp.CMDBLL.GetTransferByID(mcs_cmd_id); if (mcs_cmd == null) { result = $"Can't find MCS command:[{mcs_cmd_id}] in database."; } else { CancelActionType actType = default(CancelActionType); if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Transferring) { actType = CancelActionType.CmdCancel; isSuccess = scApp.TransferService.AbortOrCancel(mcs_cmd_id, actType); if (isSuccess) { result = "OK"; } else { result = "Send command cancel/abort failed."; } } else if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Canceling) { actType = CancelActionType.CmdAbort; isSuccess = scApp.TransferService.AbortOrCancel(mcs_cmd_id, actType); if (isSuccess) { result = "OK"; } else { result = "Send command cancel/abort failed."; } } else { result = $"MCS command:[{mcs_cmd_id}] can't excute cancel / abort,\r\ncurrent state:{mcs_cmd.TRANSFERSTATE}"; } } } else { string ohtc_cmd_id = cmd_id; if (string.IsNullOrWhiteSpace(ohtc_cmd_id)) { result = $"Vehicle:[{vh_id}] do not have command."; } else { ACMD ohtc_cmd = scApp.CMDBLL.GetCMD_OHTCByID(ohtc_cmd_id); if (ohtc_cmd == null) { result = $"Can't find vehicle command:[{ohtc_cmd_id}] in database."; } else { CancelActionType actType = ohtc_cmd.CMD_STATUS >= E_CMD_STATUS.Execution ? CancelActionType.CmdAbort : CancelActionType.CmdCancel; isSuccess = scApp.VehicleService.Send.Cancel(assignVH.VEHICLE_ID, ohtc_cmd_id, actType); if (isSuccess) { result = "OK"; } else { result = "Send vehicle status request failed."; } } } } } else { result = $"Vehicle :[{vh_id}] not found!"; } } catch (Exception ex) { isSuccess = false; result = "Execption happend!"; logger.Error(ex, "Execption:"); } var response = (Response)result; response.ContentType = restfulContentType; return(response); }; Post["AVEHICLES/PauseEvent"] = (p) => { bool isSuccess = false; SCApplication scApp = SCApplication.getInstance(); string vh_id = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty; string event_type = Request.Query.event_type.Value ?? Request.Form.event_type.Value ?? string.Empty; PauseEvent pauseEvent = default(PauseEvent); isSuccess = Enum.TryParse(event_type, out pauseEvent); if (isSuccess) { isSuccess = scApp.VehicleService.Send.Pause(vh_id, pauseEvent, PauseType.Normal); } var response = (Response)(isSuccess ? "OK" : "NG"); response.ContentType = restfulContentType; return(response); }; Post["AVEHICLES/PauseStatusChange"] = (p) => { bool isSuccess = false; string result = string.Empty; SCApplication scApp = SCApplication.getInstance(); string vh_id = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty; string pauseType = Request.Query.pauseType.Value ?? Request.Form.pauseType.Value ?? string.Empty; string event_type = Request.Query.event_type.Value ?? Request.Form.event_type.Value ?? string.Empty; PauseType pause_type = default(PauseType); PauseEvent pauseEvent = default(PauseEvent); isSuccess = Enum.TryParse(pauseType, out pause_type); if (isSuccess) { isSuccess = Enum.TryParse(event_type, out pauseEvent); if (isSuccess) { isSuccess = scApp.VehicleService.Send.Pause(vh_id, pauseEvent, pause_type); if (isSuccess) { result = "OK"; } else { result = $"Send pause request to vehicle:{vh_id} failed."; } } else { result = $"Can't recognize Pause Event:{event_type}."; } } else { result = $"Can't recognize Pause Type:{pauseType}."; } var response = (Response)result; response.ContentType = restfulContentType; return(response); }; Post["AVEHICLES/ModeStatusChange"] = (p) => { string result = string.Empty; bool isSuccess = false; SCApplication scApp = SCApplication.getInstance(); string vh_id = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty; string modeStatus = Request.Query.modeStatus.Value ?? Request.Form.modeStatus.Value ?? string.Empty; VHModeStatus mode_status = default(VHModeStatus); isSuccess = Enum.TryParse(modeStatus, out mode_status); try { if (isSuccess) { scApp.VehicleBLL.cache.updataVehicleMode(vh_id, mode_status); result = "OK"; } else { result = $"Can't recognize mode status:{modeStatus}."; } } catch (Exception ex) { result = $"Update vehicle:{vh_id} mode status failed."; logger.Error(ex, "Exception"); } var response = (Response)result; response.ContentType = restfulContentType; return(response); }; Post["AVEHICLES/ResetAlarm"] = (p) => { var scApp = SCApplication.getInstance(); string result = string.Empty; bool isSuccess = true; string vh_id = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty; try { isSuccess = scApp.VehicleService.Send.AlarmReset(vh_id); if (isSuccess) { result = "OK"; } else { result = "Reset alarm failed."; } } catch (Exception ex) { result = "Reset alarm failedwith exception happened."; } var response = (Response)result; response.ContentType = restfulContentType; return(response); }; Post["Engineer/ForceCmdFinish"] = (p) => { var scApp = SCApplication.getInstance(); string vh_id = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty; bool isSuccess = scApp.CMDBLL.forceUpdataCmdStatus2FnishByVhID(vh_id); if (isSuccess) { var vh = scApp.VehicleBLL.cache.getVehicle(vh_id); //vh.NotifyVhExcuteCMDStatusChange(); vh.onExcuteCommandStatusChange(); } var response = (Response)(isSuccess ? "OK" : "NG"); response.ContentType = restfulContentType; return(response); }; }