using System.Runtime.InteropServices; using System.Collections.Generic; using System.Text; using System.Data; using System; using CommLayerFactory; using ICommLayer; using DBFactory; using CommonLib; using System.Diagnostics; using System.Collections; using System.Net.NetworkInformation; using System.Security.Cryptography; using System.Net.Sockets; using System.Linq; namespace WcfControlMonitorLib { /// /// Creator:Richard.liu /// 监控调度类 /// public class CControl { int StackMutexXCoor = 4800; int minStackMutexXCoor = 2400; int StackZeroXCoor = 1950; StringBuilder AheadDetectUnallow = new StringBuilder();//20110505 StringBuilder sql = new StringBuilder(); char[] dd = new char[1] { '.' };//20101124 string[] DS;//20101124 private Object thisLock = new Object(); DBOperator dbo = CStaticClass.dbo; DBOperator dboM = CStaticClass.dboM; //CGetState cgs = new CGetState(); Model.MDevice devinfo; ISendDeviceOrder sdo; CCommonFunction ccf = new CCommonFunction(); int _DeviceIdx = 0;//设备索引 int _routeID = 0;//路径唯一索引 int _serialNumber = 0;//路径上的设备方向性链表的序号 int _ManageTaskIdx = 0;//调度任务索引 int _ManageKindIdx = 0;//调度任务类型 int _DeviceOrder = 0;//设备命令 int _LockedState = 0; int _Associate = 0; int _ManTaskReserve = 0; string _AheadDetect = ""; int _NumParam1 = 0; int _NumParam2 = 0; int _NumParam3 = 0; int _NumParam4 = 0; int _NumParam5 = 0; int _NumParam6 = 0; string _TxtParam = "-"; int _DeviceKind = 0; int _OutsideAltDevice = 0; int _InsideAltDevice = 0; int _StartDevice = 0; int _EndDevice = 0; int _RouteKind = 0; //CGetState cgs = new CGetState(); //int _UseAwayFork = 1; int _AgvNo = 65535; string _CControlError = "";//监控调度类错误说明 public string CControlError { get { return _CControlError; } set { _CControlError = value; RefreshMonitorEventArgs rme = new RefreshMonitorEventArgs("tsStatus", _CControlError); OnRefreshMonitor(rme); } } /// /// 贴标机 /// public static Socket socketSendPrint201; public static event CDataSourceChangeEventHandler DataChange; public static void OnDataChange(object sender, CDataChangeEventArgs e) { if (DataChange != null) { DataChange(sender, e); } } public static event RefreshMonitorEventHandler RefreshMonitor; public static void OnRefreshMonitor(RefreshMonitorEventArgs e) { if (RefreshMonitor != null) { RefreshMonitor(e); } } public CControl() { //dbo.Open(); } //~CControl() //{ // dbo.Close(); //} public void StartOrder() { //首先检测第一个调度任务单的“第一个”(所有剩下中的第一个)设备是否被占用,被占用则执行下一个调度任务单; //然后检测第一个设备的F_AheadDetect都是否满足条件,不满足,则执行下一个调度任务单; //最后开始执行时检查同步运行的关联设备F_AssociateDeviceIndex,准备给该设备发指令; //更改作业记录的状态F_Status为1,更改设备为占用状态(T_Base_device的F_LockedState=设备指令单) //给调度任务表回写调度任务IO_Control的正在执行状态FSTATUS=1;T_Manage_Task的正在执行状态FSTATUS=1 //路径明细表F_LockedDeviceIndex里的所有对应设备索引加锁,但是关联设备不加锁 StringBuilder taskkind = new StringBuilder(); DataView dv = new DataView(); DataView dvM = new DataView(); DataView dvD = new DataView(); string tray = string.Empty;//AGV 任务托盘号 try { #region 查询AGV任务状态 sql.Clear(); //sql.Append("select * from AGV_TASK where AGV_TASK_STATUS in(5)"); sql.Append("select * from AGV_TASK where AGV_TASK_STATUS in(1,2,3,4,5,6)"); var result = dbo.Query(sql.ToString()).Tables[0]; if (result.Rows.Count > 0) { foreach (DataRow item in result.Rows) { int status = Convert.ToInt32(item["AGV_TASK_STATUS"].ToString()); sql.Clear(); sql.AppendFormat("select * from T_Monitor_Task where F_DeviceCommandIndex = 4 and F_ManageTaskIndex = {0}", item["fid"]); var data = dbo.Query(sql.ToString()).Tables[0]; if (status == 5) { if (data.Rows.Count > 0) { CGetState cgs = new CGetState(); cgs.ActionComplete(Convert.ToInt32(data.Rows[0]["F_DeviceIndex"]), Convert.ToInt32(data.Rows[0]["F_MonitorIndex"]), 1); } } else if (status == 1) { if (data.Rows.Count > 0) { sql.Remove(0, sql.Length); sql.Append("update IO_CONTROL set CONTROL_STATUS=10 where CONTROL_ID =").Append(item["fid"]); dboM.ExecuteSql(sql.ToString()); } } if (status == 3) { if (data.Rows.Count > 0) { //AGV 取完货后,清楚取货设备预约锁 sql.Remove(0, sql.Length); sql.Append($"SELECT * FROM T_Base_Device WHERE F_DeviceIndex = {data.Rows[0]["F_NumParam2"]} AND F_LockedState = {data.Rows[0]["F_MonitorIndex"]}"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { sql.Remove(0, sql.Length); sql.Append($"update T_Base_Device set F_LockedState = 0 where F_DeviceIndex = {data.Rows[0]["F_NumParam2"]} AND F_LockedState = {data.Rows[0]["F_MonitorIndex"]}"); dbo.ExecuteSql(sql.ToString()); } } } //AGV 站台取货地址为29008 取货完成,清除 29008 站台记录托盘号信息 if (status == 3 && Convert.ToInt32(item["START_DEVICE_CODE"]) == 29009) { dvD = dbo.ExceSQL($"SELECT FPALLETBARCODE FROM T_Manage_Task where FID = {item["FID"]}").Tables[0].DefaultView; if (dvD.Count > 0) { tray = dvD[0]["FPALLETBARCODE"].ToString(); dvD = dbo.ExceSQL("SELECT F_PALLETBARCODE FROM T_Base_Device where F_DeviceIndex = 29008").Tables[0].DefaultView; if (dvD.Count > 0) { //根据 取货完成信息,移除 29008 托盘信息 string[] trayList = dvD[0]["F_PALLETBARCODE"].ToString().Split(',').Distinct().Where(c => !string.IsNullOrEmpty(c)).ToArray(); if (trayList.Contains(tray)) { string[] newTray = trayList.Except(tray.Split(',')).Distinct().Where(c => !string.IsNullOrEmpty(c)).ToArray(); sql.Append($"update T_Base_Device set F_PALLETBARCODE = '{string.Join(",", newTray)}' where F_DeviceIndex = 29008 "); dbo.ExceSQL(sql.ToString()); } } } } } } #endregion if (CStaticClass.Order == true) { taskkind.Append(" (F_ManageTaskKindIndex = 1 or F_ManageTaskKindIndex = 2 or F_ManageTaskKindIndex = 4) "); //调度任务与调度生成的自动任务 } else { return; } dvM = new DataView(); char[] sep = new char[1] { '-' }; //获得管理单据 sql.Remove(0, sql.Length); //20120820 sql.Append("SELECT DISTINCT F_ManageTaskIndex AS MIndex,F_MonitorTaskLevel,F_ManageTaskKindIndex,F_SplitTime FROM T_Monitor_Task where ").Append( taskkind.ToString()).Append(" order by F_ManageTaskKindIndex desc, F_MonitorTaskLevel desc,F_SplitTime asc, F_ManageTaskIndex asc");//20120616 dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { for (int i = 0; i < dv.Count; i++) { try { //1:提取每个管理单据的第一个设备指令 sql.Remove(0, sql.Length); sql.Append("select top 1 min(F_MonitorIndex) as minMidx,f_status from T_Monitor_Task where ").Append(taskkind.ToString()).Append(" and F_ManageTaskIndex = ").Append(dv[i]["MIndex"]).Append(" GROUP BY F_MonitorIndex, F_Status"); dvM = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dvM.Count > 0) {//20110412 if (dvM[0]["F_Status"].ToString() == "0" && dvM[0]["minMidx"] != DBNull.Value) { SendMonitorTask(Convert.ToInt32(dvM[0]["minMidx"])); } else { continue; } } else { continue; } } catch (Exception ex) { CControlError = string.Format("发送命令调用StartOrder时:{0}", ex.StackTrace + ex.Message); } }//for语句结束 //20091107 return; } else { return; } } catch (Exception ex) { throw ex; } finally { dv.Dispose(); dvM.Dispose(); } } /// /// 提取每个管理单据的第一个设备是否被锁定,true表示被锁定;false表示空闲 /// /// 调度任务号 /// true表示被锁定;false表示空闲 public bool GetFirstDeviceIFLocked(int minMidx, bool checkLockedstate) { char[] sep = new char[1] { '-' }; int msgIdx = 0;//消息编号 int adidx = 0;//关联设备的设备指令索引 DataView dv = new DataView(); try { //获得要发送的信息 if (GetSendInfo(minMidx) == false) {//20120420 return true; } int DeviceIdx = _DeviceIdx;//设备索引 int routeID = _routeID;//路径唯一索引 int serialNumber = _serialNumber;//路径上的设备方向性链表的序号 int ManageTaskIdx = _ManageTaskIdx;//调度任务索引 int ManageKindIdx = _ManageKindIdx;//调度任务类型 int DeviceOrder = _DeviceOrder;//设备命令 int LockedState = _LockedState; int Associate = _Associate; int ManTaskReserve = _ManTaskReserve; string AheadDetect = _AheadDetect; int NumParam1 = _NumParam1; int NumParam2 = _NumParam2; int NumParam3 = _NumParam3; int NumParam4 = _NumParam4; int NumParam5 = _NumParam5; int NumParam6 = _NumParam6; string TxtParam = _TxtParam; int DeviceKind = _DeviceKind; int OutsideAltDevice = _OutsideAltDevice; int InsideAltDevice = _InsideAltDevice; int StartDevice = _StartDevice; int EndDevice = _EndDevice; int RouteKind = _RouteKind; int AgvNo = _AgvNo; #region 设备故障时是否自动改道 if (CStaticClass.DeviceErrorAutoModifyRoutePath == "1") {//20100108 #region 只针对与RGV有关的五个动作判断改路径 //20100108 输送机的接货对接指令不参与改道 if ((_DeviceKind == 4) || ((_DeviceKind == 2) && ((_DeviceOrder == 3))) && (RouteKind != 3)) { bool IfModify = false, IfUseNegativeDevice = false;//20100610 //20091102 RGV的第一个被提前触发的运动指令不需要更改路径 if ((_DeviceKind == 4) && (_DeviceOrder == 7) && (ccf.GetSerialNumberFromRouteDevice(_routeID, _DeviceIdx) > ccf.GetSerialNumberFromRouteDevice(_routeID, _NumParam1))) { sql.Remove(0, sql.Length); sql.Append("SELECT MIN(F_MonitorIndex) AS mmi FROM dbo.T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(ManageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1)"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { //20091218 if ((dv[0]["mmi"] != DBNull.Value) && (dv[0]["mmi"].ToString() == minMidx.ToString())) { IfModify = true; IfUseNegativeDevice = true;//20100610 } } } else if ((_DeviceKind == 4) && ((_DeviceOrder == 3) || (_DeviceOrder == 5))) {//20100108对穿梭车送货对接应该加于限制,载货,空闲 devinfo = Model.CGetInfo.DeviceInfo[DeviceIdx]; if ((devinfo.RunState == 0) && (devinfo.HaveGoods == true)) { IfModify = true; IfUseNegativeDevice = false;//20100610 } devinfo = null; } else { IfModify = true; IfUseNegativeDevice = true;//20100610 } if (IfModify == true) { int altsn = ccf.GetSerialNumberFromRouteDevice(_routeID, _OutsideAltDevice); sql.Remove(0, sql.Length); sql.Append("SELECT F_SerialNumber FROM T_Base_Device,T_Base_Route_Device,T_Base_Device_State where ").Append( " T_Base_Device.F_DeviceIndex = T_Base_Route_Device.F_DeviceIndex and F_ErrorCode =F_DeviceErrorIndex and ").Append( " T_Base_Device_State.F_DeviceKindIndex = T_Base_Device.F_DeviceKindIndex AND T_Base_Device.F_ErrorCode > 0 AND ").Append( " T_Base_Route_Device.F_SerialNumber > ").Append(_serialNumber).Append(" AND T_Base_Route_Device.F_SerialNumber > ").Append( altsn).Append(" AND T_Base_Route_Device.F_RouteIDSub = ").Append(_routeID).Append(" and F_ErrorLevel=2 "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { //判断能否改道;向管理申请改道;把ManageTaskIdx,ManageKindIdx 的调度任务全部申请改道 if (GetUsableDestination(_ManageTaskIdx, _ManageKindIdx) == true) { return true; } } #region RGV目标位置被占用需要申请改道 //20100610 devinfo = null; if (_DeviceKind == 4) {//RGV devinfo = Model.CGetInfo.GetDeviceInfo(CDisassembleTask.GetNextDevice(_routeID, _serialNumber)[0]); } else {//输送机送货 devinfo = Model.CGetInfo.GetDeviceInfo(CDisassembleTask.GetNextDevice(_routeID, _serialNumber)[0]);//RGV int sn = 0; if (devinfo != null) { sn = ccf.GetSerialNumberFromRouteDevice(_routeID, devinfo.DeviceIndex); } devinfo = Model.CGetInfo.GetDeviceInfo(CDisassembleTask.GetNextDevice(_routeID, sn)[0]);//接货输送机 } if (devinfo != null) { if (devinfo.HaveGoods == true) {//目标位置被占用,申请改道 if (GetRGVIdleDestination(_ManageTaskIdx, _ManageKindIdx, devinfo.DeviceIndex, IfUseNegativeDevice) == true) { return true; } } } #endregion } } #endregion } #endregion if (DeviceKind == 6) {//20100512 AGV #region AGV if (AgvNo != 65535)//如果是已经分配车号的AGV命令,检查这个车号对应的设备索引是否被锁定 { LockedState = Convert.ToInt32(dbo.GetSingle("SELECT F_LockedState FROM T_Base_Device where F_DeviceIndex=" + (DeviceIdx + AgvNo) + "")); if (LockedState > 0) return true; } if (AheadDetectOK(minMidx, _AheadDetect) == true)//提前检测通过 { #region 双叉AGV检测,能同步的关联任务是否AheadDetectOK cz20240226改 取消双叉检测 //20100323 //devinfo = Model.CGetInfo.GetDeviceInfo(_DeviceIdx); //if (devinfo.IfCorrelDoubleFork == "1") //{ // int[] synctask = Model.CGeneralFunction.MutiForkIfSync(minMidx, _DeviceIdx, _DeviceKind); // if (synctask != null)//20120616 // { // if ((synctask.GetLength(0) == 1) && (synctask[0] == minMidx)) return true;//20120616等待未拆分的可同步执行的任务 // string[] df = null; // Dictionary mforkmonitorinfo = Model.CGeneralFunction.GetDoubleForkMonitorInfo(minMidx, _DeviceIdx); // foreach (int i in mforkmonitorinfo.Keys) // { // df = mforkmonitorinfo[i]; // if (df != null) // { // if (AheadDetectOK(Convert.ToInt32(df[0]), df[1]) == false)//多叉关联提前检测失败 // { // return true; // } // #region 关联指令不是第一个指令不能发送 // int rmankind = Model.CGeneralFunction.GetManageTaskKindIndexFromMonitor(Convert.ToInt32(df[0])); // int rman = Model.CGeneralFunction.GetManageTaskIndexfromMonitor(Convert.ToInt32(df[0])); // sql.Remove(0, sql.Length); // sql.Append("SELECT MIN(F_MonitorIndex) AS mmi FROM dbo.T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(rman).Append(") AND (F_ManageTASKKINDINDEX = ").Append(rmankind).Append(")"); // dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; // if (dv.Count > 0) // { // if ((dv[0]["mmi"] != DBNull.Value) && (dv[0]["mmi"].ToString() != df[0])) // { // return true; // } // } // #endregion // } // } // } //} #endregion return false; } else { return true; } #endregion } else {//非AGV设备:输送机、堆垛机、RGV等 #region 非AGV设备:输送机、堆垛机、RGV等 //第一个设备是否被占用,RGV和堆垛机要考虑分步控制时,没执行完连续动作时不接受新的调度任务 if (((_LockedState == 0) && (checkLockedstate == true)) || (checkLockedstate == false)) { #region 检查RGV、堆垛机等是否被调度任务预约F_ManTaskReserve if (_ManTaskReserve > 0 && DeviceKind != 2)//20140309 { devinfo = Model.CGetInfo.GetDeviceInfo(_DeviceIdx); if (devinfo.IfCorrelDoubleFork == "1") { #region 多叉关联 Dictionary mforkmonInfo = Model.CGeneralFunction.GetDoubleForkMonitorInfo(minMidx, _DeviceIdx); bool iftrue = true; int relfid = ccf.GetRELATIVECONTORLIDFromManageTask(_ManageKindIdx, _ManageTaskIdx); if (_ManTaskReserve.ToString() == _ManageKindIdx.ToString() + _ManageTaskIdx.ToString()) { iftrue = false; } else { if (relfid > 0) {//20130704 dv = dbo.ExceSQL(string.Format("SELECT FID FROM T_Manage_Task where F_RELATIVECONTORLID={0} and F_ManageTaskKindIndex={1}", relfid, _ManageKindIdx)).Tables[0].DefaultView; for (int mt = 0; mt < dv.Count; mt++) { if (_ManTaskReserve.ToString() == _ManageKindIdx.ToString() + dv[mt]["FID"].ToString()) { iftrue = false; } } } } if (iftrue == true) { UpdateAheadDetectUnallow(new StringBuilder(_DeviceIdx.ToString() + "被任务预约" + _ManTaskReserve.ToString().Substring(1)), minMidx); return true; } #endregion } else { if (_ManTaskReserve.ToString() != _ManageKindIdx.ToString() + _ManageTaskIdx.ToString()) { UpdateAheadDetectUnallow(new StringBuilder(_DeviceIdx.ToString() + "被任务预约" + _ManTaskReserve.ToString().Substring(1)), minMidx); return true; } } } #endregion //3:F_AheadDetect检测(检测开关编号组“;”) if (AheadDetectOK(minMidx, _AheadDetect) == true)//提前检测通过 { devinfo = Model.CGetInfo.GetDeviceInfo(_DeviceIdx); if (_DeviceIdx == devinfo.VirtualStack) {//20111020 AssignStackNo(_DeviceIdx, minMidx, ManageKindIdx, ManageTaskIdx); return true;//20120906 } #region 多叉堆垛机检测,能同步的DoubleFork是否AheadDetectOK //20100323 devinfo = Model.CGetInfo.GetDeviceInfo(_DeviceIdx); if (devinfo.IfCorrelDoubleFork == "1" && devinfo.DeviceKind == 1) { int[] synctask = Model.CGeneralFunction.MutiForkIfSync(minMidx, _DeviceIdx, _DeviceKind); if (synctask != null)//20120616 { if ((synctask.GetLength(0) == 1) && (synctask[0] == minMidx)) return true;//20120616等待未拆分的可同步执行的任务 string[] df = null; Dictionary mforkmonitorinfo = Model.CGeneralFunction.GetDoubleForkMonitorInfo(minMidx, _DeviceIdx); foreach (int i in mforkmonitorinfo.Keys) { if (Array.IndexOf(synctask, i) >= 0) {//20120906 df = mforkmonitorinfo[i]; if (df != null) { if (AheadDetectOK(Convert.ToInt32(df[0]), df[1]) == false)//多叉关联提前检测失败 { return true; } #region 关联指令不是第一个指令不能发送 int rmankind = Model.CGeneralFunction.GetManageTaskKindIndexFromMonitor(Convert.ToInt32(df[0])); int rman = Model.CGeneralFunction.GetManageTaskIndexfromMonitor(Convert.ToInt32(df[0])); sql.Remove(0, sql.Length); sql.Append("SELECT MIN(F_MonitorIndex) AS mmi FROM dbo.T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(rman).Append(") AND (F_ManageTASKKINDINDEX = ").Append(rmankind).Append(")"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { if ((dv[0]["mmi"] != DBNull.Value) && (dv[0]["mmi"].ToString() != df[0])) { return true; } } #endregion } } } } } #endregion //检查同步运行的关联设备F_AssociateDeviceIndex //4:是否有关联设备命令? #region 是否有关联设备命令 //AssociateDevice = ccf.GetAssociateDevice(minMidx); if (_Associate != 0) { //5:如果有,找到可以运行的关联设备的设备指令,能否运行? //重复递归到2 //split = AssociateDevice.Split(sep); adidx = _Associate; if (adidx != 0) { #region 有关联任务 if (ccf.GetAssociateMonitor(minMidx) == 0) { RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", "设备指令:" + minMidx.ToString() + "无法获得关联任务" + adidx.ToString() + ",不能发送此类命令!"); OnRefreshMonitor(rmea); return true; } if (GetFirstDeviceIFLocked(adidx, false) == false) { //6:发送关联设备命令 //CStaticClass.MessageIndex++; CStaticClass.MessageIndex = 1; msgIdx = (CStaticClass.MessageIndex); sdo = CommModeCreate.CreateSendDeviceOrder(_DeviceIdx); //判断是否为堆垛机设备 bool sendok; int[] gc = new int[6] { _NumParam2, _NumParam3, _NumParam1, _NumParam5, _NumParam6, _NumParam4 }; //ccf.GetCoordinatesFromMonitorTask(adidx);//获得坐标 if ((_DeviceKind == 1) || (_DeviceKind == 6)) { //1:堆垛机;4:RGV;6:AGV如果需要优化调度(设备表的F_NeedOptimize='1') //直接写入表:T_Monitor_Task_Child,不发送命令 if (ccf.NeedOptimize(_DeviceIdx) == true) { ccf.InsertMonitorOptimizeChildTask(adidx); sendok = true; } else { sendok = sdo.SendDeviceOrder(msgIdx, adidx, _DeviceOrder, _DeviceIdx, gc[0], gc[1], gc[2], gc[3], gc[4], gc[5]); } } else if (_DeviceKind == 4) { if (ccf.NeedOptimize(_DeviceIdx) == true) { ccf.InsertMonitorOptimizeChildTask(adidx); sendok = true; } else { sendok = sdo.SendDeviceOrder(msgIdx, adidx, _DeviceOrder, _DeviceIdx, gc[2]); } } else { sendok = sdo.SendDeviceOrder(msgIdx, adidx, _DeviceOrder, _DeviceIdx, gc[5]); } if (sendok == false) { return true; } else { //8:更改作业记录的状态F_Status为1,更改设备为占用状态(T_Base_device的F_LockedState=设备指令单) sql.Remove(0, sql.Length); sql.Append("update T_Monitor_Task set F_StartTime='").Append(DateTime.Now.ToString("u")).Append("',F_Status='1' where F_MonitorIndex=").Append(adidx); dbo.ExceSQL(sql.ToString()); //返回到原来设备值 _DeviceIdx = DeviceIdx;//设备索引 _routeID = routeID;//路径唯一索引 _serialNumber = serialNumber;//路径上的设备方向性链表的序号 _ManageTaskIdx = ManageTaskIdx;//调度任务索引 _ManageKindIdx = ManageKindIdx;//调度任务类型 _DeviceOrder = DeviceOrder;//设备命令 _LockedState = LockedState; _Associate = Associate; _ManTaskReserve = ManTaskReserve; _AheadDetect = AheadDetect; _NumParam1 = NumParam1; _NumParam2 = NumParam2; _NumParam3 = NumParam3; _NumParam4 = NumParam4; _NumParam5 = NumParam5; _NumParam6 = NumParam6; _TxtParam = TxtParam; _DeviceKind = DeviceKind; _OutsideAltDevice = OutsideAltDevice; _InsideAltDevice = InsideAltDevice; _StartDevice = StartDevice; _EndDevice = EndDevice; _RouteKind = RouteKind; _AgvNo = AgvNo; return false; } } else { return true; } #endregion } else// { #region MyRegion //返回到原来设备值 _DeviceIdx = DeviceIdx;//设备索引 _routeID = routeID;//路径唯一索引 _serialNumber = serialNumber;//路径上的设备方向性链表的序号 _ManageTaskIdx = ManageTaskIdx;//调度任务索引 _ManageKindIdx = ManageKindIdx;//调度任务类型 _DeviceOrder = DeviceOrder;//设备命令 _LockedState = LockedState; _Associate = Associate; _ManTaskReserve = ManTaskReserve; _AheadDetect = AheadDetect; _NumParam1 = NumParam1; _NumParam2 = NumParam2; _NumParam3 = NumParam3; _NumParam4 = NumParam4; _NumParam5 = NumParam5; _NumParam6 = NumParam6; _TxtParam = TxtParam; _DeviceKind = DeviceKind; _OutsideAltDevice = OutsideAltDevice; _InsideAltDevice = InsideAltDevice; _StartDevice = StartDevice; _EndDevice = EndDevice; _RouteKind = RouteKind; #endregion CControlError = string.Format("拆分调度任务得到的设备指令与详细路径的检索到的关联设备指令不匹配,系统作为没有关联设备指令处理!"); return false; } } else { #region 返回到原来设备值 //返回到原来设备值 _DeviceIdx = DeviceIdx;//设备索引 _routeID = routeID;//路径唯一索引 _serialNumber = serialNumber;//路径上的设备方向性链表的序号 _ManageTaskIdx = ManageTaskIdx;//调度任务索引 _ManageKindIdx = ManageKindIdx;//调度任务类型 _DeviceOrder = DeviceOrder;//设备命令 _LockedState = LockedState; _Associate = Associate; _ManTaskReserve = ManTaskReserve; _AheadDetect = AheadDetect; _NumParam1 = NumParam1; _NumParam2 = NumParam2; _NumParam3 = NumParam3; _NumParam4 = NumParam4; _NumParam5 = NumParam5; _NumParam6 = NumParam6; _TxtParam = TxtParam; _DeviceKind = DeviceKind; _OutsideAltDevice = OutsideAltDevice; _InsideAltDevice = InsideAltDevice; _StartDevice = StartDevice; _EndDevice = EndDevice; _RouteKind = RouteKind; #endregion return false; } #endregion } else { return true; } } else { return true; } #endregion } } catch (Exception ex) { CControlError = string.Format("发送命令调用GetFirstDeviceIFLocked时:{0}", ex.StackTrace + ex.Message); return true; } finally { dv.Dispose(); } } /// /// 检测指定设备命令的执行先决条件是否成立 /// /// 监控唯一索引 /// 是否检测通过,true表示设备执行命令的先决条件成立 public bool AheadDetectOK(int minMidx, string _AheadDetect) { //TODO 条件检测 AheadDetectUnallow.Remove(0, AheadDetectUnallow.Length);//20110505 int[] States; string dtime = DateTime.Now.ToString("u"); dtime = dtime.Substring(0, dtime.Length - 1); int DeviceIdx = _DeviceIdx; int TaskIdx = minMidx; int fid = ccf.GetManageTaskIndexfromMonitor(TaskIdx); int mti = ccf.GetManageTaskKindIndexFromMonitor(TaskIdx); int DeviceKind = ccf.GetDeviceKindIdx(DeviceIdx);//20100617 int order = ccf.GetDeviceOrderFromMonitor(TaskIdx); string barcode = ccf.GetBarCodeFromMonitor(minMidx); int StartDevice = _StartDevice;//当前调度任务起点 int EndDevice = _EndDevice;//当前调度任务终点 int EXECUTIONCOUNT = 0;//任务执行数 #region 补充顶升机不在高位的顶升命令 //if ((DeviceIdx >= 35000) && (DeviceIdx <= 35003)&&(order ==4)) //{//20120110补充顶升机不在高位的顶升命令 // if (_AheadDetect.IndexOf("D-32036.6") >= 0) // { // if(CStaticClass.GetDevicePhotoelectric(32036,7)==1) // { // InsertUpDeviceUP(32036, mti, fid,minMidx); // } // } // else if (_AheadDetect.IndexOf("D-32049.6") >= 0) // { // if (CStaticClass.GetDevicePhotoelectric(32049, 7) == 1) // { // InsertUpDeviceUP(32049, mti, fid, minMidx); // } // } //} #endregion //20100706 devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIdx); if (ccf.GetBarCodeFromMonitor(minMidx) == "brbrbr")//避让指令检测条件20120110 { int zc = 1, xc = 0; GetStackRunX_Zcoor(DeviceIdx, out xc, out zc); if (devinfo.RunState == 0 && xc == 0) { return true; } else { return false; } } //检测(检测开关编号组“;”) DataView dv = new DataView(); DataView dvdv = new DataView(); try { if (devinfo.CommType == "OPCClient")//20100706 只有OPCClient通讯类型的检查设备状态 { #region OPC通讯设备检测设备是否故障 // //gds = CommModeCreate.CreateGetDeviceState(DeviceIdx); // try // { // //States = gds.GetDeviceState(DeviceIdx, TaskIdx);//1完成,2任务号,5设备号 // if (DeviceKind == 13) // { // DeviceIdx = GetNowDevice(minMidx); // } // States = CStaticClass.GetDeviceState(DeviceIdx); // } // catch (Exception ex) // {//20110505 // RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", "提前检测时:" + ex.Message); // OnRefreshMonitor(rmea); // return false; // } // if (States == null)//没接收到任何返回值 // { // RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", "发送命令时,提前检测没收到PLC数据!"); // OnRefreshMonitor(rmea); // return false; // } // if (((States[1] == 1) || (States[1] >= 30)) && ((DeviceKind != 13) && (DeviceKind != 31)))//运行或者故障 // { // if (States[1] >= 30) // { // devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIdx); // int ErrId = States[1]; // //20110505 // errs = Model.CGetInfo.GetErrorInfo(Convert.ToInt32(_DeviceKind.ToString() + States[1].ToString())); // AheadDetectUnallow.Append(DeviceIdx + "有故障:" + errs.ErrorName); // //20090910 // //有过记录的故障设备的任务号,不再重复处理 // sql.Remove(0, sql.Length); // sql.Append("SELECT F_DeviceIndex FROM T_Base_Device where F_DeviceIndex=" ).Append( DeviceIdx ).Append( " and F_ErrorTaskNo=" ).Append( TaskIdx ); // ; // dt = dbo.ExceSQL(sql.ToString()).Tables[0]; // if (dt.Rows.Count >= 1) // { // //20110505 // UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); // return false; // } // //记录发生故障的设备正在执行的任务号 // sql.Remove(0, sql.Length); // sql.Append("update T_Base_Device set F_ErrorTaskNo= " ).Append( TaskIdx ).Append( " where F_DeviceIndex= " ).Append( DeviceIdx); // dbo.ExceSQL(sql.ToString()); // if (CStaticClass.IsEquals(devinfo.ReturnMessage, States, 2) == true) return false; // //if ((_DeviceKind == 2) || (_DeviceKind == 4)) // //{//输送机故障清零 // // sdo = CommModeCreate.CreateSendDeviceOrder(DeviceIdx); // // sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0); // //} // //if (_DeviceKind == 1) //堆垛机、RGV // //{ // // sdo = CommModeCreate.CreateSendDeviceOrder(DeviceIdx); // // sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0, 0, 0, 0, 0, 0); // //} // //20110505 // RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", "设备索引" + DeviceIdx + "有故障:" + errs.ErrorName); // OnRefreshMonitor(rmea); // rmea = new RefreshMonitorEventArgs("notifyIcon1", "警告:" + devinfo.DeviceName + "," + DeviceIdx + "发生故障:" + errs.ErrorName); // OnRefreshMonitor(rmea); // if (mti == 1) // { // sql.Remove(0, sql.Length); // sql.Append("update IO_Control set ERROR_TEXT='" ).Append( "准备执行管理任务时:" ).Append( devinfo.DeviceName ).Append( "," ).Append( DeviceIdx ).Append( errs.ErrorName ).Append( "' where Control_ID=" ).Append( fid); // dboM.ExceSQL(sql.ToString()); // } // sql.Remove(0, sql.Length); // sql.Append("update T_Manage_Task set FERRORCODE='" ).Append( "准备执行管理任务时:" ).Append( devinfo.DeviceName ).Append( "," ).Append( DeviceIdx ).Append( errs.ErrorName ).Append( "' where F_ManageTaskKindIndex=" ).Append( mti ).Append( " and FID=" ).Append( fid); // dbo.ExceSQL(sql.ToString()); // CDataChangeEventArgs cea = new CDataChangeEventArgs(null, null); // OnDataChange("发送指令提前检测时,",cea); // } // return false; // } // #endregion //} //else //{ // #region 延吉:20100319 AGV的指令67:允许AGV放残托时,如果有1219的送出指令、1220的指令正在执行或者已发送,提前检测失败,需要等待 // // // //if (ccf.GetDeviceOrderFromMonitor(minMidx) == 67) // //{ // // dv = dbo.ExceSQL("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_DeviceIndex = 1219) AND (F_DeviceCommandIndex = 6) AND (F_Status > 0)").Tables[0].DefaultView; // // if (dv.Count > 0) // // { // // return false; // // } // // dv = dbo.ExceSQL("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_DeviceIndex = 1220) AND (F_Status > 0)").Tables[0].DefaultView; // // if (dv.Count > 0) // // { // // return false; // // } // //} #endregion } #region 高端设备U线正在运行总数控制 //if ((DeviceKind == 13) && (order==6)) //{//20120328 // int arrdevice = ccf.GetDeviceArrowFromMonitor(minMidx); // int startdevice = ccf.GetDeviceStartFromMonitor(minMidx); // object ob0 = dbo.GetSingle(string.Format("SELECT count(F_MonitorIndex) as UTaskCount FROM T_Monitor_Task where F_DeviceIndex={0} and F_DeviceCommandIndex={1} and F_Status>0", DeviceIdx, order)); // DataView dvu = dbo.ExceSQL(string.Format("SELECT F_MaxRunTask,F_OutputUDevice,F_InputUDevice FROM T_Base_UArea WHERE (F_UCODE = {0})", DeviceIdx)).Tables[0].DefaultView; // if ((dvu.Count>0) && (ob0 != null)) // { // if (arrdevice == Convert.ToInt32(dvu[0]["F_OutputUDevice"])) // { // //if (Convert.ToInt32(ob0) >= Convert.ToInt32(dvu[0]["F_MaxRunTask"])) // //{ // // AheadDetectUnallow.Append("U线:" + DeviceIdx.ToString() + "正在运行任务已经超限!"); // // UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); // // return false; // //} // } // else // { // if ((Convert.ToInt32(ob0) >= (Convert.ToInt32(dvu[0]["F_MaxRunTask"]) - 2)) && (startdevice == Convert.ToInt32(dvu[0]["F_InputUDevice"]))) // { // AheadDetectUnallow.Append("U线:" + DeviceIdx.ToString() + "正在运行任务已经超限!"); // UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); // return false; // } // if ((Convert.ToInt32(ob0) >= (Convert.ToInt32(dvu[0]["F_MaxRunTask"]) - 1)) && (startdevice != Convert.ToInt32(dvu[0]["F_InputUDevice"]))) // { // //AheadDetectUnallow.Append("U线:" + DeviceIdx.ToString() + "正在运行任务已经超限!"); // //UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); // //return false; // } // } // } //} #endregion if (new int[] { 19002, 19003 }.Contains(StartDevice) && EndDevice == 12008) { _AheadDetect = _AheadDetect + ";D12006.0;D12008.0;"; } if (mti != 4 && DeviceKind == 1 && order == 4 && EndDevice == 39003) { _AheadDetect = _AheadDetect + ";D32001.0;I32001;D32002.0;I32002;D32003.0;I32003;"; } #region 提前检测信息处理 if ((_AheadDetect != "") && (_AheadDetect != null)) { char[] cc = new char[1]; cc[0] = ';'; string[] AheadDetect = _AheadDetect.Split(cc); string[] sp; //通过抽象类工厂获得IGetDeviceState的派生类 //IGetDeviceState GDS; int s = 0; //int[] sss; int fs = 1; //int[] fsss; //提取光电开关索引值 int devk = 0; for (int i = AheadDetect.GetLowerBound(0); i <= AheadDetect.GetUpperBound(0); i++) { if (AheadDetect[i].Trim().Length <= 0) continue; #region 检测逻辑有探物H if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "H")//检测逻辑有探物 { devk = ccf.GetDeviceKindIdx(Convert.ToInt32(AheadDetect[i].Trim().Substring(1))); if (devk == 9) {//机台需要从管理设备表读取 //sql.Remove(0, sql.Length); //sql.Append("SELECT FID FROM T_ITEMDEVICESTATION WHERE (FCODE = '" ).Append( AheadDetect[i].Trim().Substring(1) ).Append( "') AND (FSTATUS = '1002')"); //if (dboM.ExceSQL(sql.ToString()).Tables[0].DefaultView.Count > 0) //{ // fs = fs & 1; //} //else //{ // fs = fs & 0; //} } else { //本地设备表读取 sql.Remove(0, sql.Length); sql.Append("SELECT F_DeviceIndex, F_HaveGoods FROM T_Base_Device where F_DeviceIndex=").Append( Convert.ToInt32(AheadDetect[i].Trim().Substring(1))); dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dvdv.Count > 0) { int havegoods = -1; if (Convert.ToInt32(dvdv[0]["F_HaveGoods"]) == 0)//20110505 { havegoods = 0; AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "设备逻辑无物!"); } else { havegoods = 1; } fs = fs & havegoods; } } continue; } #endregion #region 检测逻辑无探物N if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "N")//检测逻辑无探物 { devk = ccf.GetDeviceKindIdx(Convert.ToInt32(AheadDetect[i].Trim().Substring(1))); if (devk == 9) {//机台需要从管理设备表读取;20101028管理依赖任务控制机台的站台是否有物 //if (dboM.ExceSQL("SELECT FID FROM T_ITEMDEVICESTATION WHERE (FCODE = '" + AheadDetect[i].Trim().Substring(1) + "') AND (FSTATUS = '1002')").Tables[0].DefaultView.Count > 0) //{ // fs = fs & 1; //} //else //{ // fs = fs & 0; //} } else { //本地设备表读取 sql.Remove(0, sql.Length); sql.Append("SELECT F_DeviceIndex, F_HaveGoods FROM T_Base_Device where F_DeviceIndex=").Append( Convert.ToInt32(AheadDetect[i].Trim().Substring(1))); dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dvdv.Count > 0) { if (Convert.ToInt32(dvdv[0]["F_HaveGoods"]) > 0)//20110505 { AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "设备逻辑有物!"); } s = s + Convert.ToInt32(dvdv[0]["F_HaveGoods"]); } } continue; } #endregion #region 检测设备是否空闲I //20090803检测设备是否空闲idle if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "I")//检测设备是否空闲idle { int idev = Convert.ToInt32(AheadDetect[i].Trim().Substring(1)); if (idev.ToString().Length == 6) { idev = Convert.ToInt32(idev.ToString().Substring(0, 5)); } States = CStaticClass.GetDeviceState(idev); if (States != null) { //if ((States[1] == 5) && (ccf.GetDeviceKindIdx(Convert.ToInt32(AheadDetect[i].Trim().Substring(1))) == 2)) //{//20120409只有输送机的完成可作为空闲 // States[1] = 0; //} if (DeviceHandTaskIfRun(Convert.ToInt32(AheadDetect[i].Trim().Substring(1))) == true) {//20120207 AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "手工任务或者避让任务正在运行!"); States[1] = 1; } if (States[1] != 0)//20110505 { AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "设备不空闲!"); } s = s + States[1]; } continue; } #endregion #region 检测机械手是否可以发任务P //20090803检测设备是否空闲idle if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "P")//检测设备是否空闲idle { int idev = Convert.ToInt32(AheadDetect[i].Trim().Substring(1)); if (idev.ToString().Length == 6) { idev = Convert.ToInt32(idev.ToString().Substring(0, 5)); } States = CStaticClass.GetDeviceState(idev); if (States != null) { //if ((States[1] == 5) && (ccf.GetDeviceKindIdx(Convert.ToInt32(AheadDetect[i].Trim().Substring(1))) == 2)) //{//20120409只有输送机的完成可作为空闲 // States[1] = 0; //} //if (DeviceHandTaskIfRun(Convert.ToInt32(AheadDetect[i].Trim().Substring(1))) == true) //{//20120207 // AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "手工任务或者避让任务正在运行!"); // States[1] = 1; //} if (States[1] != 0)//20110505 { AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "设备不空闲!"); } s = s + States[1]; } continue; } #endregion #region 检测设备是否串盘锁定A //20090803检测设备是否空闲idle if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "A")//检测设备是否空闲idle { int idev = Convert.ToInt32(AheadDetect[i].Trim().Substring(1)); if (idev.ToString().Length == 6) { idev = Convert.ToInt32(idev.ToString().Substring(0, 5)); } if (Convert.ToInt32(dbo.GetSingle("select F_lock from T_NeedLock where F_DeviceIndex=" + idev)) > 0) { AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "该位置存在串盘风险!"); s = s + 1; } continue; } #endregion #region 提升机是否需要变更Z //20090803检测设备是否空闲idle if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "Z")//检测设备是否空闲idle { int arrow = Convert.ToInt32(dbo.GetSingle("select F_NumParam4 from t_monitor_task where F_MonitorIndex=" + minMidx)); int idev = Convert.ToInt32(AheadDetect[i].Trim().Substring(1)); if (idev.ToString().Length == 6) { idev = Convert.ToInt32(idev.ToString().Substring(0, 5)); } if (idev == 32006) { int count1 = CStaticClass.GetDevicePhotoelectric(32002, 0); int count2 = CStaticClass.GetDevicePhotoelectric(32001, 0); int count3 = Convert.ToInt32(dbo.GetSingle("select count(0) from t_monitor_task where F_NumParam4=32002 and F_Status>0")); int count4 = Convert.ToInt32(dbo.GetSingle("select count(0) from t_monitor_task where F_NumParam4=32001 and F_Status>0")); if (arrow == 32002) { if (count1 + count3 > 0 || CStaticClass.GetDeviceState(25004)[1] > 1) { if (count2 + count4 < 1 && CStaticClass.GetDeviceState(25003)[1] <= 1)//32002改到32001 { dbo.ExceSQL("update T_Monitor_Task set F_NumParam4=(case when F_NumParam4=32002 then 32001 when F_NumParam4=32001 then 32002 else F_NumParam4 end),F_NumParam1=(case when F_NumParam1=32002 then 32001 when F_NumParam1=32001 then 32002 when F_NumParam1=42012 then 42011 when F_NumParam1=42011 then 42012 when F_NumParam1=52012 then 52011 when F_NumParam1=52011 then 52012 else F_NumParam1 end),F_DeviceIndex=(case when F_DeviceIndex=25003 then 25004 when F_DeviceIndex=25004 then 25003 when F_DeviceIndex=42012 then 42011 when F_DeviceIndex=42011 then 42012 when F_DeviceIndex=52012 then 52011 when F_DeviceIndex=52011 then 52012 else F_DeviceIndex end) where F_ManageTaskIndex=" + fid); dbo.ExceSQL("update T_Monitor_Task set F_AheadDetect=REPLACE(REPLACE(replace(REPLACE(F_AheadDetect,'25004','25003'),'32002','32001'),'42012','42011'),'52012','52011') where F_ManageTaskIndex=" + fid); return false; } else { s = s + 1; AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "等待分道"); } } } if (arrow == 32001) { if (count2 + count4 > 1 || CStaticClass.GetDeviceState(25003)[1] > 1) { if (count1 + count3 < 1 && CStaticClass.GetDeviceState(25004)[1] <= 1)//32001改到32002 { dbo.ExceSQL("update T_Monitor_Task set F_NumParam4=(case when F_NumParam4=32002 then 32001 when F_NumParam4=32001 then 32002 else F_NumParam4 end),F_NumParam1=(case when F_NumParam1=32002 then 32001 when F_NumParam1=32001 then 32002 when F_NumParam1=42012 then 42011 when F_NumParam1=42011 then 42012 when F_NumParam1=52012 then 52011 when F_NumParam1=52011 then 52012 else F_NumParam1 end),F_DeviceIndex=(case when F_DeviceIndex=25003 then 25004 when F_DeviceIndex=25004 then 25003 when F_DeviceIndex=42012 then 42011 when F_DeviceIndex=42011 then 42012 when F_DeviceIndex=52012 then 52011 when F_DeviceIndex=52011 then 52012 else F_DeviceIndex end) where F_ManageTaskIndex=" + fid); dbo.ExceSQL("update T_Monitor_Task set F_AheadDetect=REPLACE(REPLACE(replace(REPLACE(F_AheadDetect,'25003','25004'),'32001','32002'),'42011','42012'),'52011','52012') where F_ManageTaskIndex=" + fid); return false; } else { s = s + 1; AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "等待分道"); } } } } if (idev == 42007) { int count1 = CStaticClass.GetDevicePhotoelectric(42002, 0); int count2 = CStaticClass.GetDevicePhotoelectric(42001, 0); int count3 = Convert.ToInt32(dbo.GetSingle("select count(0) from t_monitor_task where F_NumParam4=42002 and F_Status>0")); int count4 = Convert.ToInt32(dbo.GetSingle("select count(0) from t_monitor_task where F_NumParam4=42001 and F_Status>0")); if (arrow == 42002) { if (count1 + count3 > 0 || CStaticClass.GetDeviceState(25002)[1] > 1) { if (count2 + count4 < 1 && CStaticClass.GetDeviceState(25001)[1] <= 1)//42002改到42001 { dbo.ExceSQL("update T_Monitor_Task set F_NumParam4=(case when F_NumParam4=42002 then 42001 when F_NumParam4=42001 then 42002 when F_NumParam4=52002 then 52001 when F_NumParam4=52001 then 52002 else F_NumParam4 end),F_NumParam1=(case when F_NumParam1=42002 then 42001 when F_NumParam1=42001 then 42002 when F_NumParam1=22001 then 22002 when F_NumParam1=22002 then 22001 when F_NumParam1=52001 then 52002 when F_NumParam1=52002 then 52001 else F_NumParam1 end),F_DeviceIndex=(case when F_DeviceIndex=25001 then 25002 when F_DeviceIndex=25002 then 25001 when F_DeviceIndex=22001 then 22002 when F_DeviceIndex=22002 then 22001 else F_DeviceIndex end) where F_ManageTaskIndex=" + fid); dbo.ExceSQL("update T_Monitor_Task set F_AheadDetect=REPLACE(REPLACE(REPLACE(F_AheadDetect,'25002','25001'),'42002','42001'),'22002','22001') where F_ManageTaskIndex=" + fid); return false; } else { s = s + 1; AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "等待分道"); } } } if (arrow == 42001) { if (count2 + count4 > 0 || CStaticClass.GetDeviceState(25001)[1] > 1) { if (count1 + count3 < 1 && CStaticClass.GetDeviceState(25002)[1] <= 1)//42002改到42001 { dbo.ExceSQL("update T_Monitor_Task set F_NumParam4=(case when F_NumParam4=42002 then 42001 when F_NumParam4=42001 then 42002 when F_NumParam4=52002 then 52001 when F_NumParam4=52001 then 52002 else F_NumParam4 end),F_NumParam1=(case when F_NumParam1=42002 then 42001 when F_NumParam1=42001 then 42002 when F_NumParam1=22001 then 22002 when F_NumParam1=22002 then 22001 when F_NumParam1=52001 then 52002 when F_NumParam1=52002 then 52001 else F_NumParam1 end),F_DeviceIndex=(case when F_DeviceIndex=25001 then 25002 when F_DeviceIndex=25002 then 25001 when F_DeviceIndex=22001 then 22002 when F_DeviceIndex=22002 then 22001 else F_DeviceIndex end) where F_ManageTaskIndex=" + fid); dbo.ExceSQL("update T_Monitor_Task set F_AheadDetect=REPLACE(REPLACE(REPLACE(F_AheadDetect,'25001','25002'),'42001','42002'),'22001','22002') where F_ManageTaskIndex=" + fid); return false; } else { s = s + 1; AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "等待分道"); } } } } if (idev == 52007) { int count1 = CStaticClass.GetDevicePhotoelectric(52002, 0); int count2 = CStaticClass.GetDevicePhotoelectric(52001, 0); int count3 = Convert.ToInt32(dbo.GetSingle("select count(0) from t_monitor_task where F_NumParam4=52002 and F_Status>0")); int count4 = Convert.ToInt32(dbo.GetSingle("select count(0) from t_monitor_task where F_NumParam4=52001 and F_Status>0")); if (arrow == 52002) { if (count1 + count3 > 0 || CStaticClass.GetDeviceState(25002)[1] > 1) { if (count2 + count4 < 1 && CStaticClass.GetDeviceState(25001)[1] <= 1)//52002改到52001 { dbo.ExceSQL("update T_Monitor_Task set F_NumParam4=(case when F_NumParam4=42002 then 42001 when F_NumParam4=42001 then 42002 when F_NumParam4=52002 then 52001 when F_NumParam4=52001 then 52002 else F_NumParam4 end),F_NumParam1=(case when F_NumParam1=42002 then 42001 when F_NumParam1=42001 then 42002 when F_NumParam1=22001 then 22002 when F_NumParam1=22002 then 22001 when F_NumParam1=52001 then 52002 when F_NumParam1=52002 then 52001 else F_NumParam1 end),F_DeviceIndex=(case when F_DeviceIndex=25001 then 25002 when F_DeviceIndex=25002 then 25001 when F_DeviceIndex=22001 then 22002 when F_DeviceIndex=22002 then 22001 else F_DeviceIndex end) where F_ManageTaskIndex=" + fid); dbo.ExceSQL("update T_Monitor_Task set F_AheadDetect=REPLACE(REPLACE(REPLACE(F_AheadDetect,'25002','25001'),'52002','52001'),'22002','22001') where F_ManageTaskIndex=" + fid); return false; } else { s = s + 1; AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "等待分道"); } } } if (arrow == 52001) { if (count2 + count4 > 0 || CStaticClass.GetDeviceState(25001)[1] > 1) { if (count1 + count3 < 1 && CStaticClass.GetDeviceState(25002)[1] <= 1)//42002改到42001 { dbo.ExceSQL("update T_Monitor_Task set F_NumParam4=(case when F_NumParam4=42002 then 42001 when F_NumParam4=42001 then 42002 when F_NumParam4=52002 then 52001 when F_NumParam4=52001 then 52002 else F_NumParam4 end),F_NumParam1=(case when F_NumParam1=42002 then 42001 when F_NumParam1=42001 then 42002 when F_NumParam1=22001 then 22002 when F_NumParam1=22002 then 22001 when F_NumParam1=52001 then 52002 when F_NumParam1=52002 then 52001 else F_NumParam1 end),F_DeviceIndex=(case when F_DeviceIndex=25001 then 25002 when F_DeviceIndex=25002 then 25001 when F_DeviceIndex=22001 then 22002 when F_DeviceIndex=22002 then 22001 else F_DeviceIndex end) where F_ManageTaskIndex=" + fid); dbo.ExceSQL("update T_Monitor_Task set F_AheadDetect=REPLACE(REPLACE(REPLACE(F_AheadDetect,'25001','25002'),'52001','52002'),'22001','22002') where F_ManageTaskIndex=" + fid); return false; } else { s = s + 1; AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "等待分道"); } } } } if (idev == 12076 || idev == 12079) { int count1 = CStaticClass.GetDevicePhotoelectric(12103, 0); int count2 = CStaticClass.GetDevicePhotoelectric(12101, 0); int count3 = Convert.ToInt32(dbo.GetSingle("select count(0) from t_monitor_task where F_NumParam4=12103 and F_Status>0")); int count4 = Convert.ToInt32(dbo.GetSingle("select count(0) from t_monitor_task where F_NumParam4=12101 and F_Status>0")); int count5 = CStaticClass.GetDevicePhotoelectric(12103, 6);//专机是否可用 int count6 = CStaticClass.GetDevicePhotoelectric(12101, 6);//专机是否可用 if (arrow == 12103) { if (count1 + count3 > 0 || count5 == 0) { if (count2 + count4 < 1 && count6 == 1) { dbo.ExceSQL("update T_Monitor_Task set F_NumParam4=12101 where F_MonitorIndex=" + minMidx); return false; } else { s = s + 1; AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "等待分道"); } } } if (arrow == 12101) { if (count2 + count4 > 0 || count6 == 0) { if (count1 + count3 < 1 && count5 == 1) { dbo.ExceSQL("update T_Monitor_Task set F_NumParam4=12103 where F_MonitorIndex=" + minMidx); return false; } else { s = s + 1; AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "等待分道"); } } } } if (idev == 62029) { int count1 = CStaticClass.GetDevicePhotoelectric(62030, 0); int count2 = CStaticClass.GetDevicePhotoelectric(62034, 0); int count3 = Convert.ToInt32(dbo.GetSingle("select count(0) from t_monitor_task where F_NumParam4=62030 and F_Status>0")); int count4 = Convert.ToInt32(dbo.GetSingle("select count(0) from t_monitor_task where F_NumParam4=62034 and F_Status>0")); if (arrow == 62030) { if (count1 + count3 > 0) { if (count2 + count4 < 1) { dbo.ExceSQL("update T_Monitor_Task set F_NumParam4=62034 where F_MonitorIndex=" + minMidx); return false; } else { s = s + 1; AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "等待分道"); } } } if (arrow == 62034) { if (count2 + count4 > 0) { if (count1 + count3 < 1) { dbo.ExceSQL("update T_Monitor_Task set F_NumParam4=62030 where F_MonitorIndex=" + minMidx); return false; } else { s = s + 1; AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "等待分道"); } } } } continue; } #endregion #region 检测终点任务数U if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "U")//检测F_NumParam1,F_NumParam4设备无正在运行的任务 { int endcount = CStaticClass.GetDevicePhotoelectric(Convert.ToInt32(AheadDetect[i].Trim().Substring(1)), 0) == 1 ? 1 : 0; //int[] enddev; //enddev = CStaticClass.GetDeviceState(Convert.ToInt32(AheadDetect[i].Trim().Substring(1))); //if (enddev != null) //{ // if (enddev[1] == 5 || enddev[1] == 0) // {//20120409只有输送机的完成可作为空闲 // } //} sql.Clear(); sql.Append(string.Format("SELECT count(fid) FROM T_manage_Task WHERE FENDDEVICE = {0} AND FStatus > 0 and fid<>{1} and fstartdevice like '1800%'", Convert.ToInt32(AheadDetect[i].Trim().Substring(1)), fid)); int count1 = Convert.ToInt32(dbo.GetSingle(sql.ToString())); sql.Clear(); sql.Append(string.Format("SELECT count(fid) FROM T_manage_Task WHERE FENDDEVICE = {0} and fid<>{1} and fstartdevice like '1200%'", Convert.ToInt32(AheadDetect[i].Trim().Substring(1)), fid)); int count2 = Convert.ToInt32(dbo.GetSingle(sql.ToString())); if (Convert.ToInt32(AheadDetect[i].Trim().Substring(1)) == 12042) { if (count1 + count2 + endcount >= 1) { s = s + 1; AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "终点任务超过一个!"); } else { s = s + 0; } } else { if (count1 + count2 + endcount >= 2) { s = s + 1; AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "终点任务超过两个!"); } else { s = s + 0; } } continue; } #endregion #region 检测码垛位置是否有可用空托盘M if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "M") { //获取当前传输线是否有货 有货为1无货为0 (有无货代表有没有空托盘) int endcount = CStaticClass.GetDevicePhotoelectric(Convert.ToInt32(AheadDetect[i].Trim().Substring(1, 5)), 0) == 1 ? 1 : 0; if (endcount == 1) { //如果有托盘判断是否为可用托盘 Gflag = 0 为可用 sql.Clear(); sql.Append(string.Format("SELECT Gflag FROM [dbo].[ZH_pallet] where Device={0} and Gflag = 0 and GOODS_COUNT=0", Convert.ToInt32(AheadDetect[i].Trim().Substring(1, 5)))); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { s = s + 0; } else { s = s + 1; AheadDetectUnallow.Append(Convert.ToInt32(AheadDetect[i].Trim().Substring(1, 5)).ToString() + "托盘不可用!"); } //int count1 = Convert.ToInt32(dbo.GetSingle(sql.ToString())); //if (count1 == 0) //{ // s = s + 0; //} //else //{ // s = s + 1; // AheadDetectUnallow.Append(Convert.ToInt32(AheadDetect[i].Trim().Substring(1, 5)).ToString() + "托盘不可用!"); //} } else { int tempdevice = 0; switch (Convert.ToInt32(AheadDetect[i].Trim().Substring(1, 5))) { case 12011: tempdevice = 12015; break; case 12014: tempdevice = 12015; break; case 12007: tempdevice = 12016; break; case 12008: tempdevice = 12016; break; } //查询有没有空托盘任务 sql.Clear(); sql.Append(string.Format("SELECT * FROM [dbo].[T_Manage_Task] where FSTARTDEVICE = {1} and FENDDEVICE={0}", AheadDetect[i].Trim().Substring(1, 5), tempdevice)); int count1 = Convert.ToInt32(dbo.GetSingle(sql.ToString())); sql.Clear(); sql.Append(string.Format("SELECT * FROM [dbo].[ZH_pallet] where Device={0}", Convert.ToInt32(AheadDetect[i].Trim().Substring(1, 5)))); int count3 = Convert.ToInt32(dbo.GetSingle(sql.ToString())); if (count1 == 0 && count3 == 0) { sql.Clear(); //sql.Append(string.Format("SELECT * FROM [dbo].[T_Manage_Task] where FID=(select F_ManageTaskIndex from T_Monitor_Task where F_DeviceIndex={0} and FENDDEVICE='{1}')", DeviceIdx, AheadDetect[i].Trim().Substring(1, 5))); sql.Append(string.Format("SELECT * FROM [dbo].[T_Manage_Task] where FID in (select F_ManageTaskIndex from T_Monitor_Task where F_DeviceIndex={0} and F_NumParam4 ='{1}')", DeviceIdx, AheadDetect[i].Trim().Substring(1, 5))); DataView dvIO = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; sql.Clear(); sql.Append(string.Format("INSERT INTO [dbo].[T_Manage_Task]([FID], [F_ManageTaskKindIndex], [FMANAGEID], [F_RELATIVECONTORLID],[FPALLETBARCODE], [FCONTROLTASKTYPE], [FTASKLEVEL], [FISRETURN], [FSTARTWAREHOUSE], [FSTARTDEVICE] , [FSTARTCELL], [FSTARTUCODE] , [FENDWAREHOUSE], [FENDDEVICE], [FENDCELL] , [FENDUCODE], [FSTATUS] , [FBEGTIME], [FENDTIME], [FIntoStepOK], [FLANEWAY], [FSTACK] , [FCurrentLocation], [FUseAwayFork], [FCONTORL_BATCH], [FLOGIC_AREA], [FStartCol], [FStartLayer], [FEndCol], [FEndLayer], [Work_Mode] , [BATTERY_TYPE], [BATTERY_BATCH],[FREMARK])VALUES({0},2 ,{4},-1,'B000001',4,1,0,'-','{1}','','0','-','{2}','','0',0,'{3}','-',0,0,0,0,0,'','',0,0,0,0,'2','0','0','{5}')", ccf.GetTempManageIdx(), tempdevice, AheadDetect[i].Trim().Substring(1, 5), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), dvIO[0]["FMANAGEID"].ToString(), dvIO[0]["FREMARK"].ToString())); dbo.GetSingle(sql.ToString()); s = s + 1; AheadDetectUnallow.Append(Convert.ToInt32(AheadDetect[i].Trim().Substring(1, 5)).ToString() + "没有可用空托盘!"); } else { s = s + 1; AheadDetectUnallow.Append(Convert.ToInt32(AheadDetect[i].Trim().Substring(1, 5)).ToString() + "等待抓取可用空托盘!"); } } continue; } #endregion #region 检测化成分容设备气缸是否低位Q(低位是可用的) if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "Q")//检测设备是否空闲idle { string cell = AheadDetect[i].Trim().Substring(1); if (cell != null) { if (dboM.GetSingle("select cylinder_status from wms_dl_cell where cell_code='" + cell + "'").ToString() != "2") {//20120207 AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "货位气缸不在低位!"); s = s + 1; } } continue; } #endregion #region 检测化成分容设备是否可用(鼎力认为只有设备真正空出来才是可用K) if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "K")//检测设备是否空闲idle { string cell = AheadDetect[i].Trim().Substring(1); if (cell != null) { if (dboM.GetSingle("select run_status_dl from wms_dl_cell where cell_code='" + cell + "'").ToString() != "Enable") {//20120207 AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "货位不可用!"); s = s + 1; } } continue; } #endregion #region 检测化成分容设备是否有货Y if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "Y")//检测设备是否空闲idle { string cell = AheadDetect[i].Trim().Substring(1); if (cell != null) { if (dboM.GetSingle("select cell_status_dl from wms_dl_cell where cell_code='" + cell + "'").ToString() != "Full") {//20120207 AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "鼎力上报货位不是有货状态!"); s = s + 1; } } continue; } #endregion #region 检测化成分容设备是否无货W if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "W")//检测设备是否空闲idle { string cell = AheadDetect[i].Trim().Substring(1); if (cell != null) { if (dboM.GetSingle("select cell_status_dl from wms_dl_cell where cell_code='" + cell + "'").ToString() != "Nohave") {//20120207 AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "鼎力上报货位不是无货状态!"); s = s + 1; } } continue; } #endregion #region 检测出库任务放货位置有没有正在执行的AGV放货任务J if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "J") { int FENDDEVICE = Convert.ToInt32(AheadDetect[i].Trim().Substring(1, 5)); sql.Clear(); sql.Append(string.Format("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE = 4 and (FENDDEVICE in (select FENDDEVICE from T_Manage_Task where fid = {0}))", fid)); dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dvdv.Count != 0) { s = s + 1; AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "有AGV入库任务!"); } else { s = s + 0; } continue; } #endregion #region 检测AGV任务有没有同货位的出库任务E if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "E") { int FENDDEVICE = Convert.ToInt32(AheadDetect[i].Trim().Substring(1, 5)); sql.Clear(); //sql.Append(string.Format("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE = 2 and FSTATUS=1 and (FENDDEVICE in (select FENDDEVICE from T_Manage_Task where fid not in ({0})))", fid)); sql.Append(string.Format(" SELECT* FROM T_Manage_Task WHERE FCONTROLTASKTYPE = 2 and FSTATUS = 1 and FID != {0} and FID in (select distinct F_ManageTaskIndex from T_Monitor_Task where F_ManageTaskIndex = {0} and(F_NumParam4 = {1} or F_NumParam5 = {1})) ", fid, EndDevice)); dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dvdv.Count != 0) { s = s + 1; AheadDetectUnallow.Append(FENDDEVICE + "有堆垛机出库任务!"); } else { s = s + 0; } continue; } #endregion #region 检测内侧取货时是否有对外侧货位的操作X if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "X")//检测积放线正在执行任务个数(J12008,2) { cc[0] = ','; sp = AheadDetect[i].Trim().Substring(1).Split(cc); if (sp.GetLength(0) == 3) { string z = sp[0].Length == 1 ? "0" + sp[0] : sp[0]; string x = sp[1].Length == 1 ? "0" + sp[1] : sp[1]; string y = sp[2].Length == 1 ? "0" + sp[2] : sp[2]; string kkk = z + "-" + x + "-" + y; int count1 = Convert.ToInt32(dbo.GetSingle("select count(0) from t_manage_task where FSTATUS=0 and FSTARTCELL='" + kkk + "'")); int count2 = Convert.ToInt32(dbo.GetSingle("select count(0) from t_monitor_task where F_NumParam1=" + sp[0].ToString() + " and F_NumParam2=" + sp[1].ToString() + " and F_NumParam3=" + sp[2].ToString())); if (count1 + count2 > 0) { s = s + 1; AheadDetectUnallow.Append("避让外侧任务!"); } else { s = s + 0; } } continue; } #endregion #region 检测外侧送货时是否有对内侧货位的操作Y if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "Y")//检测积放线正在执行任务个数(J12008,2) { cc[0] = ','; sp = AheadDetect[i].Trim().Substring(1).Split(cc); if (sp.GetLength(0) == 3) { string z = sp[0].Length == 1 ? "0" + sp[0] : sp[0]; string x = sp[1].Length == 1 ? "0" + sp[1] : sp[1]; string y = sp[2].Length == 1 ? "0" + sp[2] : sp[2]; string kkk = z + "-" + x + "-" + y; int count1 = Convert.ToInt32(dbo.GetSingle("select count(0) from t_manage_task where FSTATUS=0 and FENDCELL='" + kkk + "'")); int count2 = Convert.ToInt32(dbo.GetSingle("select count(0) from t_monitor_task where F_NumParam4=" + sp[0].ToString() + " and F_NumParam5=" + sp[1].ToString() + " and F_NumParam6=" + sp[2].ToString())); if (count1 + count2 > 0) { s = s + 1; AheadDetectUnallow.Append("避让内侧任务!"); } else { s = s + 0; } } continue; } #endregion #region 检测设备是否被堆垛机预约R //20120409 if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "R" && DeviceKind == 1)////20140309检测设备是否被堆垛机预约 { sql.Remove(0, sql.Length); sql.Append("select F_ManTaskReserve from T_Base_Device where F_ManTaskReserve>0 and F_DeviceIndex=").Append(Convert.ToInt32(AheadDetect[i].Trim().Substring(1))); object obr = dbo.GetSingle(sql.ToString()); if (obr != null) { if (obr.ToString() != (mti.ToString() + fid.ToString())) { s = s + 1; AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "被调度任务:").Append(obr.ToString()).Append("预约!"); } else { s = s + 0; } } continue; } #endregion #region 检测设备光电信号 //检测设备的光电信号:D-12001.0表示输送机12001的入口开关有物;D12001.1表示输送机12001的入口开关无物 //D-12001.2表示输送机12001的顶升高位(高到位);D12001.3表示输送机12001的顶升不在低位(不是低到位) if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "D") { int devicebyte = 0, devbit = 0; DS = AheadDetect[i].Trim().Substring(1).Split(dd); int.TryParse(DS[0], out devicebyte); int.TryParse(DS[1], out devbit); //判断是否检测负数索引值(负数代表是否满足开关量=1的执行前提) if (devicebyte < 0) { #region 负数代表值为1的开关量检测 int fsn = CStaticClass.GetDevicePhotoelectric(-devicebyte, devbit);//20101124 if (fsn != 1)//20110505 { StringBuilder kg = new StringBuilder(); switch (devbit) { case 0: kg.Append(".0有物"); break; case 1: kg.Append(".1有物"); break; case 2: if (ccf.GetDeviceKindIdx(-devicebyte) == 31) { kg.Append("高位"); } else { kg.Append(".2高位"); } break; case 3: kg.Append(".3低位"); break; case 4: kg.Append(".4高位"); break; case 5: kg.Append("有物"); break; case 6: kg.Append("高位"); break; case 7: kg.Append("低位"); break; default: break; } //if (Convert.ToInt32(dbo.GetSingle("select count(0) from T_NeedLock where f_deviceindex=" + (-devicebyte).ToString())) > 0 && devbit == 0) //{ // int emptylock = Convert.ToInt32(dbo.GetSingle("select f_lock from T_NeedLock where f_deviceindex=" + (-devicebyte).ToString())); // if (emptylock != 1) // { // dbo.ExceSQL("update T_NeedLock set f_lock=1 where f_deviceindex=" + (-devicebyte).ToString()); // } //} AheadDetectUnallow.Append(Convert.ToInt32((-devicebyte)).ToString() + kg.ToString() + "光电开关不遮挡!"); } fs = fs & fsn; #endregion } else {// #region 正数值不能为1的开关量检测 int sssn = CStaticClass.GetDevicePhotoelectric(devicebyte, devbit); if (sssn != 0)//20110505 { StringBuilder kg = new StringBuilder(); switch (devbit) { case 0: kg.Append(".0有物"); break; case 1: kg.Append(".1有物"); break; case 2: if (ccf.GetDeviceKindIdx(devicebyte) == 31) { kg.Append("高位"); } else { kg.Append(".2高位"); } break; case 3: kg.Append(".3低位"); break; case 4: kg.Append(".4高位"); break; case 5: kg.Append("有物"); break; case 6: kg.Append("高位"); break; case 7: kg.Append("低位"); break; default: break; } AheadDetectUnallow.Append(devicebyte.ToString() + kg.ToString() + "光电开关遮挡!"); } s = s + sssn; #endregion } } #endregion #region 检测设备是否被AGV锁定C //20090803检测设备是否空闲idle if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "C")//检测设备是否空闲idle { int devicebyte = 0, devbit = 0; DS = AheadDetect[i].Trim().Substring(1).Split(dd); int.TryParse(DS[0], out devicebyte); int.TryParse(DS[1], out devbit); if (devicebyte < 0) { int fsn = CStaticClass.GetDevicePhotoelectric(-devicebyte, devbit);//20240228 if (fsn > 0 || fsn == -9999) { s = s + 1; AheadDetectUnallow.Append(Convert.ToInt32((-devicebyte)).ToString() + ".2AGV互锁等待放货完成!"); } s = s + 0; } continue; } #endregion } #region 非手工任务,如果有手工任务等待执行先执行手工任务 if (mti != 4) {//20120405 if (DeviceHandTaskIfWaitRun(devinfo.DeviceIndex) == true) { AheadDetectUnallow.Append(devinfo.DeviceIndex.ToString() + "手工任务或者避让任务等待运行!"); s += 1; } } #endregion #region 检测向管理申请入库任务条码和PLCASK记录是否匹配 //20130709增加输送站台向管理申请入库任务,或者条码比对的任务,扫描后人工随意搬走箱子的保护,入库任务条码和PLCAsk记录的不相同不再执行任务 //if (DeviceKind == 1)//宁波地铁出库不检测 //{ // sql.Remove(0, sql.Length); // sql.Append("SELECT T_Base_Device.F_DeviceIndex FROM T_Base_Device,T_Base_PLC_Ask WHERE ( T_Base_Device.F_DeviceIndex = T_Base_PLC_Ask.F_DeviceIndex) and (T_Base_Device.F_DeviceKindIndex = 7) AND T_Base_PLC_Ask.F_BindingDevice = ").Append(devinfo.DeviceIndex); // object obr1 = dbo.GetSingle(sql.ToString()); // if (obr1 != null) // { // sql.Remove(0, sql.Length); // sql.Append("SELECT F_BarCode FROM T_Base_PLC_Ask where F_BindingDevice=").Append(devinfo.DeviceIndex); // object obr = dbo.GetSingle(sql.ToString()); // if (obr != null) // { // if ((obr.ToString().IndexOf(ccf.GetBarCodeFromMonitor(minMidx)) < 0) && (ccf.GetBarCodeFromMonitor(minMidx).IndexOf(obr.ToString()) < 0)) // { // s = s + 1; // AheadDetectUnallow.Append(devinfo.DeviceIndex.ToString() + "记录的条码:").Append(obr.ToString()).Append(",和任务条码").Append(ccf.GetBarCodeFromMonitor(minMidx)).Append("不匹配!"); // } // } // } //} #endregion if ((s != 0) || (fs != 1)) { UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } #endregion #region 有互斥设备的堆垛机20111020 if (DeviceKind == 1 && devinfo.VirtualStack > 0) { int mutex = ccf.GetStackMutexDevice(DeviceIdx); if (mutex > 0) {//检查互斥设备空闲时的位置和运行的目标位置 Model.MDevice mutexdev = Model.CGetInfo.GetDeviceInfo(mutex); int mutexDeviceLockedState = ccf.GetDeviceLockedState(mutex); if (mutexDeviceLockedState == -1) return true;//20120110 int mutexManTaskReserve = ccf.GetManTaskReserve(mutex); if ((mutexdev.RunState == 0) && (mutexManTaskReserve <= 0) && (mutexDeviceLockedState == 0)) {// #region mutex空闲、无任务、无管理任务预约锁 int xcoor = Model.CGeneralFunction.GetXCoorFromMonitor(TaskIdx, DeviceIdx, ccf.GetDeviceOrderFromMonitor(TaskIdx)); int zcoor = Model.CGeneralFunction.GetZCoorFromMonitor(TaskIdx, DeviceIdx, ccf.GetDeviceOrderFromMonitor(TaskIdx)); int BCcoor = GetBarcodeCoor(xcoor, zcoor); if (mutex > DeviceIdx) {//mutex=35002 if ((BCcoor + StackMutexXCoor) >= mutexdev.XCoor)//mdev.XCoor如果是条码带值需要转换为列值 { InsertStackMutexOrder(mutex, 2, (BCcoor + StackMutexXCoor), 5); if (mutexdev.XCoor > 52000)//20120110 { return true; } else { if (devinfo.XCoor <= mutexdev.XCoor - minStackMutexXCoor) { return true; } else { return false; } } } } else {//mutex35001 if (BCcoor >= (StackMutexXCoor + StackZeroXCoor)) { BCcoor = (BCcoor - StackMutexXCoor); } else { return true;//对开报警吧,管理下任务错了,或者分配堆垛机设备错误 } if (BCcoor <= mutexdev.XCoor)//mdev.XCoor如果是条码带值需要转换为列值 { InsertStackMutexOrder(mutex, 2, BCcoor, 5); if (mutexdev.XCoor < 4481)//20120110 { return true; } else { if (devinfo.XCoor > mutexdev.XCoor + minStackMutexXCoor) { return true; } else { return false; } } } } #endregion } else {//mutex有任务运行 int xcoor = Model.CGeneralFunction.GetXCoorFromMonitor(TaskIdx, DeviceIdx, ccf.GetDeviceOrderFromMonitor(TaskIdx)); int zcoor = Model.CGeneralFunction.GetZCoorFromMonitor(TaskIdx, DeviceIdx, ccf.GetDeviceOrderFromMonitor(TaskIdx)); int bccoor = GetBarcodeCoor(xcoor, zcoor); int mutXcoor; int mutZcoor; GetStackRunX_Zcoor(mutex, out mutXcoor, out mutZcoor); if (mutXcoor > 0) { #region 互斥有任务正在运行 int mutbccoor = GetBarcodeCoor(mutXcoor, mutZcoor); if (mutex > DeviceIdx) { if (mutbccoor <= (bccoor + StackMutexXCoor)) { if (mutbccoor > 52000) {//20120110 return true; } else { return false; } } } else {//mutex小 if (bccoor >= (StackMutexXCoor + StackZeroXCoor)) { if (mutbccoor >= (bccoor - StackMutexXCoor)) { if (mutbccoor < 4481)//20120110 {//20120110 return true; } else { return false; } } } else { if (bccoor >= 52000) { return true; } else { return false; } } } #endregion } else {//有任务,被预约,但没运行任务,可能报警或者触摸屏控制 if ((mutexdev.RunState > 0) || (mutexDeviceLockedState != 0)) {// 报警或者被任务锁定 #region 互斥设备不空闲 if (mutex > DeviceIdx) {//mutex=35002 if (mutexdev.XCoor <= (bccoor + StackMutexXCoor)) { return false;//或者放行直接报警 } } else {//mutex=35001 if (bccoor >= (StackMutexXCoor + StackZeroXCoor)) { if (mutexdev.XCoor >= (bccoor - StackMutexXCoor)) { return false; } } else { return false; } } #endregion } else { #region mutex被管理任务预约了,但是还没运行(【送货】等待运行) int deviceorder = GetDeviceOrderFromManTaskReserve(mutexManTaskReserve, mutex); if (deviceorder == -1) return false; GetStackRunReserveX_Zcoor(mutex, out mutXcoor, out mutZcoor); if (mutex > DeviceIdx) { if (mutexdev.XCoor <= (bccoor + StackMutexXCoor)) { //去货位高度合适位置避让,或者到52列(60000) InsertStackMutexOrder(mutex, deviceorder, (bccoor + StackMutexXCoor), GetLayerHigh(mutZcoor, mutXcoor)); if (mutexdev.XCoor > 52000)//20120110 { return true; } else { if (devinfo.XCoor < mutexdev.XCoor - minStackMutexXCoor) { return true; } else { return false; } } } } else {//mutex小 if (bccoor >= (StackMutexXCoor + StackZeroXCoor)) { if (mutexdev.XCoor >= (bccoor - StackMutexXCoor)) { //去货位高度合适位置避让,或者到0列(2000) InsertStackMutexOrder(mutex, deviceorder, (bccoor - StackMutexXCoor), GetLayerHigh(mutZcoor, mutXcoor)); if (mutexdev.XCoor < 4481) { return true; } else { if (devinfo.XCoor > mutexdev.XCoor + minStackMutexXCoor) { return true; } else { return false; } } } } else { return false; } } #endregion } } } } } #endregion #region 顶升机先控制近叉输送机送出 ////20111226 //string r1 = "12001,42001,32001,12009,42009,32009,12017,42017,32017"; //if ((r1.IndexOf(DeviceIdx.ToString()) >= 0) &&(devinfo.IfCorrelDoubleFork!="1")) //{ // if (IFExitTopPriDeviceIdxTaskWait(DeviceIdx+1) == true) // { // return false; // } //} #endregion int CONTROLTASKTYPE = ccf.GetFCONTROLTASKTYPEFromManageTask(mti, fid); #region 顶升机构自关联入库任务单独处理//20101011 //20100406入库顶升时必要检测:1102内探物“-11021”;1121低到位“-11212”;有关联任务时,1102外探物“-11022”; if ((ccf.GetCorrel_DeviceIndex(devinfo.DeviceIndex, true) == "0") && (CONTROLTASKTYPE == 1) && (devinfo.IfCorrelDoubleFork == "1"))//顶升设备自关联,入库任务20101124增加顶升设备是否双叉判断 { string[] CorrelInfo = ccf.GetOwnCorrel_DeviceInfo(devinfo.DeviceIndex); if (CorrelInfo == null) { //20110505 AheadDetectUnallow.Append("顶升机构" + devinfo.DeviceIndex.ToString() + "没有自关联!"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } if ((CStaticClass.GetDevicePhotoelectric(CorrelInfo[5]) == 1) && (CStaticClass.GetDevicePhotoelectric(CorrelInfo[2]) == 1))//近巷道有物,顶升低位//20101124 { #region 等待关联任务配对 //在CStaticClass.DoubleForkWaitTime规定时间内等待;1102(11027)转动等待 sql.Remove(0, sql.Length); sql.Append("SELECT F_TaskIndex,F_DeviceIndex,F_Remark FROM T_Base_PLC_Ask WHERE (F_TaskIndex =").Append(TaskIdx).Append(") AND (F_Remark <> '') AND (F_DeviceIndex=").Append(devinfo.DeviceIndex).Append(")"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { //(Convert.ToDateTime(dv[0]["F_Remark"]).AddSeconds(Convert.ToInt32(CStaticClass.DoubleForkWaitTime)) > DateTime.Now) || if ((GetIOControlStatus(minMidx) != Model.CGeneralFunction.TASKSINGLEFORKRUN) || ((CStaticClass.GetDevicePhotoelectric(CorrelInfo[6]) == 1) && (CStaticClass.GetDevicePhotoelectric(CorrelInfo[4]) == 0)))//20101124 { if ((CStaticClass.GetDevicePhotoelectric(CorrelInfo[6]) == 1) && (CStaticClass.GetDevicePhotoelectric(CorrelInfo[4]) == 0))//外探物,运行//20101124 { //查找本地管理任务做多叉关联配对,关联任务分配近叉 int mfid = GetEnableDoubleForkManageTask(1, devinfo.DeviceIndex, fid); if (mfid > 0) { sql.Remove(0, sql.Length); sql.Append("update T_Manage_Task set F_RELATIVECONTORLID=").Append(mfid).Append(" where F_ManageTaskKindIndex=").Append(mti).Append(" and FID=").Append(fid); dbo.ExecuteSql(sql.ToString()); sql.Remove(0, sql.Length); sql.Append("update T_Manage_Task set FUseAwayFork='0',F_RELATIVECONTORLID=").Append(fid).Append(" where F_ManageTaskKindIndex=").Append(mti).Append(" and FID=").Append(mfid); dbo.ExecuteSql(sql.ToString()); sql.Remove(0, sql.Length); sql.Append("update T_Monitor_Task set F_UseAwayFork='0' where F_ManageTASKKINDINDEX=").Append(mti).Append(" and F_ManageTaskIndex=").Append(mfid).Append(""); dbo.ExecuteSql(sql.ToString()); //由于已经分配路径不一定符合远近货叉的分配原则,需要改道 AlterRoutePath(mti, mfid, CONTROLTASKTYPE, '0', devinfo.DeviceIndex); } return true; } else { //20110505 AheadDetectUnallow.Append("顶升机构" + devinfo.DeviceIndex.ToString() + "等待关联任务!"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } else {//超过等待时间或者管理强制执行单叉任务 if (CStaticClass.GetDevicePhotoelectric(CorrelInfo[4]) == 1)//20101124 { sql.Remove(0, sql.Length); sql.Append("update T_Base_PLC_Ask set F_Remark='").Append(dtime).Append("' where (F_DeviceIndex=").Append(devinfo.DeviceIndex).Append(")"); dbo.ExecuteSql(sql.ToString()); //20110505 AheadDetectUnallow.Append("顶升机构" + devinfo.DeviceIndex.ToString() + "等待关联任务!"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } sql.Remove(0, sql.Length); sql.Append("update T_Base_PLC_Ask set F_TaskIndex=0,F_Remark='' where (F_DeviceIndex=").Append(devinfo.DeviceIndex).Append(")"); dbo.ExecuteSql(sql.ToString()); return true; } } else { sql.Remove(0, sql.Length); sql.Append("SELECT F_TaskIndex,F_DeviceIndex,F_Remark FROM T_Base_PLC_Ask WHERE (F_TaskIndex =0) AND (F_Remark = '') AND (F_DeviceIndex=").Append(devinfo.DeviceIndex).Append(")"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { sql.Remove(0, sql.Length); sql.Append("update T_Base_PLC_Ask set F_TaskIndex=").Append(TaskIdx).Append(",F_Remark='").Append(dtime).Append("' where (F_DeviceIndex=").Append(devinfo.DeviceIndex).Append(")"); dbo.ExecuteSql(sql.ToString()); sql.Remove(0, sql.Length); sql.Append("update T_Monitor_Task set F_UseAwayFork='1' where F_ManageTASKKINDINDEX=").Append(mti).Append(" and F_ManageTaskIndex=").Append(fid).Append(""); dbo.ExecuteSql(sql.ToString()); sql.Remove(0, sql.Length); sql.Append("update T_Manage_Task set FUseAwayFork='1' where F_ManageTASKKINDINDEX=").Append(mti).Append(" and FID=").Append(fid).Append(""); dbo.ExecuteSql(sql.ToString()); //由于已经分配路径不一定符合远近货叉的分配原则,需要改道 AlterRoutePath(mti, fid, CONTROLTASKTYPE, '1', devinfo.DeviceIndex); return false; } } #endregion } else { //20110505 AheadDetectUnallow.Append("顶升机构" + devinfo.DeviceIndex.ToString() + "不满足关联状态!"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } #endregion //20101011 #region 双叉堆垛机的取货任务在此判断是否关联双叉、验证双叉任务是否为双叉极限货位 if ((devinfo.DeviceKind == 1) && (devinfo.IfCorrelDoubleFork == "1") && (ccf.GetDeviceOrderFromMonitor(minMidx) == 4)) { string[] DevLanewayIOInfo = ccf.GetDeviceLaneGateInfoFromStackCoor(devinfo.DeviceIndex, minMidx); if (DevLanewayIOInfo == null) { //不是巷道口的取货任务不需要关联 CommonClassLib.CCarryConvert.WriteDarkCasket("单叉执行原因", minMidx.ToString(), devinfo.DeviceIndex.ToString(), "不是巷道口的取货任务不需要关联"); return true; } Dictionary corrinfo = Model.CGeneralFunction.GetDoubleForkMonitorInfo(minMidx, devinfo.DeviceIndex); if (corrinfo == null)//20110412没关联任务 { #region 20110412堆垛机在顶升机取单叉任务,验证是否需要换货叉 string ChangeForkCell = ccf.IfLimitCellChangeFork(minMidx, devinfo.DeviceIndex); if (ChangeForkCell != "-")//主任务需要倒换货叉 { ccf.ChangeEndCellCode(minMidx, ChangeForkCell, devinfo.DeviceIndex); return false;//20140423richard如果不返回false,还会使用原来的坐标继续发送 } #endregion #region 没关联任务 //string IfCorrel = ccf.GetCorrel_DeviceIndex(minMidx);//20110505 //if (IfCorrel == "")//无关联 //{ //} //else if (IfCorrel == "0")//自关联 //{ // //20110108 // dbo.ExecuteSql("update T_Monitor_Task set F_UseAwayFork='1' where F_ManageTASKKINDINDEX=" + mti + " and F_ManageTaskIndex=" + fid + ""); // dbo.ExecuteSql("update T_Manage_Task set FUseAwayFork='1' where F_ManageTASKKINDINDEX=" + mti + " and FID=" + fid + ""); // #region 20110412堆垛机在顶升机取单叉任务,验证是否需要换货叉 // string ChangeForkCell = ccf.IfLimitCellChangeFork(minMidx, devinfo.DeviceIndex); // if (ChangeForkCell != "-")//主任务需要倒换货叉 // { // ccf.ChangeEndCellCode(minMidx, ChangeForkCell, devinfo.DeviceIndex); // } // #endregion //} //else //{//有关联站台 // #region 双叉对等站台的单任务在此等待关联,双叉极限货位不关联 // if ((CStaticClass.GetDevicePhotoelectric(DevLanewayIOInfo[3]) == 1) && (CStaticClass.GetDevicePhotoelectric(DevLanewayIOInfo[1]) == 1))//有货,顶升高位 // { // #region 顶升高位有货 // bool isend; // return GetCorrManageTask(DevLanewayIOInfo, TaskIdx, CONTROLTASKTYPE, mti, fid, dtime,out isend); // #endregion // } // else // { // CommonClassLib.CCarryConvert.WriteDarkCasket("单叉执行原因", minMidx.ToString(), devinfo.DeviceIndex.ToString(), "顶升高位和有物信号不满足条件"); // } // #endregion //} #endregion } else { #region 有关联任务信息 #region 判断是否还有可关联的关联站台任务20120906 //bool isend; //GetCorrManageTask(DevLanewayIOInfo, TaskIdx, CONTROLTASKTYPE, mti, fid, dtime,out isend); //if (isend == false) return false; #endregion foreach (int CorrTaskindex in corrinfo.Keys) { #region 双叉任务在此验证,是否为双叉极限货位,双极限货位使用双叉倒库货位修改任务 //把倒库货位作为取货和送货动作的目标货位,增加取货和送货动作对于倒库货位的逻辑有物的提前检测 //报告倒库货位完成时,追加倒库货位---》需要换叉的极限货位的取货和送货任务 #region 检查关联任务 string ChangeForkCell1 = ccf.IfLimitCellChangeFork(CorrTaskindex, devinfo.DeviceIndex); #endregion if (ChangeForkCell1 != "-") //关联任务需要倒换货叉 { ccf.ChangeEndCellCode(CorrTaskindex, ChangeForkCell1, devinfo.DeviceIndex); return false;//20140423richard如果不返回false,还会使用原来的坐标继续发送 } #endregion } #endregion } } #endregion #region 双叉AGV的入库取货任务在此判断是否关联双叉、验证双叉任务是否为双叉极限货位 if ((devinfo.DeviceKind == 6) && (devinfo.IfCorrelDoubleFork == "1") && (ccf.GetDeviceOrderFromMonitor(minMidx) == 2) && ((CONTROLTASKTYPE == 1) || (CONTROLTASKTYPE == 4))) { Dictionary corrinfo = Model.CGeneralFunction.GetDoubleForkMonitorInfo(minMidx, devinfo.DeviceIndex); if (corrinfo == null) { #region 双叉对等站台的单任务在此等待关联,双叉极限货位不关联 if (GetIOControlStatus(TaskIdx) != Model.CGeneralFunction.TASKSINGLEFORKRUN) {//没强制单叉执行 //查找关联站台 int agvCorrel = GetAGVCorrelIndex(TaskIdx); if (agvCorrel != -1) { //查找本地管理任务做多叉关联配对,关联任务分配货叉 int mfid = GetAGVEnableDoubleForkManageTask(CONTROLTASKTYPE, agvCorrel, devinfo.DeviceIndex); if (mfid > 0) { #region 双叉同为前极限后者后极限不关联,单独执行 if ((IfInSameLimitX(fid, mfid, mti) == true) && (mti == 1)) { sql.Remove(0, sql.Length); sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(fid).Append(")"); dboM.ExecuteSql(sql.ToString()); sql.Remove(0, sql.Length); sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(mfid).Append(")"); dboM.ExecuteSql(sql.ToString()); return true; } #endregion sql.Remove(0, sql.Length); sql.Append("update T_Manage_Task set F_RELATIVECONTORLID=").Append(mfid).Append(" where F_ManageTaskKindIndex=").Append(mti).Append(" and FID=").Append(fid); dbo.ExecuteSql(sql.ToString()); sql.Remove(0, sql.Length); sql.Append("update T_Manage_Task set F_RELATIVECONTORLID=").Append(fid).Append(" where F_ManageTaskKindIndex=").Append(mti).Append(" and FID=").Append(mfid); dbo.ExecuteSql(sql.ToString()); return true; } else { //20110505 AheadDetectUnallow.Append("双叉AGV在双叉校表站台取货" + ",等待多叉关联站台" + agvCorrel.ToString() + "的任务!"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } else return true; } else {//管理强制执行单叉任务 return true; } #endregion } } #endregion #region 双叉AGV的出库口输送机取货任务在此判断是否关联双叉20110412 if ((devinfo.DeviceKind == 6) && (devinfo.IfCorrelDoubleFork == "1") && ((ccf.GetDeviceOrderFromMonitor(minMidx) == 2) || (ccf.GetDeviceOrderFromMonitor(minMidx) == 4)) && (CONTROLTASKTYPE == 2)) { Dictionary corrinfo = Model.CGeneralFunction.GetDoubleForkMonitorInfo(minMidx, devinfo.DeviceIndex); if (corrinfo == null) { #region 双叉对等站台的单任务在此等待关联,双叉极限货位不关联 if (GetIOControlStatus(TaskIdx) != Model.CGeneralFunction.TASKSINGLEFORKRUN)//20110429测试应该为GetIOControlStatus(TaskIdx)!= {//没强制单叉执行 //查找关联站台 int agvCorrel = GetAGVCorrelConveyorIndex(TaskIdx); if (agvCorrel != -1) { #region 查找队列中是否有agvCorrel的任务:如果没有,不再等待,单叉执行; if (GetAGVEnableDoubleForkManageTask(2, agvCorrel, devinfo.DeviceIndex) <= 0)//没有能关联的任务,不再等待,单叉执行 { sql.Remove(0, sql.Length); sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(fid).Append(")"); dboM.ExecuteSql(sql.ToString()); return true; } #endregion #region 20110412有能关联的任务,判断agvCorrel是否有物而且任务已经到取货状态 int[] cstates = CStaticClass.GetDeviceState(agvCorrel); int cssstate = -1; if (cstates != null) { cssstate = cstates[1]; } if ((cssstate != 0) || (CStaticClass.GetDevicePhotoelectric(agvCorrel - 2, 0) != 1) || (CStaticClass.GetDevicePhotoelectric(agvCorrel, 2) != 1))//20110412顶升机空闲、有货、低位 { //20110505 AheadDetectUnallow.Append("双叉AGV在双叉校表站台取货" + ",等待多叉关联站台" + agvCorrel.ToString() + "的任务!"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } #endregion //查找本地管理任务做双叉在输送机取货任务关联配对,关联任务分配货叉 int mfid = GetAGVFromConveyorDoubleForkGetGoodManageTask(2, agvCorrel, devinfo.DeviceIndex); if (mfid > 0) { #region 终点不相同,单叉分别执行 if (IFHaveSameEndDevice(fid, mfid, mti) == false) { sql.Remove(0, sql.Length); sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(fid).Append(")"); dboM.ExecuteSql(sql.ToString()); sql.Remove(0, sql.Length); sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(mfid).Append(")"); dboM.ExecuteSql(sql.ToString()); return true; } #endregion #region 双叉同为前极限后者后极限不关联,单独执行 //if ((IfInSameLimitX(fid, mfid, mti) == true) && (mti == 1)) //{ // sql.Remove(0, sql.Length); // sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(fid).Append(")"); // dboM.ExecuteSql(sql.ToString()); // sql.Remove(0, sql.Length); // sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(mfid).Append(")"); // dboM.ExecuteSql(sql.ToString()); // return true; //} #endregion sql.Remove(0, sql.Length); sql.Append("update T_Manage_Task set F_RELATIVECONTORLID=").Append(mfid).Append(" where F_ManageTaskKindIndex=").Append(mti).Append(" and FID=").Append(fid); dbo.ExecuteSql(sql.ToString()); sql.Remove(0, sql.Length); sql.Append("update T_Manage_Task set F_RELATIVECONTORLID=").Append(fid).Append(" where F_ManageTaskKindIndex=").Append(mti).Append(" and FID=").Append(mfid); dbo.ExecuteSql(sql.ToString()); return true; } else { //20110505 AheadDetectUnallow.Append("双叉AGV在输送机取货" + ",没找到多叉关联任务,关联站台" + agvCorrel.ToString() + "有异常物体遮挡开关!"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } else return true; } else {//管理强制执行单叉任务 return true; } #endregion } } #endregion #region 机械手码垛任务 条件检测 yy add if (DeviceKind == 17) { sql.Clear(); //终点位置是否满垛 sql.Append($" select Device from ZH_pallet where GOODS_COUNT = 1 and Device = {EndDevice} "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { AheadDetectUnallow.Append("放货站台" + EndDevice + "以满垛,等待送出;"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } //判断机械手起点或终点状态 //是否存,租盘已满等待离开的任务,是否存在供给空托盘任务 int tempDevice = StartDevice == 12041 ? 12015 : 12016; sql.Clear(); sql.Append($" select F_ManageTaskIndex from T_Monitor_Task where F_NumParam1 = {tempDevice} and F_NumParam4 = {EndDevice} and F_MonitorIndex !={minMidx} "); //判断相同终点是否存在拆盘任务 dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { AheadDetectUnallow.Append("放货站台" + EndDevice + "存在供给空托盘任务,等待拆盘完成;"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } Model.MDevice tempDevinfo = Model.CGetInfo.GetDeviceInfo(EndDevice);//放货站台 if (tempDevinfo.RunState != 0) { AheadDetectUnallow.Append("放货站台" + EndDevice + "不空闲。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } if (new int[] { 12015, 12016 }.Contains(StartDevice) && tempDevinfo.SplitByte_0 == 1) { AheadDetectUnallow.Append("拆托盘任务放货站台" + EndDevice + "有货。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } sql.Clear(); sql.Append($" select F_ManageTaskIndex from T_Monitor_Task where F_DeviceIndex = {DeviceIdx} and F_Status > 0 "); //判断相同终点是否存在拆盘任务 dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { AheadDetectUnallow.Append("机械手" + DeviceIdx + "存在执行中的任务;"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } Model.MDevice AGVDevinfo = Model.CGetInfo.GetDeviceInfo(DeviceIdx);//放货站台 if (AGVDevinfo.RunState > 0) { AheadDetectUnallow.Append("机械手" + DeviceIdx + "非空闲;"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } sql.Clear(); //终点位置是否存在重复条码信息 sql.Append($" select * from ZH_pallet where Device = {EndDevice} "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { List code = dv[0]["SN"].ToString().Split(',').ToList(); if (code.Count != code.Distinct().Count()) { string repeatCode = ""; foreach (var item in code) { if (code.Contains(item)) { repeatCode = item; break; } } AheadDetectUnallow.Append("放货站台" + EndDevice + "存在重复条码 " + repeatCode); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } } #endregion #region 出库限制,未发送AGV 任务则出库,已发送,先入后出 yy add if (mti != 4 && DeviceKind == 1 && order == 4) { sql.Clear(); sql.Clear(); sql.Append($" select * from T_Manage_Task where FID = {fid} "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0 && Convert.ToInt32(dv[0]["FCONTROLTASKTYPE"]) != 3) { //获取主任务的 终到位 string tempFENDDEVICE = dv[0]["FENDDEVICE"].ToString(); //获取主任务的 执行巷道 string tempFSTARTDEVICE = dv[0]["FSTARTDEVICE"].ToString(); //根据终到位获取执行设备 dvdv = dbo.ExceSQL($" select F_LaneGateDeviceIndex from T_Base_Lane_Gate where F_ZXY like '%{tempFENDDEVICE.Substring(0, 1).PadLeft(2, '0')}' and F_LaneIndex = '{tempFSTARTDEVICE}'").Tables[0].DefaultView; if (dvdv.Count > 0) { int F_LaneGateDeviceIndex = Convert.ToInt32(dvdv[0]["F_LaneGateDeviceIndex"]); int[] arr = new int[] { };//第一位放货位,第二位传输线终到位 switch (F_LaneGateDeviceIndex) { case 12001: arr = new int[] { 12001, 12002 }; break; case 12003: arr = new int[] { 12003, 12004 }; break; case 22001: arr = new int[] { 22001, 22002 }; break; case 22003: arr = new int[] { 22003, 22004 }; break; case 32002: arr = new int[] { 32002, 32001 }; if (_AheadDetect.Contains("32004")) { string NewAheadDetect = _AheadDetect + ";D32003.0;I32003;I32003;D32003.0"; sql.Clear(); sql.AppendLine($" update T_Monitor_Task set F_AheadDetect ='{NewAheadDetect}' where F_ManageTaskIndex = {fid} and F_MonitorIndex = {TaskIdx} ;"); dbo.ExecuteSql(sql.ToString()); } break; } Model.MDevice tempDevinfo = Model.CGetInfo.GetDeviceInfo(arr[1]);//放货站台 if (tempDevinfo.RunState != 0 || tempDevinfo.SplitByte_0 == 1) { AheadDetectUnallow.Append("放货站台" + F_LaneGateDeviceIndex + "上有物或不空闲。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } //一楼避免回库堵掉入库通道判断 if (new int[] { 19002, 19003 }.Contains(Convert.ToInt32(tempFENDDEVICE))) { tempDevinfo = Model.CGetInfo.GetDeviceInfo(Convert.ToInt32(tempFENDDEVICE));//放货站台 if (tempDevinfo.SplitByte_0 == 1) { AheadDetectUnallow.Append("放货站台" + tempFENDDEVICE + "上有物或不空闲。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } else { sql.Clear(); sql.Append($" select * from T_Manage_Task where FSTATUS > 0 and FCONTROLTASKTYPE = 2 and FID !={fid} and FENDDEVICE={Convert.ToInt32(tempFENDDEVICE)} "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; sql.Clear(); sql.Append($" select * from T_Base_TaskCount where F_EXECUTIONCOUNT > 0 and F_DeviceIndex = {EndDevice} "); dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; int EXECUTIONCOUNT01 = dvdv.Count > 0 ? Convert.ToInt32(dvdv[0]["F_EXECUTIONCOUNT"]) : 0; EXECUTIONCOUNT01 = EXECUTIONCOUNT01 > 0 ? EXECUTIONCOUNT01 - 1 : 0; if (dv.Count > EXECUTIONCOUNT01) { AheadDetectUnallow.Append("放货站台" + tempFENDDEVICE + "上有出库任务正在执行。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } } dvdv = dbo.ExceSQL($" select * from T_Monitor_Task where F_Status > 0 and F_NumParam5 in ({string.Join(",", arr)})").Tables[0].DefaultView; if (dvdv.Count > 0) { AheadDetectUnallow.Append("出库站台" + arr[1] + ",存在未完成的AGV放货。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } dvdv = dbo.ExceSQL($" select * from T_Manage_Task where FSTATUS > 0 and FENDDEVICE in ({string.Join(",", arr)})").Tables[0].DefaultView; if (dvdv.Count > 0) { AheadDetectUnallow.Append("出库站台" + arr[1] + ",存在未完成" + dvdv[0]["FID"] + "的调度任务。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } //Model.MDevice tempDevinfo = Model.CGetInfo.GetDeviceInfo(next_NumParam1);//放货站台 //if (tempDevinfo.RunState != 0 || tempDevinfo.SplitByte_0 == 1) //{ // AheadDetectUnallow.Append("放货站台" + next_NumParam1 + "上有物。"); // UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); // return false; //} } } if (EndDevice == 39003) { sql.Clear(); sql.Append($" select * from T_Manage_Task where FSTATUS > 0 and FSTARTDEVICE = 39003 "); //判断相同终点是否存在拆盘任务 dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { AheadDetectUnallow.Append("存在 39003 站台回库任务。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } if (CStaticClass.GetDevicePhotoelectric(39003, 0) > 0) { AheadDetectUnallow.Append("放货站台39003有货。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } //控制 终点 为29008 的任务数。 if (EndDevice == 29008) { dv = dbo.ExceSQL("SELECT * FROM T_Base_Device where F_DeviceIndex = 29008").Tables[0].DefaultView; if (dv.Count > 0) { string[] trayList = dv[0]["F_PALLETBARCODE"].ToString().Trim() == "-" ? new string[] { } : dv[0]["F_PALLETBARCODE"].ToString().Split(','); trayList = trayList.Distinct().Where(c => !string.IsNullOrEmpty(c)).ToArray(); dv = dbo.ExceSQL($"select * from T_Manage_Task where FSTATUS > 0 and FENDDEVICE = 29008 and FID != {fid}").Tables[0].DefaultView; sql.Clear(); sql.Append($" select * from T_Base_TaskCount where F_EXECUTIONCOUNT > 0 and F_DeviceIndex = {EndDevice} "); dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dvdv.Count > 0) { int taskNum = Convert.ToInt32(dvdv[0]["F_EXECUTIONCOUNT"]); if ((trayList.Length + dv.Count) >= taskNum) { AheadDetectUnallow.Append("29008自动传输线任务,数量累计大于等于可执行任务数量 " + taskNum); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } } } } #endregion #region AGV 站台可发送任务数量 if (mti != 4) { sql.Clear(); sql.Append($" select distinct FID from T_Manage_Task where FSTATUS > 0 and FENDDEVICE = {EndDevice} and FID != { fid} "); EXECUTIONCOUNT = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView.Count; sql.Clear(); sql.Append($" select * from T_Base_TaskCount where F_EXECUTIONCOUNT > 0 and F_DeviceIndex = {EndDevice} "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { if (EXECUTIONCOUNT >= Convert.ToInt32(dv[0]["F_EXECUTIONCOUNT"])) { AheadDetectUnallow.Append("终点站台" + EndDevice + "存在" + EXECUTIONCOUNT + "条未完成任务,等待执行完成;"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } //当放货点任务数为 1 时,验证站台是否有货 if (Convert.ToInt32(dv[0]["F_EXECUTIONCOUNT"]) == 1) { int[] arr = new int[] { EndDevice };//第一位放货位,第二位传输线终到位 switch (EndDevice) { case 12001: case 12002: arr = new int[] { 12001, 12002 }; break; case 12003: case 12004: arr = new int[] { 12003, 12004 }; break; case 22001: case 22002: arr = new int[] { 22001, 22002 }; break; case 22003: case 22004: arr = new int[] { 22003, 22004 }; break; case 32002: arr = new int[] { 32001, 32002, 32003, 32004 }; break; default: arr = new int[] { EndDevice }; break; } //AGV任务 起点终点不在当前数组中则为传输线回退/正转 if (!arr.Contains(StartDevice) && !arr.Contains(EndDevice)) { for (int i = 0; i < arr.Length; i++) { Model.MDevice tempDevinfo = Model.CGetInfo.GetDeviceInfo(arr[i]);//放货站台 if (tempDevinfo.DeviceKind == 9) { if (tempDevinfo.SplitByte_0 == 1) { AheadDetectUnallow.Append("放货站台" + arr[i] + "上有物。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } else { if (tempDevinfo.RunState != 0 || tempDevinfo.SplitByte_0 == 1) { AheadDetectUnallow.Append("放货站台" + arr[i] + "上有物或不空闲。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } } } } } } #endregion #region AGV 任务限制 放货终点存在其它以发送的垛机任务则不发送当前AGV 任务 yy add //3楼站台只能有一个正在执行的任务启动 if (new int[] { 15001, 35001 }.Contains(DeviceIdx)) { sql.Clear(); sql.Append($" select * from T_Monitor_Task where F_MonitorIndex ={minMidx} "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; int tempDevice = Convert.ToInt32(dv[0]["F_NumParam5"]); sql.Clear(); sql.Append($" select * from T_Manage_Task where FSTATUS > 0 and FCONTROLTASKTYPE = 2 and FID != {fid} and FID in ( select distinct F_ManageTaskIndex from T_Monitor_Task where (F_NumParam1 = {tempDevice} or F_NumParam2 = {tempDevice} or F_NumParam4 = {tempDevice} or F_NumParam5 = {tempDevice} ) ) "); //判断相同终点是否存在拆盘任务 dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { //AheadDetectUnallow.Append("AGV当前任务放货站台" + EndDevice + "存在执行中的任务;"); //UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); //return false; if (dv.Count == 1) { sql.Clear(); sql.Append($" select * from AGV_TASK where FID in ({dv[0]["FID"]}) and AGV_TASK_STATUS < 2 "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; //AGV 取货完成是否大于 要执行数 if (dv.Count > 0) { AheadDetectUnallow.Append("AGV当前任务放货站台" + EndDevice + "存在未取货的任务;"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); //则不给AGV发任务 return false; } } else { AheadDetectUnallow.Append("AGV当前任务放货站台" + EndDevice + "存在执行中的任务;"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } //if (DeviceIdx == 15001) if (DeviceIdx == 15001 && ccf.GetDeviceKindIdx(tempDevice) == 2) { //if (CStaticClass.GetDevicePhotoelectric(tempDevice, 0) > 0) //{ // AheadDetectUnallow.Append("放货站台" + tempDevice + "有货。"); // UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); // return false; //} sql.Clear(); sql.Append($" select * from T_Manage_Task where FCONTROLTASKTYPE = 2 and FID != {fid} and FID in ( select distinct F_ManageTaskIndex from T_Monitor_Task where (F_NumParam1 = {tempDevice} or F_NumParam2 = {tempDevice} or F_NumParam4 = {tempDevice} or F_NumParam5 = {tempDevice} ) ) "); //判断相同终点是否存在拆盘任务 dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { AheadDetectUnallow.Append("AGV当前任务放货站台" + EndDevice + "存在出库的任务;"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } if (StartDevice == 39003) { sql.Clear(); sql.Append($" select * from T_Manage_Task where FSTATUS > 0 and FENDDEVICE = 39003 "); //判断相同终点是否存在拆盘任务 dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { AheadDetectUnallow.Append("39003站台,存在执行中任务。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } } //1楼站台和二楼站台 只要AGV接到任务并且取货完成则可以下发同站台的入库任务 if (new int[] { 25001 }.Contains(DeviceIdx) && EndDevice != 22006) { sql.Clear(); sql.Append($" select * from T_Monitor_Task where F_MonitorIndex ={minMidx} "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; int tempDevice = Convert.ToInt32(dv[0]["F_NumParam5"]); sql.Clear(); sql.Append($"select fid from T_Manage_Task where FSTATUS > 0 and FCONTROLTASKTYPE = 2 and FID in ( select distinct F_ManageTaskIndex from T_Monitor_Task where (F_NumParam1 = {tempDevice} or F_NumParam2 = {tempDevice} or F_NumParam4 = {tempDevice} or F_NumParam5 = {tempDevice} ) )"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; //如果有正在执行的同站台出库任务 if (dv.Count > 0) { List arr = new List(); for (int i = 0; i < dv.Count; i++) { arr.Add(Convert.ToInt32(dv[i]["FID"])); } sql.Clear(); sql.Append($" select * from AGV_TASK where FID in ({ string.Join(",", arr)}) and AGV_TASK_STATUS < 2 "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; //AGV 取货完成是否大于 要执行数 if (dv.Count > 0) { if (dv.Count < arr.Count) { AheadDetectUnallow.Append("AGV当前任务放货站台" + tempDevice + "存在执行中的任务;"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); //则不给AGV发任务 return false; } } //sql.Clear(); //sql.Append($" select * from AGV_TASK where FID ={Convert.ToInt32(dv[0]["FID"])}"); //dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; ////并且AGV任务没有取货完成 //if (dv.Count > 0) //{ // if (Convert.ToInt32(dv[0]["AGV_TASK_STATUS"]) < 3) // { // AheadDetectUnallow.Append("AGV当前任务放货站台" + EndDevice + "存在执行中的任务;"); // UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); // //则不给AGV发任务 // return false; // } //} } } #endregion #region AGV起点任务,存在未取货任务则不在继续发送AGV站台取货任务 if (DeviceKind == 6) { sql.Clear(); sql.Append($" select F_ManageTaskIndex from T_Monitor_Task where F_NumParam2 = {StartDevice} and F_Status > 0 "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { sql.Clear(); sql.Append($"select * from AGV_TASK where AGV_TASK_STATUS >= 3 and FID in (select F_ManageTaskIndex from T_Monitor_Task where F_NumParam2 = {StartDevice} and F_Status > 0 ) "); dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dvdv.Count <= 0) { AheadDetectUnallow.Append("取货站台" + StartDevice + "存在取货未完成的任务 " + dv[dv.Count - 1]["F_ManageTaskIndex"] + "。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } if (dv.Count != dvdv.Count) { AheadDetectUnallow.Append("取货站台" + StartDevice + "存在取货未完成的任务 " + dv[dv.Count - 1]["F_ManageTaskIndex"] + "。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } } #endregion #region 12021-12024 条码验证 垛机入库条码验证 if (mti == 1 && StartDevice == 12024) { sql.Clear(); sql.Append($" select * from T_Base_PLC_Ask where F_BindingDevice = 12024 "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { //F_TxtParam if (dv[0]["F_BarCode"].ToString().Trim() != barcode) { AheadDetectUnallow.Append("12024传输线任务条码与16001扫码不一致;"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } } //调度任务、入库、垛机取货 判断 条码扫描器 if (mti == 1 && CONTROLTASKTYPE == 1 && DeviceKind == 1 && order == 4) { sql.Clear(); sql.Append($" select * from T_Base_PLC_Ask where F_BindingDevice = {StartDevice} "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { //F_TxtParam if (dv[0]["F_BarCode"].ToString().Trim() != barcode) { AheadDetectUnallow.Append(StartDevice + " 传输线任务条码与条码扫码不一致;"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } } #endregion #region 验证出库是否顺序执行 WMS_TASKTYPE if (mti != 4 && DeviceKind == 1 && order == 4) { sql.Clear(); sql.Append($" select * from T_Manage_Task where FENDDEVICE = {EndDevice} and WMS_TASKTYPE > (select distinct max( COALESCE( WMS_TASKTYPE,0)) as WMS_TASKTYPE from T_Manage_Task where FID = {fid})"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { AheadDetectUnallow.Append("终点站台" + EndDevice + "存在高顺序执行" + dv[0]["WMS_TASKTYPE"] + "未完成任务;"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } #endregion #region 叠盘机 出入任务条件检测 if (new int[] { 22005 }.Contains(StartDevice) && EndDevice == 22006) { sql.Clear(); sql.Append($" select * from T_Manage_Task where FENDDEVICE = 22006 and FSTARTDEVICE not in(22007,22005) and FSTATUS > 0 "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { AheadDetectUnallow.Append("放货站台" + EndDevice + "存在执行中的任务;"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } if (CStaticClass.GetDevicePhotoelectric(22006, 0) > 0) { AheadDetectUnallow.Append("放货站台22006有货。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } if (StartDevice != 22005 && EndDevice == 22006) { sql.Clear(); sql.Append($" select * from T_Manage_Task where FENDDEVICE = 22006 and FSTARTDEVICE in(22005)"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { AheadDetectUnallow.Append("22006站台存在满垛任务的任务;"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } if (StartDevice == 22006 && EndDevice != 22005) { sql.Clear(); sql.Append($" select * from T_Monitor_Task where F_MonitorIndex ={minMidx} and F_NumParam2 = 22006 "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { int deviceTemp = Convert.ToInt32(dv[0]["F_NumParam5"]); if (CStaticClass.GetDevicePhotoelectric(deviceTemp, 0) > 0 || CStaticClass.GetDeviceState(deviceTemp)[1] > 0) { //AGV任务验证站台是否有货 AheadDetectUnallow.Append("放货站台" + deviceTemp + "有货。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } if (CStaticClass.GetDevicePhotoelectric(EndDevice, 0) > 0 || CStaticClass.GetDeviceState(EndDevice)[1] > 0) { //AGV任务验证站台是否有货 AheadDetectUnallow.Append("放货站台" + EndDevice + "有货。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } } #endregion #region 叠盘机 任务计数 if (new int[] { 22007, 22006, 22005 }.Contains(StartDevice) == false && (EndDevice == 22006 || EndDevice == 29007)) { sql.Clear(); sql.Append($" select * from T_Monitor_Task where F_NumParam1 = 22006 or F_NumParam2 = 22006 "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { //if (dv[0]["F_NumParam5"].ToString() == "22005") //{ AheadDetectUnallow.Append("起点22006或终点22005存在未完成的任务。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; //} //sql.Clear(); //sql.Append($" select * from AGV_TASK where FID in ({dv[0]["F_ManageTaskIndex"]}) and AGV_TASK_STATUS < 2 "); //dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; ////AGV 取货完成是否大于 要执行数 //if (dv.Count > 0) //{ // AheadDetectUnallow.Append("AGV当前任务放货站台" + EndDevice + "存在未取货的任务;"); // UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); // //则不给AGV发任务 // return false; //} } if (CStaticClass.GetDevicePhotoelectric(22006, 0) > 0) { if (mti != 4 && DeviceKind == 1 && order == 4) { //AGV任务验证站台是否有货 AheadDetectUnallow.Append("放货站台22006有货。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } Model.MDevice tempDevinfo = Model.CGetInfo.GetDeviceInfo(29001);//叠盘机 if (tempDevinfo.RunState != 0) { AheadDetectUnallow.Append("叠盘机非空闲。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } Model.MDevice tempDevinfo22005 = Model.CGetInfo.GetDeviceInfo(22005);//叠盘机下传输线 sql.Clear(); sql.Append($" select * from T_Manage_Task where FENDDEVICE in( 22006,29007) and FSTATUS > 0"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count == 0) { //当没有已发送到 22006 的任务时 清空 22006 即将到达信息 dbo.ExceSQL($"update T_Base_Device set F_PALLETBARCODE = '' where F_DeviceIndex = 22006 "); } sql.Clear(); sql.Append($" select * from T_Manage_Task where FSTARTDEVICE = 22005 and FENDDEVICE = 22006 "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; //没有 22005 的任务,并且 碟盘机空闲,22005传输线空闲无货,22006传输线空闲无货,没有起点 if (dv.Count == 0 && tempDevinfo.RunState == 0 && tempDevinfo22005.RunState == 0 && tempDevinfo22005.SplitByte_0 == 0 && CStaticClass.GetDevicePhotoelectric(22006, 0) == 0) { dbo.ExceSQL($"update T_Base_Device set F_PALLETBARCODE = '' where F_DeviceIndex = 22005 "); } sql.Clear(); sql.Append($" select * from T_Manage_Task where FID = {fid} "); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (Convert.ToInt32(dv[0]["FSTATUS"]) == 0) { dvdv = dbo.ExceSQL("select F_PALLETBARCODE from T_Base_Device where F_DeviceIndex = 22005").Tables[0].DefaultView; string[] tray22005 = dvdv[0]["F_PALLETBARCODE"].ToString().Split(','); dvdv = dbo.ExceSQL("select F_PALLETBARCODE from T_Base_Device where F_DeviceIndex = 22006").Tables[0].DefaultView; string[] tray22006 = dvdv[0]["F_PALLETBARCODE"].ToString().Split(','); string[] tempArr = tray22005.Union(tray22006).Where(c => !string.IsNullOrEmpty(c)).ToArray(); //传输线 22005 和 22006 记录托盘小于 4 则可发送进叠盘机任务 if (tempArr.Length < 4) { string[] newTray = dv[0]["FPALLETBARCODE"].ToString().Split(','); if ((tempArr.Length + newTray.Length) <= 4) { string[] arrTray = tray22006.Union(newTray).Distinct().Where(c => !string.IsNullOrEmpty(c)).ToArray(); //记录即将到达22006 的托盘号 dbo.ExceSQL($"update T_Base_Device set F_PALLETBARCODE = '{string.Join(",", arrTray)}' where F_DeviceIndex = 22006 "); } else { //当前任务托盘数组,大于1 if (newTray.Length > 1) { sql.Clear(); sql.Append($" select * from T_Manage_Task where FSTATUS > 0 and FENDDEVICE = 22006 "); dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dvdv.Count <= 0) { if ((tempArr.Length + newTray.Length) <= 6) { string[] arrTray = tray22006.Union(newTray).Distinct().Where(c => !string.IsNullOrEmpty(c)).ToArray(); //记录即将到达22006 的托盘号 dbo.ExceSQL($"update T_Base_Device set F_PALLETBARCODE = '{string.Join(",", arrTray)}' where F_DeviceIndex = 22006 "); } } else { AheadDetectUnallow.Append("预存托盘数与当前任务累计大于4个,等待上一任务执行完成。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } else { AheadDetectUnallow.Append("预存托盘数与当前任务累计大于4个,等待上一任务执行完成。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } sql.Clear(); sql.Append($" select * from T_Manage_Task where FSTARTDEVICE in(22005,22006,22007)"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { AheadDetectUnallow.Append("叠盘机存在相关出叠盘机任务。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } if (CStaticClass.GetDevicePhotoelectric(22006, 0) > 0) { //AGV任务验证站台是否有货 AheadDetectUnallow.Append("放货站台22006有货。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } else { AheadDetectUnallow.Append("叠盘机预存托盘数大于等于4个托盘,等待叠盘入库。"); UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx); return false; } } } #endregion return true; } catch (Exception ex) { RefreshMonitorEventArgs rme = new RefreshMonitorEventArgs("tsStatus", "发送指令提前检测时发生错误:" + ex.StackTrace + ex.Message); OnRefreshMonitor(rme); return false; } finally { dv.Dispose(); dvdv.Dispose(); } } private bool IFExitTopPriDeviceIdxTaskWait(int DeviceIdx) { sql.Clear(); DataView dv0 = new DataView(); DataView dv = new DataView(); try { sql.Append(string.Format("SELECT F_ManageTaskIndex, F_ManageTASKKINDINDEX FROM T_Monitor_Task WHERE (F_DeviceIndex = {0})", DeviceIdx)); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; for (int i = 0; i < dv.Count; i++) { sql.Clear(); sql.Append(string.Format("SELECT top 1 F_DeviceIndex,F_Status FROM T_Monitor_Task WHERE (F_ManageTASKKINDINDEX = {0}) and F_ManageTaskIndex={1} order by F_MonitorIndex asc", Convert.ToInt32(dv[i]["F_ManageTASKKINDINDEX"]), Convert.ToInt32(dv[i]["F_ManageTASKINDEX"]))); dv0 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv0.Count > 0) { if ((dv0[0]["F_DeviceIndex"].ToString() == DeviceIdx.ToString()) && (dv0[0]["F_Status"].ToString() == "0")) { return true; } } } return false; } catch (Exception ex) { throw ex; } finally { dv.Dispose(); dv0.Dispose(); } } private int GetBarcodeCoor(int xcoor, int zcoor) { DataView dv = new DataView(); try { dv = dbo.ExceSQL(string.Format("SELECT BarcodeCoor FROM T_Base_BarcodeCoor WHERE (XCoor = {0}) AND (ZCoor = {1})", xcoor, zcoor)).Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0][0]); } else { dv = dbo.ExceSQL(string.Format("SELECT BarcodeCoor FROM T_Base_BarcodeCoor WHERE (XCoor1 = {0}) AND (ZCoor1 = {1})", xcoor, zcoor)).Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0][0]); } else { return 0; } } } catch (Exception ex) { throw ex; } finally { dv.Dispose(); } } /// /// 获得发送信息 /// /// 设备指令索引 public bool GetSendInfo(int minMidx) { DataView dvD = new DataView(); try { sql.Remove(0, sql.Length); sql.Append("SELECT F_DeviceKindIndex,F_NumParam1,F_NumParam2,F_NumParam3,F_NumParam4,").Append( "F_NumParam5,F_NumParam6,F_TxtParam,F_AheadDetect,F_ManTaskReserve,F_LockedState,").Append( "F_Associate,F_SerialNumber,F_RouteID,F_DeviceIndex,F_DeviceCommandIndex,").Append( "F_MonitorIndex,F_ManageTaskIndex,F_ManageTaskKindIndex,F_OutsideAltDevice,").Append( "F_InsideAltDevice,F_StartDevice,F_EndDevice,F_RouteKind,F_UseAwayFork,F_AgvNo ").Append( " FROM V_Monitor_Route_Device where F_MonitorIndex=").Append(minMidx); dvD = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dvD.Count > 0) { if (dvD[0]["F_AheadDetect"] != DBNull.Value) { _AheadDetect = dvD[0]["F_AheadDetect"].ToString(); } else { _AheadDetect = ""; } if (dvD[0]["F_ManTaskReserve"] != DBNull.Value) { _ManTaskReserve = Convert.ToInt32(dvD[0]["F_ManTaskReserve"]); } else { _ManTaskReserve = 0; } if (dvD[0]["F_Associate"] != DBNull.Value) { _Associate = Convert.ToInt32(dvD[0]["F_Associate"]); } else { _Associate = 0; } if (dvD[0]["F_LockedState"] != DBNull.Value) { _LockedState = Convert.ToInt32(dvD[0]["F_LockedState"]); } else { _LockedState = 0; } if (dvD[0]["F_NumParam1"] != DBNull.Value) { _NumParam1 = Convert.ToInt32(dvD[0]["F_NumParam1"]); } else { _NumParam1 = 0; } if (dvD[0]["F_NumParam2"] != DBNull.Value) { _NumParam2 = Convert.ToInt32(dvD[0]["F_NumParam2"]); } else { _NumParam2 = 0; } if (dvD[0]["F_NumParam3"] != DBNull.Value) { _NumParam3 = Convert.ToInt32(dvD[0]["F_NumParam3"]); } else { _NumParam3 = 0; } if (dvD[0]["F_NumParam4"] != DBNull.Value) { _NumParam4 = Convert.ToInt32(dvD[0]["F_NumParam4"]); } else { _NumParam4 = 0; } if (dvD[0]["F_NumParam5"] != DBNull.Value) { _NumParam5 = Convert.ToInt32(dvD[0]["F_NumParam5"]); } else { _NumParam5 = 0; } if (dvD[0]["F_NumParam6"] != DBNull.Value) { _NumParam6 = Convert.ToInt32(dvD[0]["F_NumParam6"]); } else { _NumParam6 = 0; } if (dvD[0]["F_TxtParam"] != DBNull.Value) { _TxtParam = dvD[0]["F_TxtParam"].ToString(); } else { _TxtParam = "-"; } _serialNumber = Convert.ToInt32(dvD[0]["F_SerialNumber"]); _routeID = Convert.ToInt32(dvD[0]["F_RouteID"]); _DeviceIdx = Convert.ToInt32(dvD[0]["F_DeviceIndex"]); _DeviceOrder = Convert.ToInt32(dvD[0]["F_DeviceCommandIndex"]); _ManageKindIdx = Convert.ToInt32(dvD[0]["F_ManageTaskKindIndex"]); _ManageTaskIdx = Convert.ToInt32(dvD[0]["F_ManageTaskIndex"]); _DeviceKind = Convert.ToInt32(dvD[0]["F_DeviceKindIndex"]); if (dvD[0]["F_OutsideAltDevice"] != DBNull.Value) { _OutsideAltDevice = Convert.ToInt32(dvD[0]["F_OutsideAltDevice"]); } else { _OutsideAltDevice = 0; } if (dvD[0]["F_InsideAltDevice"] != DBNull.Value) { _InsideAltDevice = Convert.ToInt32(dvD[0]["F_InsideAltDevice"]); } else { _InsideAltDevice = 0; } _StartDevice = Convert.ToInt32(dvD[0]["F_StartDevice"]); _EndDevice = Convert.ToInt32(dvD[0]["F_EndDevice"]); _RouteKind = Convert.ToInt32(dvD[0]["F_RouteKind"]); if (dvD[0]["F_AgvNo"] != DBNull.Value) { _AgvNo = Convert.ToInt32(dvD[0]["F_AgvNo"]); } else { _AgvNo = 65535; } return true; } else {//20120420 CControlError = string.Format("发送命令调用GetSendInfo时:路径表里【{0}】设备索引不存在!", GetDeviceFromMonitor(minMidx).ToString()); return false; } } catch (Exception ex) { throw ex; } finally { dvD.Dispose(); } } /// /// 发送指定调度任务号的命令 /// /// /// public bool SendMonitorTask(int MonitorIndex) { try { lock (thisLock) { char[] sep = new char[1] { '-' }; int msgIdx = 0;//消息编号 bool sendok; #region 多叉关联设备指令,如果不能同步执行,发送距离堆垛机当前位置近的设备指令 MonitorIndex = GetDoubleForkMinRouteTask(MonitorIndex); if (MonitorIndex == -1) { return false; } #endregion //获得要发送的信息 if (GetSendInfo(MonitorIndex) == false) { return false; } int deviceIdx = _DeviceIdx; int deviceKind = _DeviceKind; int deviceOrder = _DeviceOrder; int manageKindIdx = ccf.GetManageTaskKindIndexFromMonitor(MonitorIndex); int manageTaskIdx = ccf.GetManageTaskIndexfromMonitor(MonitorIndex); int EndDevice = ccf.GetEndDeviceFromManage(manageKindIdx, manageTaskIdx); string Batch = dbo.GetSingle("select BATTERY_BATCH from t_manage_task where fid=" + manageTaskIdx).ToString(); int BatteryType = Convert.ToInt32(dbo.GetSingle("select BATTERY_TYPE from t_manage_task where fid=" + manageTaskIdx)); if (BatteryType == 18650) { BatteryType = 1; } if (BatteryType == 21700) { BatteryType = 2; } string barcode = ccf.GetBarCodeFromManageTask(manageTaskIdx, manageKindIdx); devinfo = Model.CGetInfo.GetDeviceInfo(deviceIdx); if (((deviceKind == 1 && (devinfo.YCoor == 0 && devinfo.XCoor == 0)) || (deviceKind == 4) && (devinfo.XCoor == 0) && (devinfo.YCoor == 0)) && (devinfo.VirtualStack != deviceIdx))//20130510 { AheadDetectUnallow.Clear(); AheadDetectUnallow.Append(_DeviceIdx.ToString() + "的光通讯被遮挡,或者没上电!"); UpdateAheadDetectUnallow(AheadDetectUnallow, MonitorIndex); return false; } if (ccf.GetManageTaskKindIndexFromMonitor(MonitorIndex) == 4) { #region 手工任务 string ah = "I" + deviceIdx.ToString(); if ((deviceKind != 1) && ((deviceKind != 4))) { ah = ""; } if (AheadDetectOK(MonitorIndex, ah) == false) //不符合运行条件ccf.GetBeDetectedDevices(_DeviceIdx)) { return false; } //CStaticClass.MessageIndex++; CStaticClass.MessageIndex = 1; msgIdx = (CStaticClass.MessageIndex); sdo = CommModeCreate.CreateSendDeviceOrder(deviceIdx); int[] gc = new int[6] { _NumParam2, _NumParam3, _NumParam1, _NumParam5, _NumParam6, _NumParam4 }; if ((deviceKind == 1)) { sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder, deviceIdx, gc[0], gc[1], gc[2], gc[3], gc[4], gc[5]); } else if (deviceKind == 6) { DataView dv = dbo.ExceSQL(string.Format("select * from T_Monitor_Task where F_DeviceCommandIndex = 2 and F_MonitorIndex={0}", MonitorIndex)).Tables[0].DefaultView; if (dv.Count > 0) { DataRowView drv = dv[0]; //string sbs = string.Format("INSERT INTO [dbo].[AGV_TASK]([FID],[AGV_TASK_LEVEL],[PALLET_BARCODE],[PALLET_TYPE],[START_DEVICE_CODE],[FINISH_DEVICE_CODE],[AGV_TASK_STATUS],[AGV_CODE],[INSERT_TIME])VALUES({0},{1},'','',{2},{3},0,0,{4})", drv["F_ManageTaskIndex"].ToString(), drv["F_MonitorTaskLevel"].ToString(), drv["F_NumParam2"].ToString(), drv["F_NumParam5"].ToString(), DateTime.Now.ToString("yyyyMMddHHmmss")); //int rc = dbo.ExecuteSql(sbs.ToString()); //TODO AGV 到垃圾站台任务 //添加AGV任务类型 终点为 29007 时,修改终到位 为22006 ,中间点29007,类型 为 3 1--正常点到点取送, 2--存在物料顺序的任务组取送任务, 3--废料任务 4....待定 StringBuilder sql = new StringBuilder(); sql.Append(" INSERT INTO AGV_TASK ("); sql.Append(" FID,AGV_TASK_LEVEL,PALLET_BARCODE,PALLET_TYPE,START_DEVICE_CODE"); sql.Append(" ,FINISH_DEVICE_CODE,AGV_TASK_STATUS,AGV_CODE,INSERT_TIME"); sql.Append(" ,TASKTYPE,MIDDLE"); sql.Append(" ) VALUES ( "); if (dv[0]["F_NumParam5"].ToString() == "29007") { sql.Append($" {drv["F_ManageTaskIndex"].ToString()},{drv["F_MonitorTaskLevel"].ToString()},'{drv["F_TxtParam"].ToString()}','',{ drv["F_NumParam2"].ToString()}"); sql.Append($" ,{22006},0,0,{DateTime.Now.ToString("yyyyMMddHHmmss")}"); sql.Append($" ,{3},{29007} "); } else { sql.Append($" {drv["F_ManageTaskIndex"].ToString()},{drv["F_MonitorTaskLevel"].ToString()},'{drv["F_TxtParam"].ToString()}','',{ drv["F_NumParam2"].ToString()}"); sql.Append($" ,{drv["F_NumParam5"].ToString()},0,0,{DateTime.Now.ToString("yyyyMMddHHmmss")}"); sql.Append($" ,1,'' "); } sql.Append(" ) "); int rc = dbo.ExecuteSql(sql.ToString()); if (rc == 0) { sendok = false; } else { sendok = true; } } else { sendok = false; } } else if (deviceKind == 4) { if (ccf.NeedOptimize(deviceIdx) == true) { ccf.InsertMonitorOptimizeChildTask(MonitorIndex); sendok = true; } else { sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder, deviceIdx, gc[2]); } } else { sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder, deviceIdx, gc[5]); } if (sendok == false) { if (sdo.CommLayerError != null) { RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", sdo.CommLayerError); OnRefreshMonitor(rmea); } return false; } else { ////////////////////////// ccf.SendOrderSuccess(manageKindIdx, manageTaskIdx, MonitorIndex, deviceIdx, _routeID); #region 多叉关联任务,能同步的同时报告发送命令成功 //20100323 devinfo = Model.CGetInfo.GetDeviceInfo(deviceIdx); if (devinfo.IfCorrelDoubleFork == "1") { int[] mforkMoninfo = Model.CGeneralFunction.MutiForkIfSync(MonitorIndex, deviceIdx, deviceKind); if (mforkMoninfo != null) { Dictionary corr = Model.CGeneralFunction.GetDoubleForkMonitorInfo(MonitorIndex, deviceIdx); for (int i = 0; i < mforkMoninfo.GetLength(0); i++) { ccf.SendOrderSuccess(ccf.GetManageTaskKindIndexFromMonitor(mforkMoninfo[i]), ccf.GetManageTaskIndexfromMonitor(mforkMoninfo[i]), mforkMoninfo[i], Convert.ToInt32(corr[mforkMoninfo[i]][2]), Convert.ToInt32(corr[mforkMoninfo[i]][3])); } } } #endregion return true; } #endregion } #region 自动命令(taskkind == 1,2) //(taskkind == 1,2)自动命令和临时管理管理命令 /////////////////////////////////////// //2--6应该做递归调用函数 /////////////////////////////////////// ///////////////////// //20100208 #region 环形穿梭车RGV分配车号修改提前检测 #endregion //////////////////// //2:提取每个管理单据的第一个设备状态 if (GetFirstDeviceIFLocked(MonitorIndex, true) == false)//没有被锁定,空闲 { devinfo = Model.CGetInfo.GetDeviceInfo(deviceIdx); //7:发送此设备命令 //CStaticClass.MessageIndex++; CStaticClass.MessageIndex = 1; msgIdx = (CStaticClass.MessageIndex); sdo = CommModeCreate.CreateSendDeviceOrder(deviceIdx); //判断设备是否为堆垛机RGV和AGV int[] gc = new int[6] { _NumParam2, _NumParam3, _NumParam1, _NumParam5, _NumParam6, _NumParam4 };//获得坐标 if (gc == null) { this.CControlError += string.Format("发送命令时不能取得设备坐标!"); return false; } if (deviceKind == 1) { //1:堆垛机;4:RGV;6:AGV如果需要优化调度(设备表的F_NeedOptimize='1') //直接写入表:T_Monitor_Task_Child,不发送命令 if (deviceOrder == 10)//堆垛机的人工观测指令不发送 { sendok = false; } if (ccf.NeedOptimize(deviceIdx) == true) { ccf.InsertMonitorOptimizeChildTask(MonitorIndex); sendok = true; } else { sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder, deviceIdx, gc[0], gc[1], gc[2], gc[3], gc[4], gc[5]); } #region 双向出入口任务避碰 //int enddev = Convert.ToInt32(dbo.GetSingle("select FENDDEVICE from T_Manage_Task where FID=" + manageTaskIdx)); //if (deviceOrder == 4 && (_NumParam5 == 1 && _NumParam6 == 1) ) //{ // //堆垛机取货指令,而且目的地址的列数为1(站台) // Model.MDevice devinfo_light = new Model.MDevice(); // switch (enddev) // { // case 12001: // devinfo_light = Model.CGetInfo.GetDeviceInfo(17001); // break; // case 12002: // devinfo_light = Model.CGetInfo.GetDeviceInfo(17002); // break; // case 12003: // devinfo_light = Model.CGetInfo.GetDeviceInfo(17003); // break; // case 12004: // devinfo_light = Model.CGetInfo.GetDeviceInfo(17004); // break; // } // StringBuilder[] wv = { new StringBuilder("2") }; // StringBuilder[] witemnames = { new StringBuilder("") }; // witemnames[0].Clear(); // witemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(devinfo_light.Dbw1Address + 0)).Append(",b");//20130510 // wv[0].Clear(); // wv[0].Append("0"); // sdo = CommModeCreate.CreateSendDeviceOrder(devinfo_light.DeviceIndex); // sdo.WriteDBData(witemnames, wv, devinfo_light.S7Connection); // CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "出入库模式", devinfo_light.DeviceIndex.ToString(), "存在执行中的出库任务!"); //} #endregion } else if (deviceKind == 6) { DataView dv = dbo.ExceSQL(string.Format("select * from T_Monitor_Task where F_DeviceCommandIndex = 4 and F_MonitorIndex={0}", MonitorIndex)).Tables[0].DefaultView; if (dv.Count > 0) { DataRowView drv = dv[0]; //string sbs; //sbs = string.Format("INSERT INTO [dbo].[AGV_TASK]([FID],[AGV_TASK_LEVEL],[PALLET_BARCODE],[PALLET_TYPE],[START_DEVICE_CODE],[FINISH_DEVICE_CODE],[AGV_TASK_STATUS],[AGV_CODE],[INSERT_TIME])VALUES({0},{1},'','',{2},{3},0,0,{4})", drv["F_ManageTaskIndex"].ToString(), drv["F_MonitorTaskLevel"].ToString(), drv["F_NumParam2"].ToString(), drv["F_NumParam5"].ToString(), DateTime.Now.ToString("yyyyMMddHHmmss")); //int rc = dbo.ExecuteSql(sbs.ToString()); //添加AGV任务类型 终点为 29007 时,修改终到位 为22006 ,中间点29007,类型 为 3 1--正常点到点取送, 2--存在物料顺序的任务组取送任务, 3--废料任务 4....待定 StringBuilder sql = new StringBuilder(); sql.Append(" INSERT INTO AGV_TASK ("); sql.Append(" FID,AGV_TASK_LEVEL,PALLET_BARCODE,PALLET_TYPE,START_DEVICE_CODE"); sql.Append(" ,FINISH_DEVICE_CODE,AGV_TASK_STATUS,AGV_CODE,INSERT_TIME"); sql.Append(" ,TASKTYPE,MIDDLE"); sql.Append(" ) VALUES ( "); if (dv[0]["F_NumParam5"].ToString() == "29007") { sql.Append($" {drv["F_ManageTaskIndex"].ToString()},{drv["F_MonitorTaskLevel"].ToString()},'{drv["F_TxtParam"].ToString()}','',{ drv["F_NumParam2"].ToString()}"); sql.Append($" ,{22006},0,0,{DateTime.Now.ToString("yyyyMMddHHmmss")}"); sql.Append($" ,{3},{29007} "); } else { sql.Append($" {drv["F_ManageTaskIndex"].ToString()},{drv["F_MonitorTaskLevel"].ToString()},'{drv["F_TxtParam"].ToString()}','',{ drv["F_NumParam2"].ToString()}"); sql.Append($" ,{drv["F_NumParam5"].ToString()},0,0,{DateTime.Now.ToString("yyyyMMddHHmmss")}"); sql.Append($" ,1,'' "); } sql.Append(" )"); int rc = dbo.ExecuteSql(sql.ToString()); if (rc == 0) { sendok = false; } else { sendok = true; } } else { sendok = false; } } else if (_DeviceKind == 4) { if (ccf.NeedOptimize(deviceIdx) == true) { ccf.InsertMonitorOptimizeChildTask(MonitorIndex); sendok = true; } else { sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder, deviceIdx, gc[2]); } } else if (_DeviceKind == 7) { int ControlType = ccf.GetFCONTROLTASKTYPEFromManageTask(_ManageKindIdx, _ManageTaskIdx); #region 条码设备直接比对 DataView dv = dbo.ExceSQL(string.Format("SELECT F_MonitorIndex FROM T_Base_PLC_Ask ,T_Monitor_Task WHERE T_Base_PLC_Ask.F_DeviceIndex = T_Monitor_Task.F_DeviceIndex AND T_Base_PLC_Ask.F_BarCode = T_Monitor_Task.F_TxtParam and (T_Monitor_Task.F_MonitorIndex = {0})", MonitorIndex)).Tables[0].DefaultView; if ((dv.Count > 0) || (ControlType != 1)) {//比对正确 object[] obj = new object[3] { _ManageKindIdx, _ManageTaskIdx, Model.CGeneralFunction.TASKABEND }; dbo.ExecuteSql(string.Format("UPDATE T_Manage_Task SET FExceptionNO=NULL WHERE (F_ManageTaskKindIndex ={0}) AND (FID ={1}) and FExceptionNO={2}", obj)); Model.CGeneralFunction.ActionComplete(deviceIdx, MonitorIndex, 0); } else {//比对错误,改道异常处理口 //修改目标位置至异常口 dv = dbo.ExceSQL(string.Format("SELECT F_Remark,F_BindingDevice,F_BarCode FROM T_Base_PLC_Ask WHERE T_Base_PLC_Ask.F_DeviceIndex = {0}", deviceIdx)).Tables[0].DefaultView; if (dv.Count > 0) { if ((CStaticClass.DeviceErrorAutoModifyRoutePath == "1") && (dv[0]["F_BarCode"].ToString() != "1111111")) { object[] obj = new object[5] { _ManageKindIdx, _ManageTaskIdx, Convert.ToInt32(dv[0]["F_Remark"]), Model.CGeneralFunction.TASKABEND, Convert.ToInt32(dv[0]["F_BindingDevice"]) }; dbo.ExecuteSql(string.Format("UPDATE T_Manage_Task SET FExceptionNO={3},FSTARTDEVICE ={4}, FSTARTCELL ='-',FENDDEVICE ={2}, FENDCELL ='-', FENDUCODE =0 WHERE (F_ManageTaskKindIndex ={0}) AND (FID ={1})", obj)); ccf.GetUseableRouteIDSubAndModifyRoute(_ManageTaskIdx, _ManageKindIdx, Convert.ToInt32(dv[0]["F_BindingDevice"])); } else { Model.MError me; if (dv[0]["F_BarCode"].ToString() == "-")//扫描器未读条码 { me = null; Model.CGeneralFunction.ActionComplete(deviceIdx, MonitorIndex, 0); //me = Model.CGetInfo.GetErrorInfo(732); //dbo.ExecuteSql(string.Format("update T_Monitor_Task set F_Status=32 WHERE (T_Monitor_Task.F_MonitorIndex = {0})", MonitorIndex)); } else if (dv[0]["F_BarCode"].ToString().IndexOf("1111111") >= 0) {//"1111111111"条码未读到 object[] obj = new object[3] { _ManageKindIdx, _ManageTaskIdx, Model.CGeneralFunction.TASKABEND }; dbo.ExecuteSql(string.Format("UPDATE T_Manage_Task SET FExceptionNO={2} WHERE (F_ManageTaskKindIndex ={0}) AND (FID ={1})", obj)); Model.CGeneralFunction.ActionComplete(deviceIdx, MonitorIndex, 0); //dbo.ExecuteSql(string.Format("update T_Monitor_Task set F_Status=30 WHERE (T_Monitor_Task.F_MonitorIndex = {0})", MonitorIndex)); me = Model.CGetInfo.GetErrorInfo(730); } else {//条码不正确 object[] obj = new object[3] { _ManageKindIdx, _ManageTaskIdx, Model.CGeneralFunction.TASKABEND }; dbo.ExecuteSql(string.Format("UPDATE T_Manage_Task SET FExceptionNO={2} WHERE (F_ManageTaskKindIndex ={0}) AND (FID ={1})", obj)); Model.CGeneralFunction.ActionComplete(deviceIdx, MonitorIndex, 0); // dbo.ExecuteSql(string.Format("update T_Monitor_Task set F_Status=31 WHERE (T_Monitor_Task.F_MonitorIndex = {0})", MonitorIndex)); me = Model.CGetInfo.GetErrorInfo(731); } if (me != null) { RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("notifyIcon1", "警告:" + devinfo.DeviceName + "," + deviceIdx + "发生故障:" + me.ErrorName); OnRefreshMonitor(rmea); } } if (_ManageKindIdx == 1) { sql.Remove(0, sql.Length); sql.Append("update IO_Control set ERROR_TEXT='").Append(devinfo.DeviceName).Append(",").Append(deviceIdx).Append("条码不正确!").Append("' where CONTROL_ID=").Append(manageTaskIdx); dboM.ExceSQL(sql.ToString()); } } } //20130709 dbo.ExecuteSql(string.Format("UPDATE T_Base_PLC_Ask SET F_BarCode = '-' WHERE (F_DeviceIndex = {0}) ", deviceIdx)); #endregion return true; } else if (_DeviceKind == 17) { if (deviceOrder == 4) { sendok = false; } else { string ng = Convert.ToString(dbo.GetSingle("select NG_BATTERY from t_manage_task where fid=" + manageTaskIdx)); string FENDDEVICE = Convert.ToString(dbo.GetSingle("select FENDDEVICE from t_manage_task where fid=" + manageTaskIdx).ToString()); msgIdx = Convert.ToInt32(dbo.GetSingle("select FSTARTDEVICE from t_manage_task where fid=" + manageTaskIdx)); sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder, deviceIdx, FENDDEVICE, ng.ToString()); //修改 20240325 //int RunState = Convert.ToInt32(dbo.GetSingle("select F_STATE from T_Base_Device where F_DeviceIndex=" + deviceIdx)); //StringBuilder sss = new StringBuilder(); //sss.Append("**读标志机械手"+deviceIdx).Append("**状态" + devinfo.RunState); //CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "收到机械手状态", deviceIdx.ToString(), sss.ToString()); //if (RunState == 0)//机械手状态标识为空闲时,发送下一个码垛指令 //{ // sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder, deviceIdx, FENDDEVICE, ng.ToString()); //} //else //{ // sendok = false; //} } } else { if (deviceKind == 2 && deviceOrder == 8)//横店东磁分配预充 { DataView ProCharge = dbo.ExceSQL("select T_ProCharge.*,F_LockedState from T_ProCharge,T_Base_Device where F_ArrowIndex=T_Base_Device.F_DeviceIndex and F_LockedState<>-1 and T_ProCharge.F_DeviceIndex=" + deviceIdx).Tables[0].DefaultView; if (ProCharge.Count > 0) { for (int i = 0; i < ProCharge.Count; i++) { int ProChargeDevice = CStaticClass.GetDevicePhotoelectric(Convert.ToInt32(ProCharge[i]["f_arrowindex"]), 2) == 0 ? 1 : 0; int CurDevice = CStaticClass.GetDevicePhotoelectric(Convert.ToInt32(ProCharge[i]["f_arrowindex"]), 0); int taskcount = Convert.ToInt32(dbo.GetSingle("select count(0) from t_manage_task where fstartdevice=" + deviceIdx + " and fenddevice=" + ProCharge[i]["f_arrowindex"])); if (ProChargeDevice + taskcount + CurDevice == 0) { Model.AutoTask at = new Model.AutoTask(4, barcode, deviceIdx.ToString(), "-", ProCharge[i]["f_arrowindex"].ToString(), "-", false, false, 0, 0); string error = string.Empty; if (BuildAutoTask(at, out error)) { //cgs.ActionComplete(deviceIdx, MonitorIndex, 1); Model.CGeneralFunction.ActionComplete(deviceIdx, MonitorIndex, 1); } break; } if (i == ProCharge.Count - 1) { for (int j = 0; j < ProCharge.Count; j++) { ProChargeDevice = CStaticClass.GetDevicePhotoelectric(Convert.ToInt32(ProCharge[j]["f_arrowindex"]), 2) == 0 ? 1 : 0; CurDevice = CStaticClass.GetDevicePhotoelectric(Convert.ToInt32(ProCharge[j]["f_arrowindex"]), 0); taskcount = Convert.ToInt32(dbo.GetSingle("select count(0) from t_manage_task where fstartdevice=" + deviceIdx + " and fenddevice=" + ProCharge[j]["f_arrowindex"])); if (ProChargeDevice + taskcount + CurDevice == 1) { Model.AutoTask at = new Model.AutoTask(4, barcode, deviceIdx.ToString(), "-", ProCharge[j]["f_arrowindex"].ToString(), "-", false, false, 0, 0); string error = string.Empty; if (BuildAutoTask(at, out error)) { //cgs.ActionComplete(deviceIdx, MonitorIndex, 1); Model.CGeneralFunction.ActionComplete(deviceIdx, MonitorIndex, 1); } break; } } } } } sendok = false; } else if (deviceKind == 2 && deviceOrder == 10) { sendok = false; DataView dvv = dbo.ExceSQL("select t_dispallet.* from t_dispallet,t_base_device where f_enddevice=f_deviceindex and F_LockedState<>-1 and f_startdevice=" + deviceIdx).Tables[0].DefaultView; if (dvv.Count > 0) { for (int i = 0; i < dvv.Count; i++) { int dispallet = CStaticClass.GetDevicePhotoelectric(Convert.ToInt32(dvv[i]["f_enddevice"]), 1); int havegoods = CStaticClass.GetDevicePhotoelectric(Convert.ToInt32(dvv[i]["f_enddevice"]), 0); int taskcount = Convert.ToInt32(dbo.GetSingle("select count(0) from t_manage_task where fstartdevice=" + dvv[i]["f_startdevice"] + " and fenddevice=" + dvv[i]["f_enddevice"])); if (taskcount + (havegoods + dispallet > 0 ? 1 : 0) == 0) { Model.AutoTask at = new Model.AutoTask(4, barcode, deviceIdx.ToString(), "-", dvv[i]["f_enddevice"].ToString(), "-", false, false, 0, 0); string error = string.Empty; if (Convert.ToInt32(dbo.GetSingle("select count(0) from T_DisPallet where f_enddevice=" + EndDevice)) > 0) { dbo.ExceSQL("delete t_monitor_task where F_MonitorIndex=" + MonitorIndex); dbo.ExceSQL("update t_manage_task set FIntoStepOK='0',FSTATUS=0,fstartdevice=" + deviceIdx + ",fenddevice=" + dvv[i]["f_enddevice"] + " where fid=" + manageTaskIdx); //dboM.ExceSQL("update io_control set END_DEVICE_CODE='" + dvv[i]["f_enddevice"].ToString() + "' where CONTROL_ID=" + manageTaskIdx); } else { if (BuildAutoTask(at, out error)) { //cgs.ActionComplete(deviceIdx, MonitorIndex, 1); Model.CGeneralFunction.ActionComplete(deviceIdx, MonitorIndex, 1); } } break; } if (i == dvv.Count - 1) { for (int j = 0; j < dvv.Count; j++) { dispallet = CStaticClass.GetDevicePhotoelectric(Convert.ToInt32(dvv[j]["f_enddevice"]), 1); havegoods = CStaticClass.GetDevicePhotoelectric(Convert.ToInt32(dvv[j]["f_enddevice"]), 0); taskcount = Convert.ToInt32(dbo.GetSingle("select count(0) from t_manage_task where fstartdevice=" + dvv[j]["f_startdevice"] + " and fenddevice=" + dvv[j]["f_enddevice"])); if (taskcount + (havegoods + dispallet > 0 ? 1 : 0) < Convert.ToInt32(dvv[j]["f_count"])) { if (deviceIdx == 32077 || deviceIdx == 32047 || deviceIdx == 32062)//OVC1后方有来托盘再分配否则等待 { int temp = Convert.ToInt32(dbo.GetSingle("select count(0) from t_monitor_task where F_NumParam4=" + deviceIdx + " and F_ManageTaskIndex<>" + manageTaskIdx)); if (temp < 1) { continue; } } Model.AutoTask at = new Model.AutoTask(4, barcode, deviceIdx.ToString(), "-", dvv[j]["f_enddevice"].ToString(), "-", false, false, 0, 0); string error = string.Empty; //dbo.ExceSQL("update t_manage_task set F_ManageTaskKindIndex=2 where F_ManageTaskKindIndex=1 and fid=" + manageTaskIdx); if (Convert.ToInt32(dbo.GetSingle("select count(0) from T_DisPallet where f_enddevice=" + EndDevice)) > 0) { dbo.ExceSQL("delete t_monitor_task where F_MonitorIndex=" + MonitorIndex); dbo.ExceSQL("update t_manage_task set FIntoStepOK='0',FSTATUS=0,fstartdevice=" + deviceIdx + ",fenddevice=" + dvv[i]["f_enddevice"] + " where fid=" + manageTaskIdx); //dboM.ExceSQL("update io_control set END_DEVICE_CODE='" + dvv[i]["f_enddevice"].ToString() + "' where CONTROL_ID=" + manageTaskIdx); } else { if (BuildAutoTask(at, out error)) { //cgs.ActionComplete(deviceIdx, MonitorIndex, 1); Model.CGeneralFunction.ActionComplete(deviceIdx, MonitorIndex, 1); } } break; } } } } } } else if (deviceKind == 2 && deviceOrder == 9)//需要分叠盘机 { sendok = false; if (Batch == "0") { DataView batterydata = dboM.ExceSQL("select goods_property1 from STORAGE_LIST with(nolock) where goods_property2='" + barcode.ToString() + "'").Tables[0].DefaultView; if (batterydata.Count > 0) { if (!string.IsNullOrEmpty(batterydata[0]["goods_property1"].ToString())) { Batch = batterydata[0]["goods_property1"].ToString(); } } } if (Batch == "0") { AheadDetectUnallow.Clear(); AheadDetectUnallow.Append("未知电池批次!"); UpdateAheadDetectUnallow(AheadDetectUnallow, MonitorIndex); return false; } else { int arrow = 0; FindStackPallet(deviceIdx, Batch, out arrow); if (arrow != 0) { Model.AutoTask at = new Model.AutoTask(4, barcode, deviceIdx.ToString(), "-", arrow.ToString(), "-", false, false, 0, 0); string error = string.Empty; if (BuildAutoTask(at, out error)) { //cgs.ActionComplete(deviceIdx, MonitorIndex, 1); Model.CGeneralFunction.ActionComplete(deviceIdx, MonitorIndex, 1); dbo.ExceSQL("update t_manage_task set BATTERY_BATCH='" + Batch + "' where FPALLETBARCODE='" + barcode + "' and fstartdevice=" + deviceIdx + " and fenddevice=" + arrow); } } else { AheadDetectUnallow.Clear(); AheadDetectUnallow.Append("尚无叠盘机可分!"); UpdateAheadDetectUnallow(AheadDetectUnallow, MonitorIndex); return false; } } } else if (deviceKind == 2 && devinfo.Dbw2Getlength > 10 && deviceOrder == 6 && ((deviceIdx > 32130 || deviceIdx < 32105) || (deviceIdx >= 32105 && deviceIdx <= 32130 && deviceIdx == gc[5])))//OCV4叠盘机对接OCV设备需要特殊判断 { string nowbatch = dbo.GetSingle("select F_BATCH from T_STACKPALLET where F_ENDDEVICE=" + ccf.GetEndDeviceFromManage(manageKindIdx, manageTaskIdx)).ToString(); if (nowbatch == Batch || nowbatch == "0") { sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder, deviceIdx, gc[5], BatteryType, barcode); if (nowbatch == "0") { dbo.ExceSQL("update T_STACKPALLET set F_BATCH='" + Batch + "' where F_ENDDEVICE=" + ccf.GetEndDeviceFromManage(manageKindIdx, manageTaskIdx)); } } else { dbo.ExceSQL("update t_monitor_task set F_DeviceCommandIndex=7 where F_MonitorIndex=" + MonitorIndex); sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, 7, deviceIdx, gc[5], BatteryType, barcode); dbo.ExceSQL("update T_STACKPALLET set F_BATCH='" + Batch + "' where F_ENDDEVICE=" + ccf.GetEndDeviceFromManage(manageKindIdx, manageTaskIdx)); } } else { if (deviceKind == 2 && devinfo.Dbw2Getlength > 10 && ((deviceIdx > 32130 || deviceIdx < 32105) || (deviceIdx >= 32105 && deviceIdx <= 32130 && deviceIdx == gc[5])))//OCV4叠盘机对接OCV设备需要特殊判断 { sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder, deviceIdx, gc[5], BatteryType, barcode); } else { if (deviceIdx != 12024)//cz临时修改保证只有一条任务启动 { string sql2 = string.Format("select * from T_Monitor_Task where F_NumParam1 in ({0}) and F_Status > 0 ", deviceIdx); DataView dvIO = dbo.ExceSQL(sql2).Tables[0].DefaultView; if (dvIO.Count == 0) //if (dvIO.Count <= 1) { sql.Remove(0, sql.Length); sql.Append("select * from IO_Control where taskflag=1").Append(" and CONTROL_ID=(select F_ManageTaskIndex from T_Monitor_Task where F_MonitorIndex= ").Append(MonitorIndex).Append(")"); DataView dvPlcAsk = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dvPlcAsk.Count == 1) { //如果物料条码不是空才打印条码 if (!string.IsNullOrEmpty(dvPlcAsk[0]["STOCK_BARCODE"].ToString())) { #region 发送贴码信息 //TODO 条码打印 socketSendPrint201 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socketSendPrint201.SendTimeout = 100; socketSendPrint201.ReceiveTimeout = 100; socketSendPrint201.Connect("10.0.27.124", Convert.ToInt32("9100")); string printTxt = dvPlcAsk[0]["STOCK_BARCODE"].ToString(); //string input = "#041C1E1Q1^D " + dvPlcAsk[0]["STOCK_BARCODE"].ToString() + "??]"; //string input = "#041C1E1Q1^D " + printTxt + "??]"; string input = "#041C1E1Q1^D" + printTxt + "??]"; byte[] utf8Bytes = Encoding.UTF8.GetBytes(input); socketSendPrint201.Send(utf8Bytes); socketSendPrint201.Disconnect(true); CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "r任务号:" + MonitorIndex, "发送贴标机条码信息", "条码:" + dvPlcAsk[0]["STOCK_BARCODE"].ToString()); #endregion 发送贴码信息 } // System.Threading.Thread.Sleep(3000); } sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder, deviceIdx, gc[5], BatteryType); } else { sendok = false; } } else { sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder, deviceIdx, gc[5], BatteryType); } } } } if (sendok == false) { if (sdo.CommLayerError != null) { RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", sdo.CommLayerError); OnRefreshMonitor(rmea); } return false; } else//发送命令成功 { sql.Remove(0, sql.Length); sql.Append("update T_Monitor_Task set F_SendFlag='1' where F_MonitorIndex=").Append(MonitorIndex); dbo.ExecuteSql(sql.ToString());//20100905只重发主任务 ccf.SendOrderSuccess(manageKindIdx, manageTaskIdx, MonitorIndex, deviceIdx, _routeID); if (deviceIdx >= 32105 && deviceIdx <= 32130 && EndDevice != deviceIdx)//OCV4特殊处理在叠盘入库后将后面要去叠盘的任务重发 { DataView needresend = dbo.ExceSQL("select * from t_manage_task where FSTATUS>0 and F_ManageTaskKindIndex=1 and FStartDevice=" + deviceIdx + " and FEndDevice=" + deviceIdx + " order by fid desc").Tables[0].DefaultView; if (needresend.Count > 0) { string LastGroupBarcode = dbo.GetSingle("select F_BarCode from T_Base_PLC_Ask where F_BindingDevice=" + deviceIdx).ToString(); if (!string.IsNullOrEmpty(LastGroupBarcode)) { if (LastGroupBarcode.IndexOf(needresend[0]["FPALLETBARCODE"].ToString()) >= 0) { dbo.ExceSQL("update t_monitor_task set F_Status=0 where F_ManageTaskIndex=" + needresend[0]["fid"]); } } } } #region 多叉关联任务,能同步的同时报告发送命令成功 //20100323 devinfo = Model.CGetInfo.GetDeviceInfo(deviceIdx); if (devinfo.IfCorrelDoubleFork == "1") { int[] corrtask = Model.CGeneralFunction.MutiForkIfSync(MonitorIndex, deviceIdx, deviceKind); if (corrtask != null) { int rfid = 0, rmankind = 0, rdev = 0; for (int i = 0; i < corrtask.GetLength(0); i++) { rfid = ccf.GetManageTaskIndexfromMonitor(corrtask[i]); rmankind = ccf.GetManageTaskKindIndexFromMonitor(corrtask[i]); rdev = ccf.GetDeviceindexFromMonitor(corrtask[i]); ccf.SendOrderSuccess(rmankind, rfid, corrtask[i], rdev, 0); if (rdev.ToString().IndexOf("12064") >= 0 || rdev.ToString().IndexOf("12065") >= 0 || rdev.ToString().IndexOf("12066") >= 0 || rdev.ToString().IndexOf("12067") >= 0) { Model.CGeneralFunction.ActionComplete(rdev, corrtask[i], 0); } } } } #endregion return true; } } else { return false; } #endregion } } catch (Exception ex) {//20110608 CControlError = string.Format("发送命令调用SendMonitorTask时:{0}", ex.StackTrace + ex.Message); return false; } } int GetDeviceFromMonitor(int monitorIndex) { DataView dv = new DataView(); try { sql.Remove(0, sql.Length); sql.Append("SELECT F_MonitorIndex, F_DeviceIndex FROM T_Monitor_Task WHERE (F_MonitorIndex = ").Append(monitorIndex).Append(")"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0]["F_DeviceIndex"]); } else { return -1; } } catch (Exception ex) { throw ex; } finally { dv.Dispose(); } } /// /// 获取可用的目标位置:入库的巷道或者出库站台 /// /// 调度任务索引 /// 调度任务类别 /// bool GetUsableDestination(int manageTaskIdx, int manageKindIdx) { //20100610查找一个路径可用,任务数最少的终点设备 Dictionary advDev = new Dictionary(); object ob; DataView dv = new DataView(); DataRowView dr = null; DataView dvIO = new DataView(); DataTable dtd = new DataTable(); DataTable dt = new DataTable(); try { sql.Remove(0, sql.Length); sql.Append("SELECT * FROM T_Manage_Task WHERE (FID = ").Append(manageTaskIdx).Append(") AND (F_ManageTaskKindIndex = ").Append(manageKindIdx).Append(")"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count <= 0) { return false; } dr = dv[0]; //20091107 sql.Remove(0, sql.Length); sql.Append("select CONTROL_ID, CONTROL_STATUS from IO_Control where (CONTROL_ID = ").Append(Convert.ToInt32(dr["FID"])).Append(") AND ((CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKALTERROUTEAPPLY).Append(") or (CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKALTERROUTEREPLY).Append("))"); dvIO = dboM.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dvIO.Count <= 0) { //只修申请改调度任务的路径,不修改调度自动任务路径 if (dr["F_ManageTaskKindIndex"].ToString() != "1") return false; string adviceDev = ""; sql.Remove(0, sql.Length); sql.Append("SELECT F_TASKKIND, F_DESTINATION FROM T_Base_Destination WHERE (F_Warehouse='").Append(dr["FENDWAREHOUSE"]).Append("') and (F_TASKKIND = ").Append(dr["FCONTROLTASKTYPE"]).Append(") and (F_AbendStation=1) and (F_DESTINATION=").Append(dr["FENDDEVICE"]).Append(")"); dtd = dbo.ExceSQL(sql.ToString()).Tables[0]; if (dtd.Rows.Count > 0)//原来终点是应急站台那么还分配这个站台,不需要改变 { adviceDev = dtd.Rows[0]["F_DESTINATION"].ToString(); return false; } else { //查找可用目标位置 sql.Remove(0, sql.Length); sql.Append("SELECT F_TASKKIND, F_DESTINATION FROM T_Base_Destination WHERE (F_Warehouse='").Append(dr["FENDWAREHOUSE"]).Append("') and (F_TASKKIND = ").Append(dr["FCONTROLTASKTYPE"]).Append(") and (F_DESTINATION <>").Append(dr["FENDDEVICE"]).Append(") and (F_AbendStation=0)"); dt = dbo.ExceSQL(sql.ToString()).Tables[0]; if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { if (CDisassembleTask.MinRouteID(Convert.ToInt32(dr["FSTARTDEVICE"]), Convert.ToInt32(dt.Rows[i]["F_DESTINATION"]), dr["FUseAwayFork"]) != -1) { //20100610统计到终点设备正在执行的任务数 sql.Remove(0, sql.Length); sql.Append("SELECT count(FENDDEVICE) as counts FROM T_Manage_Task where FENDDEVICE='").Append(dt.Rows[i]["F_DESTINATION"]).Append("' and fstatus>0"); ob = dbo.GetSingle(sql.ToString()); advDev.Add(Convert.ToInt32(dt.Rows[i]["F_DESTINATION"]), Convert.ToInt32(ob)); //20100610 break; } } if (advDev.Count == 0)//20100610 { return false; } else {//20100610 int mincount = 9999; foreach (int aaa in advDev.Keys) { if (advDev[aaa] < mincount) { mincount = advDev[aaa]; adviceDev = aaa.ToString(); } } if (adviceDev == "") { return false; } } } else {//20100610 return false; } } string dtime = DateTime.Now.ToString("u"); dtime = dtime.Substring(0, dtime.Length - 1); //20091128 dboM.TransBegin(); try { sql.Remove(0, sql.Length); sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKALTERROUTEAPPLY).Append(" where CONTROL_ID=").Append(dr["FID"]).Append(""); dboM.ExceSQL(sql.ToString()); //向管理申请修改任务// int appid = dboM.GetManageTableIndex("IO_CONTROL_APPLY", true);//CONTROL_APPLY_ID sql.Remove(0, sql.Length); sql.Append("INSERT INTO IO_CONTROL_APPLY ( CONTROL_APPLY_ID,CONTROL_ID,CONTROL_APPLY_TYPE,WAREHOUSE_CODE, STOCK_BARCODE, DEVICE_CODE, APPLY_TASK_STATUS, CREATE_TIME, ").Append( " CONTROL_APPLY_REMARK)").Append( "VALUES (").Append(appid).Append(",").Append(dr["FID"]).Append(",2,'").Append(dr["FENDWAREHOUSE"]).Append("','").Append(dr["FPALLETBARCODE"]).Append("','").Append(adviceDev).Append("',0,'").Append(dtime).Append("',null)"); dboM.ExceSQL(sql.ToString()); dboM.TransCommit(); //把ManageTaskIdx,ManageKindIdx 的调度任务全部申请改道 sql.Remove(0, sql.Length); sql.Append("UPDATE T_Monitor_Task SET F_Status = 3 WHERE (F_ManageTaskIndex = ").Append(manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX =").Append(manageKindIdx).Append(")"); dbo.ExceSQL(sql.ToString()); CommonClassLib.CCarryConvert.WriteDarkCasket("CControl.GetUsableDestination", "堆垛机入库目标位置发生改道", "管理任务:" + manageKindIdx.ToString() + "-" + manageTaskIdx.ToString(), "条码:" + dr["FPALLETBARCODE"].ToString().ToUpper()); return true; } catch (Exception ex) { CControlError = string.Format("发送指令,申请改道时:{0}", ex.StackTrace + ex.Message); dboM.TransRollback(); return false; } } else { return false; } } catch (Exception ex) { throw ex; } finally { dt.Dispose(); dtd.Dispose(); dv.Dispose(); dvIO.Dispose(); dr = null; } } bool GetRGVIdleDestination(int manageTaskIdx, int manageKindIdx, int RGVGateDevice, bool IfUseNegativeDevice) { //20100610 t_Base_device 表F_UsableEndDevice字段存放入库或者出库对等的设备索引组(以分号隔开): //负数代表位于当前设备前面(环形RGV行走方向的反方向),只允许在发送RGV取货和第一、二个运动时使用; //正数代表当前设备后面的设备,可以在发送送货和之前的所有命令使用.直道RGV都是正数。 //T_Base_RGV_Gate新增字段“F_EndDevice”用于记载入库时靠近巷道一侧的RGV出入口输送机的对应的巷道设备索引 //或者出库时靠近出库站台一侧的输送机对应的出库站台索引 //可变更目标位置的选择原则:RGV目标位置空闲、无物;目标位置参与的正在执行的调度任务数最少 DataView dv = new DataView(); DataRowView dr = null; string adviceDev = ""; char[] cc = new char[1] { ';' }; string[] sp; DataView dvIO = new DataView(); Dictionary advDev = new Dictionary(); object ob; DataView dvu = new DataView(); try { sql.Remove(0, sql.Length); sql.Append("SELECT * FROM T_Manage_Task WHERE (FID = ").Append(manageTaskIdx).Append(") AND (F_ManageTaskKindIndex = ").Append(manageKindIdx).Append(")"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count <= 0) { return false; } dr = dv[0]; //只修申请改调度任务的路径,不修改调度自动任务路径 if (dr["F_ManageTaskKindIndex"].ToString() != "1") return false; sql.Remove(0, sql.Length); sql.Append("select CONTROL_ID, CONTROL_STATUS from IO_Control where (CONTROL_ID = ").Append(Convert.ToInt32(dr["FID"])).Append(") AND ((CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKALTERROUTEAPPLY).Append(") or (CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKCANCEL).Append(") or(CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKALTERROUTEREPLY).Append("))"); dvIO = dboM.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dvIO.Count <= 0) { #region 根据T_Base_Device表的F_UsableEndDevice查找可用终点设备 sql.Remove(0, sql.Length); sql.Append("select F_UsableEndDevice from T_Base_Device where F_UsableEndDevice is not null and F_DeviceIndex=").Append(RGVGateDevice).Append(""); dvu = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dvu.Count > 0) { int enddv = 0, DESTINATION = 0; sp = dvu[0]["F_UsableEndDevice"].ToString().Split(cc); for (int i = sp.GetLowerBound(0); i <= sp.GetUpperBound(0); i++) { if (int.TryParse(sp[i], out enddv) == false) continue; enddv = Convert.ToInt32(sp[i]); if (enddv < 0) { //负数代表当前设备前面的设备(环形RGV行走方向的反方向) if (IfUseNegativeDevice == true) { enddv = -(enddv); } else { continue; } } devinfo = Model.CGetInfo.GetDeviceInfo(enddv); if ((devinfo.HaveGoods == true) || (devinfo.RunState == 2)) {//目标位置被占用或者故障 continue; } sql.Remove(0, sql.Length); sql.Append("SELECT F_EndDevice FROM T_Base_RGV_Gate WHERE (F_RGVGateDeviceIndex = ").Append(enddv).Append(") AND (F_EndDevice IS NOT NULL)"); ob = dbo.GetSingle(sql.ToString()); if (ob == null) continue; DESTINATION = Convert.ToInt32(ob); if (CDisassembleTask.MinRouteID(Convert.ToInt32(dr["FSTARTDEVICE"]), DESTINATION, dr["FUseAwayFork"]) != -1) { //20100609统计到终点设备正在执行的任务数 sql.Remove(0, sql.Length); sql.Append("SELECT count(FENDDEVICE) as counts FROM T_Manage_Task where FENDDEVICE='").Append(DESTINATION).Append("' and fstatus>0"); ob = dbo.GetSingle(sql.ToString()); advDev.Add(DESTINATION, Convert.ToInt32(ob)); } } } else { return false; } if (advDev.Count <= 0) { return false; } else { int mincount = 9999; foreach (int aaa in advDev.Keys) { if (advDev[aaa] < mincount) { mincount = advDev[aaa]; adviceDev = aaa.ToString(); } } if (adviceDev == "") { return false; } } #endregion //20101108int fid = dboM.GetManageTableIndex("IO_CONTROL_APPLY"); string dtime = DateTime.Now.ToString("u"); dtime = dtime.Substring(0, dtime.Length - 1); dboM.TransBegin(); try { sql.Remove(0, sql.Length); sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKALTERROUTEAPPLY).Append(" where CONTROL_ID=").Append(dr["FID"]).Append(" and CONTROL_STATUS<>").Append(Model.CGeneralFunction.TASKCANCEL).Append(""); dboM.ExceSQL(sql.ToString()); //向管理申请修改任务 int appid = dboM.GetManageTableIndex("IO_CONTROL_APPLY", true);//CONTROL_APPLY_ID sql.Remove(0, sql.Length); sql.Append("INSERT INTO IO_CONTROL_APPLY (CONTROL_APPLY_ID, CONTROL_ID, WAREHOUSE_CODE, STOCK_BARCODE, DEVICE_CODE, APPLY_TASK_STATUS, CREATE_TIME,CONTROL_APPLY_REMARK)").Append( "VALUES (").Append(appid).Append(",").Append(dr["FID"]).Append(",'").Append(dr["FENDWAREHOUSE"]).Append("','").Append(dr["FPALLETBARCODE"]).Append("','").Append(adviceDev).Append("',0,'").Append(dtime).Append("',null)"); dboM.ExceSQL(sql.ToString()); dboM.TransCommit(); //把ManageTaskIdx,ManageKindIdx 的调度任务全部申请改道 sql.Remove(0, sql.Length); sql.Append("UPDATE T_Monitor_Task SET F_Status = 3 WHERE (F_ManageTaskIndex = ").Append(manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX =").Append(manageKindIdx).Append(")"); dbo.ExceSQL(sql.ToString()); CommonClassLib.CCarryConvert.WriteDarkCasket("CControl.GetRGVIdleDestination", "穿梭车目标位置发生改道", "管理任务:" + manageKindIdx.ToString() + "-" + manageTaskIdx.ToString(), "条码:" + dr["FPALLETBARCODE"].ToString().ToUpper()); return true; } catch (Exception ex) { dboM.TransRollback(); CControlError = string.Format("发送指令,申请改道时:{0}", ex.StackTrace + ex.Message); return false; } } else { return false; } } catch (Exception ex) { CControlError = string.Format("发送指令,申请改道时:{0}", ex.StackTrace + ex.Message); return false; } finally { dv.Dispose(); dr = null; cc = null; sp = null; dvIO.Dispose(); dvu.Dispose(); } } /// /// 返回在顶升处入库任务可以多叉关联的调度任务索引 /// /// 控制任务类型 /// 设备索引 /// int GetEnableDoubleForkManageTask(int controlTaskType, int devindex, int FID) { DataView dv0 = new DataView(); DataView dv = new DataView(); try { sql.Remove(0, sql.Length); sql.Append("SELECT F_MonitorIndex,T_Monitor_Task.F_ManageTaskIndex,T_Monitor_Task.F_ManageTASKKINDINDEX FROM T_Monitor_Task ,T_Manage_Task where T_Monitor_Task.F_ManageTaskIndex = T_Manage_Task.FID AND T_Monitor_Task.F_ManageTASKKINDINDEX = T_Manage_Task.F_ManageTaskKindIndex AND F_DeviceIndex=").Append(devindex).Append(" and FCONTROLTASKTYPE=").Append(controlTaskType); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { for (int i = 0; i < dv.Count; i++) { sql.Remove(0, sql.Length); sql.Append("select min(F_MonitorIndex) as mm from T_Monitor_Task where F_ManageTaskIndex=").Append(dv[i]["F_ManageTaskIndex"]).Append(" and F_ManageTASKKINDINDEX=").Append(dv[i]["F_ManageTASKKINDINDEX"]); dv0 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv0.Count > 0) { if (dv0[0]["mm"].ToString() == dv[i]["F_MonitorIndex"].ToString()) { if (FID != Convert.ToInt32(dv[i]["F_ManageTaskIndex"])) { return Convert.ToInt32(dv[i]["F_ManageTaskIndex"]); } } } } return -1; } else { return -1; } } catch (Exception ex) { throw ex; } finally { dv.Dispose(); dv0.Dispose(); } } /// /// 获得堆垛机在对等站台取货的多叉关联任务 /// /// 控制任务类型 /// 堆垛机设备索引 /// 站台设备索引 /// 调度任务索引 /// int GetEnableDoubleForkManageTask(int controlTaskType, int Stackdevindex, int StationDevice, int FID) { DataView dv1 = new DataView(); DataView dv0 = new DataView(); DataView dv = new DataView(); try { sql.Remove(0, sql.Length); sql.Append("SELECT F_ZXY FROM T_Base_Lane_Gate,T_Base_LaneInfo WHERE ").Append( "(T_Base_Lane_Gate.F_LaneIndex = T_Base_LaneInfo.F_LaneDeviceIndex) and (T_Base_LaneInfo.F_StackIndex = ").Append( Stackdevindex).Append(") and (F_LaneGateDeviceIndex=").Append(StationDevice).Append(")"); dv1 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv1.Count <= 0) return -1; char[] cc = new char[1] { '-' }; string[] zxy = dv1[0]["F_ZXY"].ToString().Split(cc); sql.Remove(0, sql.Length); sql.Append("SELECT F_MonitorIndex,T_Monitor_Task.F_ManageTaskIndex,T_Monitor_Task.F_ManageTASKKINDINDEX ").Append( " FROM T_Monitor_Task ,T_Manage_Task where T_Monitor_Task.F_ManageTaskIndex = T_Manage_Task.FID AND ").Append( "T_Monitor_Task.F_ManageTASKKINDINDEX = T_Manage_Task.F_ManageTaskKindIndex AND F_DeviceIndex=").Append( Stackdevindex).Append(" and FCONTROLTASKTYPE=").Append(controlTaskType).Append(" and F_NumParam1=").Append(zxy[0]).Append( " and F_NumParam2=").Append(zxy[1]).Append(" and F_NumParam3=").Append(zxy[2]).Append(" and F_RELATIVECONTORLID<>").Append(FID); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { for (int i = 0; i < dv.Count; i++) { sql.Remove(0, sql.Length); sql.Append("select min(F_MonitorIndex) as mm from T_Monitor_Task where F_ManageTaskIndex=").Append(dv[i]["F_ManageTaskIndex"]).Append(" and F_ManageTASKKINDINDEX=").Append(dv[i]["F_ManageTASKKINDINDEX"]).Append(" "); dv0 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv0.Count > 0) { if (dv0[0]["mm"].ToString() == dv[i]["F_MonitorIndex"].ToString()) { if (FID != Convert.ToInt32(dv[i]["F_ManageTaskIndex"])) { return Convert.ToInt32(dv[i]["F_ManageTaskIndex"]); } } } } return -1; } else { return -1; } } catch (Exception ex) { throw ex; } finally { dv.Dispose(); dv0.Dispose(); dv1.Dispose(); } } /// /// /// /// 调度任务类型索引 /// 调度任务索引 /// 调度任务类型 /// 最后分配的远、近货叉 void AlterRoutePath(int Mankind, int FID, int ControlTaskType, char UseAwayFork, int NowDevice) { DataView dv = new DataView(); DataView dv1 = new DataView(); DataView dvnew = new DataView(); //先找到以前的路径是否与最后分配的货叉匹配,不匹配的改道 try { sql.Remove(0, sql.Length); sql.Append("SELECT T_Monitor_Task.F_MonitorIndex,T_Monitor_Task.F_DeviceIndex FROM T_Monitor_Task,T_Base_Route_Device where ").Append( " T_Monitor_Task.F_RouteID = T_Base_Route_Device.F_RouteIDSub AND T_Monitor_Task.F_DeviceIndex = T_Base_Route_Device.F_DeviceIndex and T_Monitor_Task.F_ManageTaskIndex=").Append( FID).Append(" and T_Monitor_Task.F_ManageTASKKINDINDEX=").Append(Mankind).Append(" and T_Base_Route_Device.F_UseAwayFork<>'").Append(UseAwayFork).Append("'"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { sql.Remove(0, sql.Length); sql.Append("select * from T_Manage_Task where F_ManageTaskKindIndex=").Append(Mankind).Append(" and FID=").Append(FID); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { //20100702 sql.Remove(0, sql.Length); sql.Append("SELECT T_Base_Route_Device.F_RouteIDSub FROM T_Base_Route,T_Base_Route_Device where T_Base_Route.F_RouteID = T_Base_Route_Device.F_RouteID ").Append( " and (T_Base_Route_Device.F_UseAwayFork = '").Append(UseAwayFork).Append("') AND (T_Base_Route_Device.F_DeviceIndex = ").Append(NowDevice).Append(") AND (T_Base_Route.F_StartDevice = ").Append( dv[0]["FSTARTDEVICE"]).Append(") AND (T_Base_Route.F_EndDevice = ").Append(dv[0]["FENDDEVICE"]).Append(" and F_RouteKind=").Append(ControlTaskType).Append(")"); ; dv1 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv1.Count > 0) { int routeidNew = Convert.ToInt32(dv1[0][0]); //删除原来的申请修改路径任务,拆分新的任务并且只保留现有设备开始的任务 sql.Remove(0, sql.Length); sql.Append("DELETE FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(FID).Append(") AND (F_ManageTASKKINDINDEX =").Append(Mankind).Append(")"); dbo.ExceSQL(sql.ToString()); if (CDisassembleTask.CreateMonitor(Mankind, FID, routeidNew, dv[0], 3) > 0) { CommonClassLib.CCarryConvert.WriteDarkCasket("调用拆分任务", "调用拆分任务", "位置", "2"); sql.Remove(0, sql.Length); sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append( FID).Append(") AND (F_ManageTASKKINDINDEX = ").Append(Mankind).Append(") AND (F_DeviceIndex = ").Append( NowDevice).Append(") AND (F_RouteID = ").Append(routeidNew).Append( ") AND (F_Status = 3) "); dvnew = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dvnew.Count > 0) { sql.Remove(0, sql.Length); sql.Append("delete from T_Monitor_Task where F_MonitorIndex<").Append(dvnew[0]["F_MonitorIndex"]).Append(" and (F_ManageTaskIndex = ").Append( FID).Append(") AND (F_ManageTASKKINDINDEX = ").Append(Mankind).Append(") AND (F_Status = 3)"); dbo.ExceSQL(sql.ToString()); sql.Remove(0, sql.Length); sql.Append("update T_Monitor_Task set F_Status =0 where (F_ManageTaskIndex = ").Append( FID).Append(") AND (F_ManageTASKKINDINDEX = ").Append(Mankind).Append(") AND (F_Status = 3)"); dbo.ExceSQL(sql.ToString()); } } } } } } catch (Exception ex) { throw ex; } finally { dv.Dispose(); dv1.Dispose(); dvnew.Dispose(); } } int GetDoubleForkMinRouteTask(int taskno) { DataView dv = new DataView(); try { //不是双叉的直接返回taskno;是双叉但是可以同步的直接返回taskno //双叉不能同步的反馈距离当前堆垛机位置最短的taskno int manKind = Model.CGeneralFunction.GetManageTaskKindIndexFromMonitor(taskno); int manFid = Model.CGeneralFunction.GetManageTaskIndexfromMonitor(taskno); int deviceindex = Model.CGeneralFunction.GetDeviceIndexFromMonitor(taskno); int devKind = Model.CGeneralFunction.GetDeviceKindIdx(deviceindex); int devOrder = Model.CGeneralFunction.GetDeviceOrderFromMonitor(taskno); devinfo = Model.CGetInfo.GetDeviceInfo(deviceindex); int nX = Model.CGeneralFunction.GetXCoorFromMonitor(taskno, deviceindex, devOrder); int nY = Model.CGeneralFunction.GetYCoorFromMonitor(taskno, deviceindex, devOrder); double nXY = 0, doubleXY = 0, doubleX = 0, doubleY = 0; nXY = Math.Pow((double)(nX - devinfo.XCoor), 2) + (Math.Pow((double)(nY - devinfo.YCoor), 2)); if (devinfo.IfCorrelDoubleFork == "1") { Dictionary df = Model.CGeneralFunction.GetDoubleForkMonitorInfo(taskno, deviceindex); if (df == null) return taskno; if (Model.CGeneralFunction.MutiForkIfSync(taskno, deviceindex, devKind) == null) { #region 遍历每个关联任务 foreach (int cortask in df.Keys) { //20120906 sql.Remove(0, sql.Length); sql.Append("SELECT F_MonitorIndex FROM dbo.T_Monitor_Task WHERE (F_MonitorIndex = ").Append(cortask).Append(") AND (F_status = 0)"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count <= 0) { continue; } #region 关联指令不是第一个指令不能发送 int rmankind = Model.CGeneralFunction.GetManageTaskKindIndexFromMonitor(cortask); int rman = Model.CGeneralFunction.GetManageTaskIndexfromMonitor(cortask); sql.Remove(0, sql.Length); sql.Append("SELECT MIN(F_MonitorIndex) AS mmi FROM dbo.T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(rman).Append(") AND (F_ManageTASKKINDINDEX = ").Append(rmankind).Append(")"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { if ((dv[0]["mmi"] != DBNull.Value) && (dv[0]["mmi"].ToString() != cortask.ToString())) { return -1; } } #endregion if (devKind == 1)//堆垛机 {//如果存在倒库货位,则后执行该任务20120906嘉兴电力改进,倒库货位的取货命令检测堆垛机货叉对应开关是否有货 //if (devOrder == 5)//送货指令时判断20110505 //{ // if (true == IfChangeForkCell_LastRun(cortask)) // { // continue; // } //} doubleX = Model.CGeneralFunction.GetXCoorFromMonitor(cortask, deviceindex, devOrder); doubleY = Model.CGeneralFunction.GetYCoorFromMonitor(cortask, deviceindex, devOrder); doubleXY = Math.Pow((double)(doubleX - devinfo.XCoor), 2) + (Math.Pow((double)(doubleY - devinfo.YCoor), 2)); if (nXY > doubleXY) { nXY = doubleXY; taskno = cortask; } } else if (devKind == 6)//AGV { sql.Remove(0, sql.Length); sql.Append("SELECT F_Sequence FROM T_Base_AGV_Gate WHERE (F_AGVGateDeviceIndex = ").Append(nX).Append(")"); nXY = Convert.ToInt32(dbo.GetSingle(sql.ToString())); sql.Remove(0, sql.Length); sql.Append("SELECT F_Sequence FROM T_Base_AGV_Gate WHERE (F_AGVGateDeviceIndex = ").Append(doubleX).Append(")"); doubleXY = Convert.ToInt32(dbo.GetSingle(sql.ToString())); if (nXY < doubleXY) { return taskno; } else { return Convert.ToInt32(df[0]); } } else { return taskno; } } #endregion //返回最小值的任务号 return taskno; } else { #region 遍历每个关联任务 foreach (int cortask in df.Keys) { #region 关联指令不是第一个指令不能发送 int rmankind = Model.CGeneralFunction.GetManageTaskKindIndexFromMonitor(cortask); int rman = Model.CGeneralFunction.GetManageTaskIndexfromMonitor(cortask); sql.Remove(0, sql.Length); sql.Append("SELECT MIN(F_MonitorIndex) AS mmi FROM dbo.T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(rman).Append(") AND (F_ManageTASKKINDINDEX = ").Append(rmankind).Append(")"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { if ((dv[0]["mmi"] != DBNull.Value) && (dv[0]["mmi"].ToString() != cortask.ToString())) { return -1; } } #endregion } #endregion return taskno; } } else { return taskno; } } catch (Exception ex) { CControlError = string.Format("发送命令调用GetDoubleForkMinRouteTask时:{0},{1}", sql.ToString(), ex.StackTrace + ex.Message); return taskno; } finally { dv.Dispose(); } } bool IFAGVGate(int devIndex) { sql.Remove(0, sql.Length); sql.Append("SELECT F_AGVGateDeviceIndex FROM T_Base_AGV_Gate WHERE (F_AGVGateDeviceIndex = ").Append(devIndex).Append(")"); if (dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView.Count > 0) { return true; } else { return false; } } /// /// 同轨两个堆垛机组合作业,通过中转货位交替作业 /// /// /// /// void ChangeStackCellCode(int taskindex, string ChangeStackCell, int StackIndex) {//20120820 int[] zxy = ccf.GetCoordinatesFromMonitorTask(taskindex); StringBuilder zxystr = new StringBuilder(); DataView dvl = new DataView(); DataView dv = new DataView(); if (zxy != null) { zxystr.Append((zxy[3].ToString().Length == 1 ? "0" + zxy[3].ToString() : zxy[3].ToString())).Append("-").Append( ((zxy[4].ToString().Length == 1) ? ("0" + zxy[4].ToString()) : (zxy[4].ToString()))).Append("-").Append( ((zxy[5].ToString().Length == 1) ? ("0" + zxy[5].ToString()) : (zxy[5].ToString()))); } int laneway = 0; dvl = dbo.ExceSQL(string.Format("SELECT F_LaneDeviceIndex FROM T_Base_LaneInfo WHERE (F_StackIndex = {0})", StackIndex)).Tables[0].DefaultView; if (dvl.Count > 0) { laneway = Convert.ToInt32(dvl[0]["F_LaneDeviceIndex"]); } else return; char[] cc = new char[1] { '-' }; string[] endCell = ChangeStackCell.Split(cc); int fid = ccf.GetManageTaskIndexfromMonitor(taskindex); int Mankind = ccf.GetManageTaskKindIndexFromMonitor(taskindex); //dbo.TransBegin(); try { sql.Remove(0, sql.Length); sql.Append("SELECT F_LaneGateDeviceIndex FROM T_Base_Lane_Gate,T_Base_Device WHERE (T_Base_Lane_Gate.F_LaneGateDeviceIndex = T_Base_Device.F_DeviceIndex) and (F_ZXY = '").Append(ChangeStackCell).Append("') and F_LaneIndex=").Append(laneway); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { sql.Remove(0, sql.Length);//20120420 sql.Append("update T_Monitor_Task set F_AheadDetect=F_AheadDetect+'").Append(";N").Append(dv[0]["F_LaneGateDeviceIndex"].ToString()).Append(";R").Append(dv[0]["F_LaneGateDeviceIndex"].ToString()) .Append("', F_NumParam4=").Append(endCell[0]).Append(",F_NumParam5=").Append(endCell[1]).Append(",F_ChangeStackCell='").Append(laneway.ToString() + "," + ChangeStackCell ).Append("',F_NumParam6=").Append(endCell[2]).Append(" where F_ManageTaskIndex=").Append(fid).Append(" and F_ManageTASKKINDINDEX=").Append(Mankind).Append(" and F_DeviceIndex=").Append(StackIndex); dbo.ExecuteSql(sql.ToString()); sql.Remove(0, sql.Length); sql.Append("update T_Manage_Task set FREMARK='").Append(zxystr.ToString()).Append("',FExceptionNO=").Append(Model.CGeneralFunction.TASKCHANGESTACK).Append(" where FID=").Append(fid).Append(" and F_ManageTaskKindIndex=").Append(Mankind); dbo.ExecuteSql(sql.ToString()); } //dbo.TransCommit(); } catch (Exception ex) { throw ex; //dbo.TransRollback(); } finally { dv.Dispose(); dvl.Dispose(); } } int GetIOControlStatus(int TaskIndex) { int mankind = ccf.GetManageTaskKindIndexFromMonitor(TaskIndex); int Fid = ccf.GetManageTaskIndexfromMonitor(TaskIndex); if (mankind == 1) { sql.Remove(0, sql.Length); sql.Append("SELECT CONTROL_STATUS FROM IO_CONTROL WHERE (CONTROL_ID = ").Append(Fid).Append(")"); object ob = dboM.GetSingle(sql.ToString()); if (ob != null) { return Convert.ToInt32(ob); } else { return 1; } } else { return 1; } } /// /// 返回AGV双叉的关联站台,“-1”代表没有关联 /// /// 设备指令索引 /// int GetAGVCorrelIndex(int taskindex) { sql.Remove(0, sql.Length); sql.Append("SELECT F_NumParam2 FROM T_Monitor_Task WHERE (F_MonitorIndex = ").Append(taskindex).Append(")"); object ob = dbo.GetSingle(sql.ToString()); if (ob != null) { int cs = Convert.ToInt32(ob); if (cs % 2 == 0) { return (cs - 1); } else { return (cs + 1); } } else { return -1; } } int GetAGVCorrelConveyorIndex(int taskindex) { sql.Remove(0, sql.Length); sql.Append("SELECT F_NumParam2 FROM T_Monitor_Task WHERE (F_MonitorIndex = ").Append(taskindex).Append(")"); object ob = dbo.GetSingle(sql.ToString()); if (ob != null) { int cs = Convert.ToInt32(ob); if (cs % 2 == 0) { return (cs + 1); } else { return (cs - 1); } } else { return -1; } } /// /// 返回AGV在此站台取货的调度任务索引 /// /// 控制任务类型 /// AGV站台索引 /// int GetAGVEnableDoubleForkManageTask(int controltype, int stationIndex, int agv) {//20110412 DataView dv = new DataView(); try { sql.Remove(0, sql.Length); sql.Append("SELECT F_MonitorIndex,T_Monitor_Task.F_ManageTaskIndex,T_Monitor_Task.F_ManageTASKKINDINDEX ").Append( " FROM T_Monitor_Task ,T_Manage_Task where T_Monitor_Task.F_ManageTaskIndex = T_Manage_Task.FID AND ").Append( "T_Monitor_Task.F_ManageTASKKINDINDEX = T_Manage_Task.F_ManageTaskKindIndex and FCONTROLTASKTYPE=").Append( controltype).Append(" and F_NumParam2=").Append(stationIndex).Append(" and F_DeviceIndex=").Append(agv).Append(" and F_Status=0 and F_DeviceCommandIndex=2"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0]["F_ManageTaskIndex"]); } return -1; } catch (Exception ex) { throw ex; } finally { dv.Dispose(); } } bool IfInSameLimitX(int fid, int mfid, int manKind) { DataView dv = new DataView(); DataView dv1 = new DataView(); try { sql.Remove(0, sql.Length); sql.Append("SELECT F_ForwardLimitX,F_BackLimitX,FEndCol FROM T_Manage_Task,T_Base_LaneInfo WHERE T_Manage_Task.FLANEWAY = T_Base_LaneInfo.F_LaneDeviceIndex and (F_ManageTaskKindIndex = ").Append(manKind).Append(") AND (FID = ").Append(fid).Append(")"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count == 0) { return false; } sql.Remove(0, sql.Length); sql.Append("SELECT F_ForwardLimitX,F_BackLimitX,FEndCol FROM T_Manage_Task,T_Base_LaneInfo WHERE T_Manage_Task.FLANEWAY = T_Base_LaneInfo.F_LaneDeviceIndex and (F_ManageTaskKindIndex = ").Append(manKind).Append(") AND (FID = ").Append(mfid).Append(")"); dv1 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv1.Count == 0) { return false; } if ((dv[0]["FEndCol"].ToString() == dv[0]["F_ForwardLimitX"].ToString()) && (dv1[0]["F_ForwardLimitX"].ToString() == dv1[0]["FEndCol"].ToString())) { return true; } if ((dv[0]["FEndCol"].ToString() == dv[0]["F_BackLimitX"].ToString()) && (dv1[0]["F_BackLimitX"].ToString() == dv1[0]["FEndCol"].ToString())) { return true; } return false; } catch (Exception ex) { throw ex; } finally { dv.Dispose(); dv1.Dispose(); } } int GetAGVFromConveyorDoubleForkGetGoodManageTask(int controltype, int stationIndex, int agv) { DataView dv0 = new DataView(); DataView dv = new DataView(); try { sql.Remove(0, sql.Length); sql.Append("SELECT T_Monitor_Task.F_ManageTaskIndex,F_MonitorIndex,T_Manage_Task.F_ManageTaskKindIndex ").Append( " FROM T_Monitor_Task ,T_Manage_Task where T_Monitor_Task.F_ManageTaskIndex = T_Manage_Task.FID AND ").Append( "T_Monitor_Task.F_ManageTASKKINDINDEX = T_Manage_Task.F_ManageTaskKindIndex and FCONTROLTASKTYPE=").Append( controltype).Append(" and F_NumParam2=").Append(stationIndex).Append(" and F_DeviceIndex=").Append(agv).Append(" and F_Status=0 and F_DeviceCommandIndex=2 order by F_MonitorIndex asc");//20110412 dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { for (int i = 0; i < dv.Count; i++) { sql.Remove(0, sql.Length); sql.Append("SELECT top 1 F_MonitorIndex ").Append(" FROM T_Monitor_Task where T_Monitor_Task.F_ManageTaskIndex = ") .Append(dv[i]["F_ManageTaskIndex"].ToString()).Append( " and F_ManageTASKKINDINDEX = ").Append(dv[i]["F_ManageTaskKindIndex"].ToString()).Append(" order by F_MonitorIndex asc"); dv0 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv0[0]["F_MonitorIndex"].ToString() == dv[i]["F_MonitorIndex"].ToString()) { return Convert.ToInt32(dv[i]["F_ManageTaskIndex"]); } } } return -1; } catch (Exception ex) { throw ex; } finally { dv.Dispose(); dv0.Dispose(); } } bool IFHaveSameEndDevice(int fid, int CorrelFid, int mti) { DataView dv0 = new DataView(); DataView dv = new DataView(); try { sql.Remove(0, sql.Length); sql.Append("SELECT FENDDEVICE, FENDCELL, FUseAwayFork FROM T_Manage_Task WHERE (F_ManageTaskKindIndex = ").Append(mti).Append(") AND (FID = ").Append(fid).Append(")"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { sql.Remove(0, sql.Length); sql.Append("SELECT FENDDEVICE, FENDCELL, FUseAwayFork FROM T_Manage_Task WHERE (F_ManageTaskKindIndex = ").Append(mti).Append(") AND (FID = ").Append(CorrelFid).Append(")"); dv0 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv0.Count > 0) { if ((dv[0]["FENDDEVICE"].ToString() == dv0[0]["FENDDEVICE"].ToString()) && (dv[0]["FENDDEVICE"].ToString() == "28001") && (Math.Abs(Convert.ToInt32(dv[0]["FENDCELL"]) - Convert.ToInt32(dv0[0]["FENDCELL"])) == 1))//20110412 { if ((Convert.ToInt32(dv[0]["FENDCELL"]) > Convert.ToInt32(dv0[0]["FENDCELL"])) && (Convert.ToInt32(dv[0]["FUseAwayFork"]) > Convert.ToInt32(dv0[0]["FUseAwayFork"]))) { return true; } if ((Convert.ToInt32(dv[0]["FENDCELL"]) < Convert.ToInt32(dv0[0]["FENDCELL"])) && (Convert.ToInt32(dv[0]["FUseAwayFork"]) < Convert.ToInt32(dv0[0]["FUseAwayFork"]))) { return true; } return false; } else { return false; } } else { return false; } } else { return false; } } catch (Exception ex) { throw ex; } finally { dv.Dispose(); dv0.Dispose(); } } void UpdateAheadDetectUnallow(StringBuilder aheadUnallow, int taskindex) { #region 20110505增加的信息提示 int rec = 0; if (aheadUnallow.Length > 0) { rec = dbo.ExecuteSql(string.Format("UPDATE T_Monitor_Task SET F_ErrorCode ='{0}' WHERE F_MonitorIndex ={1} and F_ErrorCode <>'{0}'", aheadUnallow.ToString(), taskindex)); } else { rec = dbo.ExecuteSql(string.Format("UPDATE T_Monitor_Task SET F_ErrorCode ='' WHERE F_MonitorIndex ={1} and F_ErrorCode <>''", aheadUnallow.ToString(), taskindex)); } if (rec > 0) { CDataChangeEventArgs cea = new CDataChangeEventArgs(null, null); OnDataChange("发送提前检测时,异常", cea); } #endregion } /// /// 如果是倒叉货位,那它后执行 /// /// /// bool IfChangeForkCell_LastRun(int TaskIndex) {//20110505 DataView dv = new DataView(); try { int laneway = ccf.GetLaneWayFromLaneInfo(ccf.GetDeviceindexFromMonitor(TaskIndex)); int[] zxy = ccf.GetCoordinatesFromMonitorTask(TaskIndex); string zxystr = (zxy[3].ToString().Length == 1 ? "0" + zxy[0].ToString() : zxy[3].ToString()) + "-" + ((zxy[4].ToString().Length == 1) ? ("0" + zxy[4].ToString()) : (zxy[4].ToString())) + "-" + ((zxy[5].ToString().Length == 1) ? ("0" + zxy[5].ToString()) : (zxy[5].ToString())); int lanedev = ccf.GetChangeCellStationFromLaneGate(laneway, zxystr); dv = dbo.ExceSQL(string.Format("SELECT F_ChangeForkCell FROM T_Base_LaneInfo WHERE F_LaneDeviceIndex={0} and (F_ChangeForkCell like '%{1}%' or F_ChangeForkCell like '%{2}%')", laneway, zxystr, lanedev)).Tables[0].DefaultView; if (dv.Count > 0)//倒库货位的任务后执行 { return true; } return false; } catch (Exception ex) { throw ex; } finally { dv.Dispose(); } } /// /// 分配实际工作的堆垛机设备索引20111020 /// /// 虚拟堆垛机设备索引 /// 设备指令索引 /// 调度任务类型 /// 调度任务索引 bool AssignStackNo(int deviceIndex, int taskIndex, int manKind, int fid) {//20120820 DataView dv = new DataView(); Model.MDevice devinfo; int resDev = 0; try { int Xcoor = Model.CGeneralFunction.GetXCoorFromMonitor(taskIndex, deviceIndex, ccf.GetDeviceOrderFromMonitor(taskIndex)); int Zcoor = Model.CGeneralFunction.GetZCoorFromMonitor(taskIndex, deviceIndex, ccf.GetDeviceOrderFromMonitor(taskIndex)); int XcoorS = Model.CGeneralFunction.GetXCoorFromMonitor(taskIndex, deviceIndex, 5); int ZcoorS = Model.CGeneralFunction.GetZCoorFromMonitor(taskIndex, deviceIndex, 5); int sno = 0; bool IfCombinedWork = false; GetSpecialStackNo(deviceIndex, Zcoor, Xcoor, ZcoorS, XcoorS, out sno, out IfCombinedWork); //先考虑特殊情况20111226 if (IfCombinedWork == true) { //两个堆垛机组合交替作业 string ChangeStackCell = GetChangeStackCell(deviceIndex); if (ChangeStackCell != "") { ChangeStackCellCode(taskIndex, ChangeStackCell, deviceIndex); SetStackNo(deviceIndex, sno, manKind, fid); return true; } else {//20120820没有空闲的两个堆垛机公用的交接货位 return false; } } //然后其余情况根据总列数折中分配给两个堆垛机 resDev = GetPRIStackNo(deviceIndex, Zcoor, Xcoor, ZcoorS, XcoorS); devinfo = Model.CGetInfo.GetDeviceInfo(resDev); if (devinfo.RunState == 0 && ccf.GetManTaskReserve(resDev) <= 0 && ccf.GetDeviceLockedState(resDev) == 0) {//空闲、无任务执行、无管理任务预约锁 SetStackNo(deviceIndex, resDev, manKind, fid); return true; } else {//根据35001当前位置和正在执行的任务的目标位置考虑是否分配35002 resDev = devinfo.MutexStack; devinfo = Model.CGetInfo.GetDeviceInfo(resDev); if (devinfo.RunState == 0 && ccf.GetManTaskReserve(resDev) <= 0 && ccf.GetDeviceLockedState(resDev) == 0) { sql = new StringBuilder(string.Format("SELECT F_DeviceCommandIndex,F_NumParam1, F_NumParam2, F_NumParam3, F_NumParam4, F_NumParam5, F_NumParam6 FROM T_Monitor_Task WHERE (F_Status > 0) AND (F_DeviceIndex = {0})", devinfo.MutexStack)); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { if (dv[0]["F_DeviceCommandIndex"].ToString() == "4")//取货 { if ((GetBarcodeCoor(Convert.ToInt32(dv[0]["F_NumParam2"]), Convert.ToInt32(dv[0]["F_NumParam1"])) + StackMutexXCoor) <= GetBarcodeCoor(Xcoor, Zcoor)) { SetStackNo(deviceIndex, resDev, manKind, fid); return true; } } if (dv[0]["F_DeviceCommandIndex"].ToString() == "5")//送货 { if ((GetBarcodeCoor(Convert.ToInt32(dv[0]["F_NumParam5"]), Convert.ToInt32(dv[0]["F_NumParam4"])) + StackMutexXCoor) <= GetBarcodeCoor(Xcoor, Zcoor)) { SetStackNo(deviceIndex, resDev, manKind, fid); return true; } } } else {//(resDev - devinfo.MutexStack)设备编号小的设备,实际行走位置的坐标值也小 int xcMutex = (resDev - devinfo.MutexStack) * (GetBarcodeCoor(Xcoor, Zcoor) - Model.CGetInfo.GetDeviceInfo(devinfo.MutexStack).XCoor);//20120513 int xMutex = Math.Abs(GetBarcodeCoor(Xcoor, Zcoor) - Model.CGetInfo.GetDeviceInfo(devinfo.MutexStack).XCoor); int xDev = Math.Abs(GetBarcodeCoor(Xcoor, Zcoor) - Model.CGetInfo.GetDeviceInfo(resDev).XCoor); devinfo = Model.CGetInfo.GetDeviceInfo(devinfo.MutexStack);//20120513 if ((xDev < xMutex) || ((devinfo.RunState >= 2) && (devinfo.RunState <= 4) && (xcMutex > StackMutexXCoor)))//20120513 { SetStackNo(deviceIndex, resDev, manKind, fid); return true; } } } } return false; } catch (Exception ex) { throw ex; } finally { dv.Dispose(); } } private string GetChangeStackCell(int stack) {//20120820根据两个堆垛机的组合任务判断哪个更换堆垛机站台空闲 DataView dv = new DataView(); int fids = 0; string cell = ""; int minfids = int.MaxValue; try { dv = dbo.ExceSQL(string.Format("SELECT F_LaneDeviceIndex, F_ChangeStackCell FROM T_Base_LaneInfo where F_StackIndex={0}", stack)).Tables[0].DefaultView; if (dv.Count > 0) { char[] cc = new char[1] { ';' }; string[] sp = dv[0]["F_ChangeStackCell"].ToString().Split(cc); string ChangeStackCell = string.Empty; int lanedev = 0; for (int i = 0; i < sp.GetLength(0); i++) {//T_Monitor_Task表新增 F_ChangeStackCell "18001,01-30-02" int.TryParse(sp[i], out lanedev); if (lanedev > 0) {//T_Base_LaneInfo表的 F_ChangeStackCell 和F_ChangeForkCell字段可以填写倒叉货位对应虚拟站台的设备索引 sp[i] = ccf.GetChangeCellFromLaneGate(Convert.ToInt32(dv[0]["F_LaneDeviceIndex"]), lanedev); } ChangeStackCell = dv[0]["F_LaneDeviceIndex"].ToString() + "," + sp[i]; fids = Convert.ToInt32(dbo.GetSingle(string.Format("SELECT count(distinct F_ManageTaskIndex) as fids FROM T_Monitor_Task where F_ChangeStackCell='{0}'", ChangeStackCell))); if (fids < minfids) { minfids = fids; cell = sp[i]; } } } return cell; } catch (Exception ex) { throw ex; } finally { dv.Dispose(); } } void SetStackNo(int dummyStackno, int stackno, int manKind, int fid) { //20111226考虑调整配套的站台和提前检测,35001-32038;35002-32036 if (StackIfExitTask(stackno) == true) return; object[] ob = new object[4] { stackno, manKind, fid, dummyStackno }; dbo.ExecuteSql(string.Format("UPDATE T_Monitor_Task SET F_DeviceIndex ={0} WHERE (F_ManageTASKKINDINDEX = {1}) AND (F_ManageTaskIndex = {2}) AND (F_DeviceIndex = {3})", ob)); dbo.ExecuteSql(string.Format("UPDATE T_Monitor_Task SET F_AheadDetect =replace(F_AheadDetect,{3},{0}) WHERE (F_ManageTASKKINDINDEX = {1}) AND (F_ManageTaskIndex = {2}) ", ob)); } void GetStackRunX_Zcoor(int StackdeviceIndex, out int Xcoor, out int Zcoor) {//20111020 DataView dv = new DataView(); try { Xcoor = 0; Zcoor = 1; sql = new StringBuilder(string.Format("SELECT F_DeviceCommandIndex,F_NumParam1, F_NumParam2, F_NumParam3, F_NumParam4, F_NumParam5, F_NumParam6 FROM T_Monitor_Task WHERE (F_Status > 0) AND (F_DeviceIndex = {0})", StackdeviceIndex)); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { if ((dv[0]["F_DeviceCommandIndex"].ToString() == "2") || (dv[0]["F_DeviceCommandIndex"].ToString() == "4"))//将取,取货 { Zcoor = Convert.ToInt32(dv[0]["F_NumParam1"]); Xcoor = Convert.ToInt32(dv[0]["F_NumParam2"]); } else if (dv[0]["F_DeviceCommandIndex"].ToString() == "5")//送货 { Zcoor = Convert.ToInt32(dv[0]["F_NumParam4"]); Xcoor = Convert.ToInt32(dv[0]["F_NumParam5"]); } } //else //{ // int ManTaskReserve = ccf.GetManTaskReserve(StackdeviceIndex); // if (ManTaskReserve > 0) // { // int mti =Convert.ToInt32( ManTaskReserve.ToString().Substring(0, 1)); // int fid = Convert.ToInt32(ManTaskReserve.ToString().Substring(1)); // sql = new StringBuilder(string.Format("SELECT F_DeviceIndex,F_DeviceCommandIndex,F_NumParam1, F_NumParam2, F_NumParam3, F_NumParam4, F_NumParam5, F_NumParam6 FROM T_Monitor_Task WHERE (F_ManageTASKKINDINDEX={0}) AND (F_ManageTaskIndex = {1}) order by F_MonitorIndex asc", mti, fid)); // dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; // if (dv.Count > 0) // { // if (dv[0]["F_DeviceIndex"].ToString() == StackdeviceIndex.ToString()) // { // if ((dv[0]["F_DeviceCommandIndex"].ToString() == "2") || (dv[0]["F_DeviceCommandIndex"].ToString() == "4"))//将取,取货 // { // Zcoor = Convert.ToInt32(dv[0]["F_NumParam1"]); // Xcoor = Convert.ToInt32(dv[0]["F_NumParam2"]); // } // else if (dv[0]["F_DeviceCommandIndex"].ToString() == "5")//送货 // { // Zcoor = Convert.ToInt32(dv[0]["F_NumParam4"]); // Xcoor = Convert.ToInt32(dv[0]["F_NumParam5"]); // } // } // } // } //} } catch (Exception ex) { throw ex; } finally { dv.Dispose(); } } void GetStackRunReserveX_Zcoor(int StackdeviceIndex, out int Xcoor, out int Zcoor) {//20111020 Xcoor = 0; Zcoor = 1; DataView dv = new DataView(); try { int ManTaskReserve = ccf.GetManTaskReserve(StackdeviceIndex); if (ManTaskReserve > 0) { int mti = Convert.ToInt32(ManTaskReserve.ToString().Substring(0, 1)); int fid = Convert.ToInt32(ManTaskReserve.ToString().Substring(1)); sql = new StringBuilder(string.Format("SELECT F_DeviceIndex,F_DeviceCommandIndex,F_NumParam1, F_NumParam2, F_NumParam3, F_NumParam4, F_NumParam5, F_NumParam6 FROM T_Monitor_Task WHERE (F_ManageTASKKINDINDEX={0}) AND (F_ManageTaskIndex = {1}) order by F_MonitorIndex asc", mti, fid)); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { if (dv[0]["F_DeviceIndex"].ToString() == StackdeviceIndex.ToString()) { if ((dv[0]["F_DeviceCommandIndex"].ToString() == "2") || (dv[0]["F_DeviceCommandIndex"].ToString() == "4"))//将取,取货 { Zcoor = Convert.ToInt32(dv[0]["F_NumParam1"]); Xcoor = Convert.ToInt32(dv[0]["F_NumParam2"]); } else if (dv[0]["F_DeviceCommandIndex"].ToString() == "5")//送货 { Zcoor = Convert.ToInt32(dv[0]["F_NumParam4"]); Xcoor = Convert.ToInt32(dv[0]["F_NumParam5"]); } } } } } catch (Exception ex) { throw ex; } finally { dv.Dispose(); } } /// /// 插入避让指令 /// /// 避让堆垛机 /// 指令 /// 避让到达的条码坐标 /// 避让堆垛机的货物层高度 void InsertStackMutexOrder(int stackno, int order, int Barcodecoor, int layerhigh) {//20111020 DataView dv = new DataView(); try { dv = dbo.ExceSQL("SELECT MAX(BarcodeCoor) AS maxcoor, MIN(BarcodeCoor) AS mincoor FROM T_Base_BarcodeCoor").Tables[0].DefaultView; if (dv.Count > 0) { if (Barcodecoor > Convert.ToInt32(dv[0]["maxcoor"])) { Barcodecoor = Convert.ToInt32(dv[0]["maxcoor"]); } if (Barcodecoor < Convert.ToInt32(dv[0]["mincoor"])) { Barcodecoor = Convert.ToInt32(dv[0]["mincoor"]); } } else { return; } if (order == 2 || order == 4) { if (CStaticClass.GetDevicePhotoelectric(stackno, 0) == 0)//20120110 { order = 2; } else { order = 1; } } else { if (CStaticClass.GetDevicePhotoelectric(stackno, 0) == 1)//20120110 { order = 3; } else { order = 1; } } int zc = 0, xc = 0, yc = 0, zc1 = 0, xc1 = 0, yc1 = 0; if (stackno == 35001) { dv = dbo.ExceSQL(string.Format("SELECT TOP 1 ABS(MIN(BarcodeCoor - {0})) AS Expr1, XCoor, ZCoor FROM T_Base_BarcodeCoor where BarcodeCoor<={0} and layerhigh<={1} and (brorder=0 or brorder={2}) GROUP BY XCoor, ZCoor ORDER BY Expr1", Barcodecoor, layerhigh, order)).Tables[0].DefaultView; } else { dv = dbo.ExceSQL(string.Format("SELECT TOP 1 ABS(MIN(BarcodeCoor - {0})) AS Expr1, XCoor, ZCoor FROM T_Base_BarcodeCoor where BarcodeCoor>={0} and layerhigh<={1} and (brorder=0 or brorder={2}) GROUP BY XCoor, ZCoor ORDER BY Expr1", Barcodecoor, layerhigh, order)).Tables[0].DefaultView; } if (dv.Count > 0) { if (order == 2) { zc = Convert.ToInt32(dv[0]["ZCoor"]); xc = Convert.ToInt32(dv[0]["XCoor"]); if (xc == 51) xc = 52;//20120110 if (xc <= 5) { zc = 2; xc = 2; } yc = 1; if (xc == 52) zc = 1; } else { zc1 = Convert.ToInt32(dv[0]["ZCoor"]); xc1 = Convert.ToInt32(dv[0]["XCoor"]); if (xc1 == 51) xc1 = 52;//20120110 if (xc1 <= 5) { zc1 = 2; xc1 = 2; } yc1 = 1; if (xc1 == 52) zc1 = 2; } } else { if (order != 1) { return; } } dv = dbo.ExceSQL(string.Format("select F_MonitorIndex from T_Monitor_Task where F_DeviceIndex={0} and F_TxtParam='brbrbr'", stackno)).Tables[0].DefaultView; if (dv.Count <= 0) { int hidx = ccf.GetTempManageIdx(); int hmindx = ccf.GetMonitorIndex(hidx, 2); sql.Remove(0, sql.Length); sql.Append("insert into T_Monitor_Task(F_MonitorTaskLevel,F_RouteID,F_ManageTaskIndex,F_ManageTaskKindIndex,F_MonitorIndex,"). Append("F_DeviceIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2,F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6,F_TxtParam,F_AheadDetect) "). Append("values(2,").Append(ccf.GetRouteIDsub(stackno)).Append(","). Append(hidx).Append(",4,").Append(hmindx).Append(",").Append(stackno). Append(",").Append(order).Append(",").Append(zc).Append(",").Append(xc).Append(",").Append(yc).Append(",").Append(zc1).Append(",").Append(xc1).Append(",").Append(yc1).Append(",'brbrbr','-')"); dbo.ExecuteSql(sql.ToString()); } } catch (Exception ex) { CControlError = string.Format("插入互斥堆垛机避让指令时:{0}", ex.StackTrace + ex.Message); } finally { dv.Dispose(); } } int GetNowDevice(int taskindex) { DataView dvb = new DataView(); try { sql.Remove(0, sql.Length); sql.Append("SELECT F_NumParam1 FROM T_Monitor_Task WHERE (F_MonitorIndex = ").Append(taskindex).Append(")"); dvb = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dvb.Count > 0) { return Convert.ToInt32(dvb[0]["F_NumParam1"]); } else { return 0; } } catch (Exception ex) { throw ex; } finally { dvb.Dispose(); } } /// /// 设备指令队列中是否存在可以关联堆垛机的取货命令 /// /// 堆垛机 /// 取货货位 /// 关联货位 /// 此次设备指令索引 /// bool IFHaveStackCorrelGetCommand(int Stackdev, string zxy, string Correlzxy, int nottaskindex) { DataView dv = new DataView(); char[] cc = new char[1] { '-' }; string[] zxystr = zxy.Split(cc); string[] zxystrCorrl = Correlzxy.Split(cc); try { int laneway = ccf.GetLaneWayNoFromStack(Stackdev); int corrdev = 0; dv = dbo.ExceSQL(string.Format("SELECT F_LaneGateDeviceIndex FROM T_Base_Lane_Gate WHERE (F_LaneIndex = {0}) AND (F_ZXY = '{1}')", laneway, Correlzxy)).Tables[0].DefaultView; if (dv.Count > 0) { corrdev = Convert.ToInt32(dv[0]["F_LaneGateDeviceIndex"]); } object[] ob = new object[8] { Stackdev, nottaskindex, Convert.ToInt32(zxystr[0]), Convert.ToInt32(zxystr[1]),Convert.ToInt32(zxystr[2]), Convert.ToInt32(zxystrCorrl[0]),Convert.ToInt32(zxystrCorrl[1]),Convert.ToInt32(zxystrCorrl[2]) }; dv = dbo.ExceSQL(string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_DeviceIndex = {0}) AND (F_DeviceCommandIndex =4) AND (F_MonitorIndex<>{1}) and (((F_NumParam1 = {2}) AND (F_NumParam2 = {3}) AND (F_NumParam3 = {4})) or ((F_NumParam1 = {5}) AND (F_NumParam2 = {6}) AND (F_NumParam3 = {7})))", ob)).Tables[0].DefaultView; if (dv.Count > 0) {//20120906不是已经等待多叉关联任务 sql.Remove(0, sql.Length);//输送机等待双叉任务号等于堆垛机取货TaskIdx sql.Append("SELECT F_TaskIndex,F_DeviceIndex,F_Remark FROM T_Base_PLC_Ask WHERE (F_TaskIndex =").Append(Convert.ToInt32(dv[0]["F_MonitorIndex"])).Append(") AND (F_DeviceIndex=").Append(corrdev).Append(")"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { return false; } return true; } else { return false; } } catch (Exception ex) { throw ex; } finally { dv.Dispose(); cc = null; zxystrCorrl = null; zxystr = null; } } int GetDeviceOrderFromManTaskReserve(int manTaskReserve, int deviceIndex) { DataView dv = new DataView(); try { int mti = Convert.ToInt32(manTaskReserve.ToString().Substring(0, 1)); int fid = Convert.ToInt32(manTaskReserve.ToString().Substring(1)); dv = dbo.ExceSQL(string.Format("SELECT F_DeviceIndex,F_DeviceCommandIndex FROM T_Monitor_Task WHERE (F_ManageTASKKINDINDEX = {0}) AND (F_ManageTaskIndex = {1}) order by F_MonitorIndex asc", mti, fid)).Tables[0].DefaultView; if (dv.Count > 0) { if (deviceIndex == Convert.ToInt32(dv[0]["F_DeviceIndex"])) { return Convert.ToInt32(dv[0]["F_DeviceCommandIndex"]); } else { return -1; } } else { return -1; } } catch (Exception ex) { throw ex; } finally { dv.Dispose(); } } int GetLayerHigh(int Zcoor, int Xcoor) { DataView dv = new DataView(); try { dv = dbo.ExceSQL(string.Format("SELECT LayerHigh FROM T_Base_BarcodeCoor WHERE (ZCoor = {0}) AND (XCoor = {1})", Zcoor, Xcoor)).Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0][0]); } else { return 3; } } catch (Exception ex) { throw ex; } finally { dv.Dispose(); } } void InsertUpDeviceUP(int updevice, int Mankind, int ManFID, int mindex) { DataRowView drv = null; DataView dv = new DataView(); try { dv = dbo.ExceSQL(string.Format("SELECT F_MonitorTaskLevel, F_RouteID, F_TxtParam, F_UseAwayFork,F_PriorMonitor FROM T_Monitor_Task WHERE F_MonitorIndex={0}", mindex)).Tables[0].DefaultView; if (dv.Count > 0) { mindex = Convert.ToInt32(dv[0]["F_PriorMonitor"]); drv = dv[0]; } else return; StringBuilder ah = new StringBuilder(); ah.Append("D-").Append(updevice).Append(".7;D").Append(updevice).Append(".0;I").Append(updevice); if (DeviceAndOrderExitInMonitor(Mankind, ManFID, updevice, 9, 0) == false) { #region 生成输送机命令 sql.Remove(0, sql.Length); sql.Append("INSERT INTO T_Monitor_Task ").Append( "(F_ManageTaskIndex, F_ManageTASKKINDINDEX, F_MonitorIndex,F_MonitorTaskLevel,").Append( " F_DeviceIndex, F_DeviceCommandIndex, F_RouteID, F_Status,F_NumParam1, F_NumParam4,").Append( " F_AheadDetect,F_TxtParam,F_UseAwayFork)").Append( "VALUES (").Append(ManFID).Append(",").Append(Mankind).Append(",").Append(mindex).Append(",").Append(drv["F_MonitorTaskLevel"] ).Append(",").Append(updevice).Append(",").Append(9).Append(",").Append(drv["F_RouteID"]).Append(",").Append(0).Append(",").Append(updevice).Append("," + 0 ).Append(",'").Append(ah).Append("','").Append(drv["F_TxtParam"]).Append("','").Append(drv["F_UseAwayFork"]).Append("')"); dbo.ExceSQL(sql.ToString()); #endregion } } catch (Exception ex) { CControlError = "插入顶升机上升指令时:" + ex.StackTrace + ex.Message; } finally { dv.Dispose(); drv = null; } } /// /// 判断调度表T_Monitor_Task是否存在调度任务的设备和命令 /// /// 调度任务类型 /// 调度任务索引 /// 设备所引 /// 设备命令 /// public bool DeviceAndOrderExitInMonitor(int Mankind, int ManFID, int DeviceIndex, int Order, int ArrowAddress) { DataView dv = new DataView(); try { if (Order == -1) return true; sql.Remove(0, sql.Length); switch (ccf.GetDeviceKindIdx(DeviceIndex)) { case 1://堆垛机 sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(ManFID).Append(")").Append( " AND (F_ManageTASKKINDINDEX = ").Append(Mankind).Append(") AND (F_DeviceIndex = ").Append(DeviceIndex).Append(")").Append( " AND (F_DeviceCommandIndex = ").Append(Order).Append(")"); break; case 2://输送机 sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(ManFID).Append(")").Append( " AND (F_ManageTASKKINDINDEX = ").Append(Mankind).Append(") AND (F_DeviceIndex = ").Append(DeviceIndex).Append(")").Append( " AND (F_DeviceCommandIndex = ").Append(Order).Append(")"); break; case 4://RGV sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(ManFID).Append(")").Append( " AND (F_ManageTASKKINDINDEX = ").Append(Mankind).Append(") AND (F_DeviceIndex = ").Append(DeviceIndex).Append(")").Append( " AND (F_DeviceCommandIndex = ").Append(Order).Append(") and F_NumParam1=").Append(ArrowAddress); break; case 6://AGV sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(ManFID).Append(")").Append( " AND (F_ManageTASKKINDINDEX = ").Append(Mankind).Append(") AND (F_DeviceIndex = ").Append(DeviceIndex).Append(")").Append( " AND (F_DeviceCommandIndex = ").Append(Order).Append(")"); break; default: sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(ManFID).Append(")").Append( " AND (F_ManageTASKKINDINDEX = ").Append(Mankind).Append(") AND (F_DeviceIndex = ").Append(DeviceIndex).Append(")").Append( " AND (F_DeviceCommandIndex = ").Append(Order).Append(")"); break; } dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { return true; } else { return false; } } catch (Exception ex) { CControlError = "ControlSystem.CControl.DeviceAndOrderExitInMonitor:" + ex.StackTrace + ex.Message; return false; } finally { dv.Dispose(); } } /// /// 堆垛机是否存在避让指令正在运行 /// /// /// bool DeviceHandTaskIfRun(int DeviceIndex) { DataView dv = new DataView(); try { dv = dbo.ExceSQL(string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task where F_ManageTASKKINDINDEX=4 and F_DeviceIndex={0} and F_Status>0", DeviceIndex)).Tables[0].DefaultView; if (dv.Count > 0) { return true; } else { return false; } } catch (Exception ex) { throw ex; } finally { dv.Dispose(); } } /// /// 堆垛机是否存在避让指令等待运行 /// /// /// bool DeviceHandTaskIfWaitRun(int DeviceIndex) { DataView dv = new DataView(); try { dv = dbo.ExceSQL(string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task where F_ManageTASKKINDINDEX=4 and F_DeviceIndex={0} and F_Status=0", DeviceIndex)).Tables[0].DefaultView; if (dv.Count > 0) { return true; } else { return false; } } catch (Exception ex) { throw ex; } finally { dv.Dispose(); } } bool StackIfExitTask(int stackno) { DataView dv = new DataView(); try { dv = dbo.ExceSQL(string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task where F_DeviceIndex={0}", stackno)).Tables[0].DefaultView; if (dv.Count > 0) { return true; } else { return false; } } catch (Exception ex) { throw ex; } finally { dv.Dispose(); } } void GetSpecialStackNo(int virStack, int startZ, int startX, int endZ, int endX, out int stackno, out bool IfCombinedWork) { stackno = 0; IfCombinedWork = false; int Getdevice = 0, Sendevice = 0; char[] fcc = new char[1] { ';' }; char[] dcc = new char[1] { ',' }; char[] hcc = new char[1] { '-' }; DataView dv = new DataView(); string[] zxys; string[] zx_x; string[] x_x; try { dv = dbo.ExceSQL(string.Format("SELECT T_Base_StackInfo.F_StackIndex, T_Base_StackInfo.F_SpecialZXArea,T_Base_StackInfo.F_PRIZXArea FROM T_Base_StackInfo WHERE T_Base_StackInfo.F_Mutex IS NOT NULL and T_Base_StackInfo.F_VirtualStack={0}", virStack)).Tables[0].DefaultView; for (int i = 0; i < dv.Count; i++) { zxys = dv[i]["F_SpecialZXArea"].ToString().Split(fcc);//1,0-2;2,0-5 for (int d = 0; d < zxys.GetLength(0); d++) { zx_x = zxys[d].Split(dcc); if (zx_x.GetLength(0) > 1) { for (int h = 1; h < zx_x.GetLength(0); h++) { x_x = zx_x[h].Split(hcc); if (x_x.GetLength(0) > 1) { if ((Convert.ToInt32(zx_x[0]) == startZ) && (startX >= Convert.ToInt32(x_x[0])) && (startX <= Convert.ToInt32(x_x[1]))) { Getdevice = Convert.ToInt32(dv[i]["F_StackIndex"]); } if ((Convert.ToInt32(zx_x[0]) == endZ) && (endX >= Convert.ToInt32(x_x[0])) && (endX <= Convert.ToInt32(x_x[1]))) { Sendevice = Convert.ToInt32(dv[i]["F_StackIndex"]); } } } } } } stackno = Getdevice; if (Getdevice != Sendevice) { devinfo = Model.CGetInfo.GetDeviceInfo(Getdevice); if (Sendevice == devinfo.VirtualStack) { IfCombinedWork = true; } else { IfCombinedWork = false; } } else { IfCombinedWork = false; } } catch (Exception ex) { CControlError = "分配堆垛机号GetSpecialStackNo:" + ex.StackTrace + ex.Message; } finally { } } int GetPRIStackNo(int virStack, int startZ, int startX, int endZ, int endX) { int Getdevice = 0; char[] fcc = new char[1] { ';' }; char[] dcc = new char[1] { ',' }; char[] hcc = new char[1] { '-' }; DataView dv = new DataView(); string[] zxys; string[] zx_x; string[] x_x; try { dv = dbo.ExceSQL(string.Format("SELECT T_Base_StackInfo.F_StackIndex, T_Base_StackInfo.F_SpecialZXArea,T_Base_StackInfo.F_PRIZXArea FROM T_Base_StackInfo WHERE T_Base_StackInfo.F_Mutex IS NOT NULL and T_Base_StackInfo.F_VirtualStack={0}", virStack)).Tables[0].DefaultView; for (int i = 0; i < dv.Count; i++) { zxys = dv[i]["F_PRIZXArea"].ToString().Split(fcc);//1,0-2;2,0-5 for (int d = 0; d < zxys.GetLength(0); d++) { zx_x = zxys[d].Split(dcc); if (zx_x.GetLength(0) > 1) { for (int h = 1; h < zx_x.GetLength(0); h++) { x_x = zx_x[h].Split(hcc); if (x_x.GetLength(0) > 1) { if ((Convert.ToInt32(zx_x[0]) == startZ) && (startX >= Convert.ToInt32(x_x[0])) && (startX <= Convert.ToInt32(x_x[1]))) { Getdevice = Convert.ToInt32(dv[i]["F_StackIndex"]); } } } } } } return Getdevice; } catch (Exception ex) { CControlError = "分配堆垛机号GetPRIStackNo:" + ex.StackTrace + ex.Message; return Getdevice; } finally { dv.Dispose(); } } /// /// 获取可关联的任务进行配多叉关联 /// /// 巷道出入口信息 /// 设备指令索引 /// 控制任务类型 /// 控制任务类别 /// 控制任务编号 /// 当前时间 /// bool GetCorrManageTask(string[] DevLanewayIOInfo, int TaskIdx, int CONTROLTASKTYPE, int mti, int fid, string dtime, out bool IfCorrTaskEnd) { IfCorrTaskEnd = false; DataView dv = new DataView(); try { sql.Remove(0, sql.Length);//输送机等待双叉任务号等于堆垛机取货TaskIdx sql.Append("SELECT F_TaskIndex,F_DeviceIndex,F_Remark FROM T_Base_PLC_Ask WHERE (F_TaskIndex =").Append(Convert.ToInt32(TaskIdx)).Append(") AND (F_Remark <> '') AND (F_DeviceIndex=").Append(DevLanewayIOInfo[0]).Append(")"); dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { #region 有任务等待关联任务 string zxy = DevLanewayIOInfo[9]; int waitdevice = Convert.ToInt32(dv[0]["F_DeviceIndex"]); //DevLanewayIOInfo[8]包含多个关联设备信息逐一检查20120906 char[] cc = new char[1] { ';' }; string[] CorrStations = DevLanewayIOInfo[8].Split(cc); foreach (string cs in CorrStations) { DevLanewayIOInfo = ccf.GetLanewayDeviceInfoFromStackDev(devinfo.DeviceIndex, Convert.ToInt32(cs));//关联站台的信息 string Correlzxy = DevLanewayIOInfo[9]; DateTime dtq = Convert.ToDateTime(dv[0]["F_Remark"]).AddSeconds(Convert.ToInt32(CStaticClass.DoubleForkWaitTime)); if ((GetIOControlStatus(TaskIdx) != Model.CGeneralFunction.TASKSINGLEFORKRUN) && (dtq > DateTime.Now)) { #region 没超时,不是单叉运行 //20111231没超时,不是单叉运行 //查找本地管理任务做多叉关联配对,关联任务分配货叉 int mfid = GetEnableDoubleForkManageTask(CONTROLTASKTYPE, devinfo.DeviceIndex, int.Parse(DevLanewayIOInfo[0]), fid); if (mfid > 0) { #region 双叉同为前极限后者后极限不关联,单独执行 if ((IfInSameLimitX(fid, mfid, mti) == true) && (mti == 1)) { sql.Remove(0, sql.Length); sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(fid).Append(")"); dboM.ExecuteSql(sql.ToString()); sql.Remove(0, sql.Length); sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(mfid).Append(")"); dboM.ExecuteSql(sql.ToString()); CommonClassLib.CCarryConvert.WriteDarkCasket("单叉执行原因", TaskIdx.ToString(), devinfo.DeviceIndex.ToString(), "双叉同为前极限后者后极限不关联,单独执行"); IfCorrTaskEnd = true; return true; } #endregion sql.Remove(0, sql.Length); sql.Append("update T_Manage_Task set F_RELATIVECONTORLID=").Append(fid).Append(" where F_ManageTaskKindIndex=").Append(mti).Append(" and FID=").Append(fid); dbo.ExecuteSql(sql.ToString()); sql.Remove(0, sql.Length); sql.Append("update T_Manage_Task set F_RELATIVECONTORLID=").Append(fid).Append(" where F_ManageTaskKindIndex=").Append(mti).Append(" and FID=").Append(mfid); dbo.ExecuteSql(sql.ToString()); //判断是否为1叉的关联任务:是,配叉结束 if (ccf.GetManageTaskStackFork(mti, mfid) == "1") { sql.Remove(0, sql.Length); sql.Append("update T_Base_PLC_Ask set F_Remark='' where (F_TaskIndex=").Append(TaskIdx).Append(")"); dbo.ExecuteSql(sql.ToString()); IfCorrTaskEnd = true; } continue; } else { //20110505 AheadDetectUnallow.Append(devinfo.DeviceIndex.ToString() + "双叉堆垛机等待多叉关联取货任务!"); UpdateAheadDetectUnallow(AheadDetectUnallow, TaskIdx); continue; } #endregion } else { #region 20111230单叉执行极限货位需要倒货叉 #region 堆垛机在顶升机取单叉任务,验证是否需要换货叉 string ChangeForkCell = ccf.IfLimitCellChangeFork(TaskIdx, devinfo.DeviceIndex); if (ChangeForkCell != "-")//主任务需要倒换货叉 { ccf.ChangeEndCellCode(TaskIdx, ChangeForkCell, devinfo.DeviceIndex); sql.Remove(0, sql.Length); sql.Append("update T_Base_PLC_Ask set F_TaskIndex=0,F_Remark='' where (F_DeviceIndex=").Append(waitdevice).Append(")"); dbo.ExecuteSql(sql.ToString()); CommonClassLib.CCarryConvert.WriteDarkCasket("单叉执行原因", TaskIdx.ToString(), devinfo.DeviceIndex.ToString(), "主任务需要倒换货叉"); IfCorrTaskEnd = true; return true; } #endregion #endregion if ((IFHaveStackCorrelGetCommand(devinfo.DeviceIndex, zxy, Correlzxy, TaskIdx) == true) && (GetIOControlStatus(TaskIdx) != Model.CGeneralFunction.TASKSINGLEFORKRUN))//20101124 {//队列中有可以关联的任务,重新计时 sql.Remove(0, sql.Length); sql.Append("update T_Base_PLC_Ask set F_Remark='").Append(dtime).Append("' where (F_DeviceIndex=").Append(waitdevice).Append(")"); dbo.ExecuteSql(sql.ToString()); //20110505 AheadDetectUnallow.Append(devinfo.DeviceIndex.ToString() + "双叉堆垛机在双叉对等站台取货" + ",等待多叉关联任务!"); UpdateAheadDetectUnallow(AheadDetectUnallow, TaskIdx); return false; } else {//超时或者管理强制执行单叉任务 sql.Remove(0, sql.Length); sql.Append("update T_Base_PLC_Ask set F_TaskIndex=0,F_Remark='' where (F_DeviceIndex=").Append(waitdevice).Append(")"); dbo.ExecuteSql(sql.ToString()); CommonClassLib.CCarryConvert.WriteDarkCasket("单叉执行原因", TaskIdx.ToString(), devinfo.DeviceIndex.ToString(), "超时或者管理强制执行单叉任务"); IfCorrTaskEnd = true; return true; } } } #endregion } return false; } catch (Exception ex) { CControlError = "获取堆垛机关联配叉GetCorrManageTask:" + ex.StackTrace + ex.Message; return false; } finally { dv.Dispose(); } } public bool BuildAutoTask(Model.AutoTask Autotask, out string Errtext) { DataView dv = new DataView(); try { string Sql, _tasktype; if ((Autotask._enableStartCell == true) && (ccf.GetDeviceKindIdx(Convert.ToInt32(Autotask._startDevice)) == 10)) { if (dbo.Exists("SELECT FID FROM ST_CELL where FLaneWay=" + Autotask._startDevice + " and FCELLCODE='" + Autotask._startCell + "'") == false) { Errtext = "起始位置和起始货位编码在数据库中没有记录!"; return false; } } if ((Autotask._enableEndCell == true) && (ccf.GetDeviceKindIdx(Convert.ToInt32(Autotask._endDevice)) == 10)) { if (dbo.Exists("SELECT FID FROM ST_CELL where FLaneWay=" + Autotask._endDevice + " and FCELLCODE='" + Autotask._endCell + "'") == false) { Errtext = "终点位置和终点货位编码在数据库中没有记录!"; return false; } } #region AGV通道 if ((Autotask._enableStartCell == true) && (ccf.GetDeviceKindIdx(Convert.ToInt32(Autotask._startDevice)) == 11)) { if (dbo.Exists("SELECT F_AGVGateDeviceIndex FROM T_Base_AGV_Gate WHERE (F_ChannelsIndex = " + Autotask._startDevice + ") AND (F_AGVGateDeviceIndex = " + Autotask._startCell + ")") == false) { Errtext = "AGV站点设备在数据库中没有记录!"; return false; } } if ((Autotask._enableEndCell == true) && (ccf.GetDeviceKindIdx(Convert.ToInt32(Autotask._endDevice)) == 11)) { if (dbo.Exists("SELECT F_AGVGateDeviceIndex FROM T_Base_AGV_Gate WHERE (F_ChannelsIndex = " + Autotask._endDevice + ") AND (F_AGVGateDeviceIndex = " + Autotask._endCell + ")") == false) { Errtext = "AGV站点设备在数据库中没有记录!"; return false; } } #endregion Sql = "SELECT F_RouteID FROM T_Base_Route WHERE (F_StartDevice = " + Autotask._startDevice + ") AND (F_EndDevice = " + Autotask._endDevice + ")"; dv = dbo.ExceSQL(Sql).Tables[0].DefaultView; if (dv.Count <= 0) { Errtext = "起始位置和结束位置不在有效路径的范围内!"; return false; } _tasktype = Autotask._controlType.ToString(); string FSTARTCELL = Autotask._startCell, FENDCELL = Autotask._endCell, UseAwayFork = "-"; int FSTARTDEVICE = Convert.ToInt32(Autotask._startDevice); int FENDDEVICE = Convert.ToInt32(Autotask._endDevice); Model.MDevice devinfo = Model.CGetInfo.GetDeviceInfo(FSTARTDEVICE); int flaneway = 0; int stackno = 0; //dbo.TransBegin(); try { if (devinfo != null) { int uc = 0; if (int.TryParse(FSTARTCELL, out uc) == true) { UseAwayFork = dbo.GetSingle("SELECT F_UseAwayFork FROM T_Base_AGV_Gate WHERE ( F_AGVGateDeviceIndex= " + uc + ")").ToString(); } if ((UseAwayFork == "-") || (UseAwayFork == null)) { UseAwayFork = devinfo.DoubleFork; } } if ((UseAwayFork == "-") || (UseAwayFork == null)) {//20110412 devinfo = Model.CGetInfo.GetDeviceInfo(FENDDEVICE); if (devinfo != null) { int uc = 0; if (int.TryParse(FENDCELL, out uc) == true) { UseAwayFork = dbo.GetSingle("SELECT F_UseAwayFork FROM T_Base_AGV_Gate WHERE ( F_AGVGateDeviceIndex= " + uc + ")").ToString(); } if ((UseAwayFork == "-") || (UseAwayFork == null)) { UseAwayFork = devinfo.DoubleFork; } } } StringBuilder sbs = new StringBuilder(); int FSTARTUCODE = 0; int FENDUCODE = 0; sbs.Clear(); sbs.Append("SELECT FUCODE,FUCONVEYOR FROM ST_CELL where FCELLCODE='").Append(FSTARTCELL) .Append("' and FLaneWay=").Append(FSTARTDEVICE).Append(" and FUCODE>0"); dv = dbo.ExceSQL(sbs.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { FSTARTUCODE = Convert.ToInt32(dv[0][0]); FSTARTCELL = dv[0][1].ToString(); } sbs.Clear(); sbs.Append("SELECT FUCODE,FUCONVEYOR FROM ST_CELL where FCELLCODE='").Append(FENDCELL) .Append("' and FLaneWay=").Append(FENDDEVICE).Append(" and FUCODE>0"); dv = dbo.ExceSQL(sbs.ToString()).Tables[0].DefaultView; if (dv.Count > 0) { FENDUCODE = Convert.ToInt32(dv[0][0]); FENDCELL = dv[0][1].ToString(); } string dtime = DateTime.Now.ToString("u");//20101028 dtime = dtime.Substring(0, dtime.Length - 1);//20101028 int AutoManageIdx = ccf.GetTempManageIdx(); //if (Convert.ToInt32(dbo.GetSingle("select count(0) from T_DisPallet where f_enddevice=" + FENDDEVICE)) > 0) //{ // AutoManageIdx = Convert.ToInt32(dbo.GetSingle("select fid from t_manage_task where FPALLETBARCODE='" + Autotask._palletBarcode + "'")); //} //int AutoManageIdx = ccf.GetTempManageIdx(); //插入临时调度任务T_Manage_Task(监控下的调度任务): Sql = "insert into T_Manage_Task(FID,FPALLETBARCODE,FCONTROLTASKTYPE,F_ManageTaskKindIndex,FSTARTWAREHOUSE,FSTARTDEVICE,FSTARTCELL," + "FENDWAREHOUSE,FENDDEVICE,FENDCELL,FLANEWAY,FSTACK,FUseAwayFork,FBEGTIME,FSTARTUCODE,FENDUCODE,WORK_MODE) " + "values(" + AutoManageIdx + ",'" + Autotask._palletBarcode + "','" + _tasktype + "',1,'" + ccf.GetWarehouseIndex(FSTARTDEVICE, FSTARTCELL) + "','" + FSTARTDEVICE + "','" + FSTARTCELL + "','" + ccf.GetWarehouseIndex(FENDDEVICE, FENDCELL) + "','" + FENDDEVICE + "','" + FENDCELL + "'," + flaneway + "," + stackno + ",'" + UseAwayFork + "','" + dtime + "'," + FSTARTUCODE + "," + FENDUCODE + "," + 0 + ")";//20101028 dbo.ExecuteSql(Sql); //通知客户端更新界面 CDataChangeEventArgs cea = new CDataChangeEventArgs(null, null); OnDataChange("BuildAutoTask", cea); } catch (Exception ex) { Errtext = ex.StackTrace + ex.Message; return false; } Errtext = string.Empty; return true; } catch (Exception ex) { Errtext = ex.StackTrace + ex.Message; return false; } finally { dv.Dispose(); } } public void FindStackPallet(int StartDevice, string Batch, out int Arrow) { Arrow = 0; DataView ArrowDevice = dbo.ExceSQL("select T_STACKPALLET.*,F_LockedState from T_STACKPALLET,T_Base_Device where F_ENDDEVICE=T_Base_Device.F_DeviceIndex and F_LockedState<>-1 and T_STACKPALLET.F_STARTDEVICE=" + StartDevice + "order by f_GoAway asc").Tables[0].DefaultView; int maxgoaway = Convert.ToInt32(dbo.GetSingle("select max(f_goaway) from T_STACKPALLET,T_Base_Device where F_ENDDEVICE=T_Base_Device.F_DeviceIndex and F_LockedState<>-1 and T_STACKPALLET.F_STARTDEVICE=" + StartDevice)); if (maxgoaway >= ArrowDevice.Count && maxgoaway != 0) { dbo.ExceSQL("update T_STACKPALLET set f_goaway=0 where F_STARTDEVICE=" + StartDevice); ArrowDevice = dbo.ExceSQL("select T_STACKPALLET.*,F_LockedState from T_STACKPALLET,T_Base_Device where F_ENDDEVICE=T_Base_Device.F_DeviceIndex and F_LockedState<>-1 and T_STACKPALLET.F_STARTDEVICE=" + StartDevice + "order by f_GoAway asc").Tables[0].DefaultView; } if (ArrowDevice.Count > 0) { for (int i = 0; i < ArrowDevice.Count; i++) { if (Convert.ToInt32(dbo.GetSingle("select count(0) from t_manage_task where BATTERY_BATCH='" + Batch + "' and fenddevice=" + ArrowDevice[i]["F_ENDDEVICE"])) > 0)//先找路上是否有同批次的 { Arrow = Convert.ToInt32(ArrowDevice[i]["F_ENDDEVICE"]); return; } } for (int i = 0; i < ArrowDevice.Count; i++) { if (Convert.ToInt32(dbo.GetSingle("select count(0) from t_manage_task where fenddevice=" + ArrowDevice[i]["F_ENDDEVICE"])) == 0)//路上没有且当前叠盘机批次一致 { string nowbatch = dbo.GetSingle("select F_BATCH from T_STACKPALLET where F_ENDDEVICE=" + ArrowDevice[i]["F_ENDDEVICE"]).ToString(); if (nowbatch == Batch && nowbatch != "0") { Arrow = Convert.ToInt32(ArrowDevice[i]["F_ENDDEVICE"]); return; } } } for (int i = 0; i < ArrowDevice.Count; i++) { if (Convert.ToInt32(dbo.GetSingle("select count(0) from t_manage_task where fenddevice=" + ArrowDevice[i]["F_ENDDEVICE"])) == 0)//路上没有且没有批次的 { string nowbatch = dbo.GetSingle("select F_BATCH from T_STACKPALLET where F_ENDDEVICE=" + ArrowDevice[i]["F_ENDDEVICE"]).ToString(); if (nowbatch == "0") { Arrow = Convert.ToInt32(ArrowDevice[i]["F_ENDDEVICE"]); return; } } } for (int i = 0; i < ArrowDevice.Count; i++) { if (Convert.ToInt32(dbo.GetSingle("select count(0) from t_manage_task where fenddevice=" + ArrowDevice[i]["F_ENDDEVICE"])) == 0)//路上没有的 { if (ArrowDevice[i]["f_goaway"].ToString() == "0") { Arrow = Convert.ToInt32(ArrowDevice[i]["F_ENDDEVICE"]); dbo.ExceSQL("update T_STACKPALLET set f_goaway=" + (maxgoaway + 1) + " where F_ENDDEVICE=" + ArrowDevice[i]["F_ENDDEVICE"]); return; } } } } } } }