using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Resources; using System.Drawing; using DBFactory; using ICommLayer; using CommLayerFactory; using System.Globalization; using System.Net; using Microsoft.VisualBasic; using System.Web.UI.WebControls; using System.Linq; namespace ControlSystem { /// /// Creator:Richard.liu /// 获得设备状态类 /// /// 需要做的工作: /// 1.下位机给上位机发送设备(任务)状态信息(正在执行状态或者报警的设备所处调度路径的F_SerialNumber》=当前值) /// 2.(单独处理)下位机给上位机发送条码信息(托盘条码,烟箱一号工程码) /// 3.(单独处理)下位机给上位机发送现场控制触摸屏申请信号:1-重发当前设备指令 /// 2-申请修改当前设备所执行任务的目标位置 /// 4.跟踪货物运行到的位置(多个调度任务在执行同一个调度任务,取有探物的为当前位置) /// 并且判断是否存在提前触发任务 /// 5.获取调度任务的优先策略判断:最短路径优先, /// 入库优先携带出库,出库优先携带入库等 /// 6.任务号传递到当前设备时,把本路径的前一设备的运行锁解除, /// 同时把当前设备加运行锁 /// 7.(根据故障点单独处理)调度路径是否可用的分析以及给管理进行反馈 /// 8.(单独处理)创建自动调度任务 /// 9.动画显示设备状态 /// public class CGetState { Model.MError errs; Model.MDevice devinfo; ISendDeviceOrder sdo; IGetDeviceState gds; CCommonFunction ccf = new CCommonFunction(); DBOperator dbo1 =CStaticClass.dbo1; DBOperator dbo = CStaticClass.dbo; DBOperator dboM =CStaticClass.dboM; //20100108 CControl ccl = new CControl(); string _CGetStateError = "";//监控调度类错误说明 public string CGetStateError { get { return _CGetStateError; } set { _CGetStateError = value; } } public int[] _States; int _fid; int _mti; //int _iotype=0; //int _endnode=0; /// /// 获得所有正在执行设备的状态 /// public CGetState() { //dbo.Open(); //if (dboM.Open() == false) //{ // if (FrmControlMonitor.FormInstance.GetObjectText("tsStatus").IndexOf("连接管理数据库失败!!!") < 0) // { // FrmControlMonitor.FormInstance.FlashPanit("tsStatus", "连接管理数据库失败!!!", true); // } //} } // 放在类的顶部,静态或成员变量中 private static Dictionary _lastExecTimeDict = new Dictionary(); // 你的定时 /// /// 获得反馈信息 ///电器反馈该设备的"完成"时 删除设备指令 , 解除设备表占用状态F_LockedState=0; ///路径明细表F_LockedDeviceIndex里的所有对应设备索引解锁; /// ///判断是最后一个设备指令吗? 是,回写调度任务IO_Control的FSTATUS=2即"搬运完成"; /// T_Manage_Task的正在执行状态FSTATUS=2 ; /// /// public void GetDeviceState() { try { DataView dv=new DataView(); DataView dvm = new DataView(); //20091107 DataView dvmo = new DataView(); int devKind; int DeviceIdx; int TaskIdx=0; StringBuilder[] wv = new StringBuilder[1]{ new StringBuilder("")} ; StringBuilder[] witemnames = new StringBuilder[1] { new StringBuilder("") }; //20100617增加和管理交互虚拟设备,类型30 //20120915 DataView dd = dbo.ExceSQL("SELECT F_DeviceIndex,F_DeviceKindIndex,F_MaxSendCount,F_SendInterval FROM T_Base_Device WHERE (F_DeviceKindIndex = 1) OR (F_DeviceKindIndex = 2 ) OR (F_DeviceKindIndex = 4) OR (F_DeviceKindIndex = 7) OR (F_DeviceKindIndex = 6) OR (F_DeviceKindIndex = 30)").Tables[0].DefaultView; for (int j = 0; j < dd.Count; j++) { DateTime dt1 = DateTime.Now; DeviceIdx = Convert.ToInt32(dd[j]["F_DeviceIndex"]); devKind = Convert.ToInt32(dd[j]["F_DeviceKindIndex"]); //20100609 devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIdx); //扫码头 if (dd[j]["F_DeviceKindIndex"].ToString() == "7") { string gdata2 = CStaticClass.GetStringData(DeviceIdx); if (!string.IsNullOrEmpty(gdata2)) { string cleanStr = gdata2.Replace("\0", ""); DateTime now = DateTime.Now; // 清理超过60秒未访问的数据(防止内存增长) var keysToRemove = _lastExecTimeDict .Where(kv => (now - kv.Value).TotalSeconds > 60) .Select(kv => kv.Key) .ToList(); foreach (var key in keysToRemove) { _lastExecTimeDict.Remove(key); } // 判断是否需要执行逻辑(8秒内只触发一次) bool shouldExecute = false; if (!_lastExecTimeDict.ContainsKey(gdata2) || (now - _lastExecTimeDict[gdata2]).TotalSeconds >= 12) { _lastExecTimeDict[gdata2] = now; shouldExecute = true; } if (shouldExecute) { DataView Manage = dbo.ExceSQL($"select * from T_Manage_Task where FSTATUS=-1 and FPALLETBARCODE ='{gdata2}'").Tables[0].DefaultView; if (Manage.Count > 0) // 有可执行任务 { dbo.ExceSQL("update T_Manage_Task set FSTATUS=0 where FID=" + Convert.ToInt32(Manage[0]["FID"])); } else // 条码校验失败退出去 { //先检索有没有待执行的自动任务,没有就要退回入库口 DataView Manage2 = dbo.ExceSQL($"select * from T_Manage_Task where FSTATUS=0 and F_ManageTaskKindIndex = 2").Tables[0].DefaultView; if (Manage2.Count==0) { CreateMonitor.CreateMove(12002, 12001, 6); } } } } } else//其它类型设备 { if (CStaticClass.Order == true) { GetKindDeviceState(TaskIdx, DeviceIdx, 0); } } } dv = null; dvm = null; dvmo = null; dd = null; } catch(Exception ex) { if (FrmControlMonitor.FormInstance.GetObjectText("tsStatus").IndexOf("获取设备状态时:"+ex.Message) < 0) { FrmControlMonitor.FormInstance.FlashPanit("tsStatus", "获取设备状态时:" + ex.Message, true); } //throw ex; } } /// /// 设备报告空闲 /// /// public void ActionIdle(int DeviceIdx) { } /// /// 报告完成 ///电器反馈该设备的"完成"时 删除设备指令 , 解除设备表占用状态F_LockedState=0; ///路径明细表F_LockedDeviceIndex里的所有对应设备索引解锁 /// ///判断是最后一个设备指令吗? 是,回写调度任务IO_Control的FSTATUS=2即"搬运完成"; /// T_Manage_Task的正在执行状态FSTATUS=2 ; /// /// 设备索引 /// 设备指令索引 ///是否向设备发送清零命令:1清零;900撤销整个调度任务;999手工报告调度任务完成 public void ActionComplete(int DeviceIdx,int TaskIdx,int ClearZero) { if (TaskIdx == 0) return; devinfo=Model.CGetInfo.GetDeviceInfo(DeviceIdx); int devKind = ccf.GetDeviceKindIdx(DeviceIdx); //20100305 int[] zxy = ccf.GetCoordinatesFromMonitorTask(TaskIdx); string zxystr = ""; if (zxy != null) { zxystr = (zxy[3].ToString().Length ==1 ? "0" + zxy[3].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 order = ccf.GetDeviceOrderFromMonitor(TaskIdx); if (order == -1) { _CGetStateError = "电器反馈的调度任务号没有记忆!"; return; } if (GetManage_Kind(TaskIdx) == false) return; int errrcode= ccf.GetExceptionNOFromManageTask(_fid,_mti ); int ControlType=ccf.GetFCONTROLTASKTYPEFromManageTask(_mti,_fid); //20100710 int AgvNextDeviceKind = 0; if ((devKind == 6)&&(order==2)) { AgvNextDeviceKind = ccf.GetDeviceKindIdx(zxy[4]); } //20100108 DataView dvman; DataView dv; DataView dvlane; DataView Inv = null; string dtime; // #region 出库优先携带入库优先策略的处理或者入库优先携带出库优先策略的处理(入出库交替) int Pri = ccf.SelectTaskPriPrecept(); //20091016 if (((Pri == 21) || (Pri == 12)) && (devKind == 1) && (ccf.GetFCONTROLTASKTYPEFromManageTask(_mti, _fid) == 2))//堆垛机出库优先并且携带入库任务 { string mansql = "select * from T_Manage_Task where FTASKLEVEL=10 and FSTACK = " + DeviceIdx + " AND (FCONTROLTASKTYPE = 1) AND (FIntoStepOK = '1') "; //20100108 dvman=dbo.ExceSQL(mansql).Tables[0].DefaultView ; if (dvman.Count <= 0) { mansql = "SELECT FID, F_ManageTaskKindIndex, FCONTROLTASKTYPE FROM T_Manage_Task WHERE (FSTACK = " + DeviceIdx + ") AND (FCONTROLTASKTYPE = 1) AND (FIntoStepOK = '1') order by FTASKLEVEL desc, F_ManageTaskKindIndex desc,FID asc"; dvman = dbo.ExceSQL(mansql).Tables[0].DefaultView; for (int ii = 0; ii < dvman.Count; ii++) { string sql = "select * from T_Monitor_Task where F_ManageTASKKINDINDEX=" + dvman[ii]["F_ManageTASKKINDINDEX"] + " and F_ManageTaskIndex=" + dvman[ii]["FID"] + " order by F_MonitorIndex asc"; //20100108 dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { int stackkind = ccf.GetDeviceKindIdx(Convert.ToInt32(dv[0]["F_DeviceIndex"])); if (stackkind == 1) { dbo.ExceSQL("update T_Monitor_Task set F_MonitorTaskLevel=10 where F_ManageTASKKINDINDEX=" + dvman[ii]["F_ManageTASKKINDINDEX"] + " and F_ManageTaskIndex=" + dvman[ii]["FID"] + ""); dbo.ExceSQL("update T_Manage_Task set FTASKLEVEL=10 where F_ManageTASKKINDINDEX=" + dvman[ii]["F_ManageTASKKINDINDEX"] + " and FID=" + dvman[ii]["FID"] + ""); break; } } } } } #endregion //dbo.TransBegin(); try { int fid = _fid; int mti = _mti; string cap; //20101011 #region 补充逻辑预约锁的解锁(此调度任务的此设备的最后一个命令需要解锁,有关联任务的改为关联任务预约) if ((devKind == 1) || (devKind == 4)) { object ob = dbo.GetSingle("select count(F_MonitorIndex) as counts from T_Monitor_Task " + " where F_ManageTaskIndex =" + fid + " and F_ManageTaskKindIndex= " + mti + " and F_DeviceIndex=" + DeviceIdx); if (Convert.ToInt32(ob) == 1) { #region 有管理任务存在,增加关联任务预约锁//20100710 ob = dbo.GetSingle("SELECT T_Manage_Task.FID FROM T_Manage_Task ,T_Monitor_Task where T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX AND T_Manage_Task.FID = T_Monitor_Task.F_ManageTaskIndex and (T_Manage_Task.F_RELATIVECONTORLID = " + fid + ") AND (T_Manage_Task.F_ManageTaskKindIndex = " + mti + ") and F_DeviceIndex=" + DeviceIdx + ""); if (ob != null) { dbo.ExceSQL("update T_Base_Device set F_ManTaskReserve=" + (mti.ToString() + ob.ToString()) + " where F_ManTaskReserve=" + (mti.ToString() + fid.ToString()) + " and F_DeviceIndex=" + DeviceIdx); } else { dbo.ExceSQL("update T_Base_Device set F_ManTaskReserve=0 where F_ManTaskReserve=" + (mti.ToString() + fid.ToString()) + " and F_DeviceIndex=" + DeviceIdx); } #endregion } } #endregion //20100108 dv = dbo.ExceSQL("select count(F_MonitorIndex) as counts from T_Monitor_Task " + " where F_ManageTaskIndex =" + fid + " and F_ManageTaskKindIndex= " + mti).Tables[0].DefaultView; if (dv.Count > 0) { #region 最后一个调度任务的处理 if ((Convert.ToInt32(dv[0]["counts"]) == 1)) //20091016 { //固定路径模式 //调度任务的fid的最后一个监控分解任务完成 if (mti == 1) { if (CObtainTask.IsInv == 1)//盘库 { CObtainTask.IsInv = 0; Inv = dbo.ExceSQL($"SELECT COUNT(*) AS count,FMANAGEID FROM T_Manage_Task WHERE FMANAGEID = (SELECT FMANAGEID FROM T_Manage_Task WHERE FID = {fid}) GROUP BY FMANAGEID").Tables[0].DefaultView; cap = "调度任务"; //完成FSTATUS=999;970堆垛机送货重故障异常完成;980堆垛机取空故障异常完成;990条码扫描异常完成; //调度撤销删除调度任务900;950送到拆盘机的不是空托盘组;940人工暂停出库任务 //20090902 if (errrcode >= 900)//异常完成 { if (errrcode == Model.CGeneralFunction.TASKDELETE) ClearZero = errrcode; else if (errrcode == Model.CGeneralFunction.TASKREPEATINPUT) errrcode = Model.CGeneralFunction.TASKREPEATINPUT;//聊城修改,以前是Model.CGeneralFunction.TASKFINISH else if (errrcode == Model.CGeneralFunction.TASKEMPTYOUTPUT) dboM.ExceSQL("update IO_Control set ERROR_TEXT='堆垛机取空故障异常完成' where CONTROL_ID=" + fid); else if (errrcode == Model.CGeneralFunction.TASKABEND) dboM.ExceSQL("update IO_Control set ERROR_TEXT='异常完成' where CONTROL_ID=" + fid); else if (errrcode == Model.CGeneralFunction.TASKTYPEERROR) dboM.ExceSQL("update IO_Control set ERROR_TEXT='送到拆盘机的不是空托盘组' where CONTROL_ID=" + fid); else if (errrcode == Model.CGeneralFunction.TASKSTOPOUTPUT) dboM.ExceSQL("update IO_Control set ERROR_TEXT='人工暂停出库任务' where CONTROL_ID=" + fid); //20100304 switch (CStaticClass.ManDBFactory) { case "OracleDBFactory": dboM.ExceSQL("update IO_Control set CONTROL_END_TIME =sysdate, CONTROL_STATUS=" + errrcode + " where CONTROL_ID=" + fid); break; case "SQLServerDBFactory": dboM.ExceSQL("update IO_Control set CONTROL_END_TIME =GETDATE(), CONTROL_STATUS=" + errrcode + " where CONTROL_ID=" + fid); break; case "OleDBFactory": dtime = DateTime.Now.ToString("u"); dtime = dtime.Substring(0, dtime.Length - 1); dboM.ExceSQL("update IO_Control set CONTROL_END_TIME ='" + dtime + "', CONTROL_STATUS=" + errrcode + " where CONTROL_ID=" + fid); break; } } else if (errrcode != Model.CGeneralFunction.TASKCHANGEFORK)//20110525 { //完成FSTATUS=999 switch (CStaticClass.ManDBFactory) { case "OracleDBFactory": dboM.ExceSQL("update IO_Control set CONTROL_END_TIME =sysdate, CONTROL_STATUS=" + Model.CGeneralFunction.TASKFINISH + " where CONTROL_ID=" + fid); break; case "SQLServerDBFactory": if ((zxy[0] == 12043) && (zxy[3] == 18007 || zxy[3] == 12049 || zxy[3] == 12054)) { dboM.ExceSQL("update IO_Control set CONTROL_END_TIME =GETDATE(), CONTROL_STATUS=" + Model.CGeneralFunction.TASKPACKFINISH + ",END_DEVICE_CODE=" + zxy[3] + " where CONTROL_ID=" + fid); } else if (zxy[0] == 32080 && order == 7) { dboM.ExceSQL("update IO_Control set CONTROL_END_TIME =GETDATE(), CONTROL_STATUS=" + Model.CGeneralFunction.TASKUNPACKFINISH + " where CONTROL_ID=" + fid); } else { if (Inv.Count>0) { int taskID = Convert.ToInt32(Inv[0]["FMANAGEID"]); dboM.ExceSQL("update IO_Control set CONTROL_END_TIME =GETDATE(), CONTROL_STATUS=" + Model.CGeneralFunction.TASKFINISH + " where CONTROL_ID=" + taskID); CreateMonitor.WcsToManageTaskOver(taskID); } } break; case "OleDBFactory": dtime = DateTime.Now.ToString("u"); dtime = dtime.Substring(0, dtime.Length - 1); dboM.ExceSQL("update IO_Control set CONTROL_END_TIME ='" + dtime + "', CONTROL_STATUS=" + Model.CGeneralFunction.TASKFINISH + " where CONTROL_ID=" + fid); break; } } } else { cap = "调度任务"; //完成FSTATUS=999;970堆垛机送货重故障异常完成;980堆垛机取空故障异常完成;990条码扫描异常完成; //调度撤销删除调度任务900;950送到拆盘机的不是空托盘组;940人工暂停出库任务 //20090902 if (errrcode >= 900)//异常完成 { if (errrcode == Model.CGeneralFunction.TASKDELETE) ClearZero = errrcode; else if (errrcode == Model.CGeneralFunction.TASKREPEATINPUT) errrcode = Model.CGeneralFunction.TASKREPEATINPUT;//聊城修改,以前是Model.CGeneralFunction.TASKFINISH else if (errrcode == Model.CGeneralFunction.TASKEMPTYOUTPUT) dboM.ExceSQL("update IO_Control set ERROR_TEXT='堆垛机取空故障异常完成' where CONTROL_ID=" + fid); else if (errrcode == Model.CGeneralFunction.TASKABEND) dboM.ExceSQL("update IO_Control set ERROR_TEXT='异常完成' where CONTROL_ID=" + fid); else if (errrcode == Model.CGeneralFunction.TASKTYPEERROR) dboM.ExceSQL("update IO_Control set ERROR_TEXT='送到拆盘机的不是空托盘组' where CONTROL_ID=" + fid); else if (errrcode == Model.CGeneralFunction.TASKSTOPOUTPUT) dboM.ExceSQL("update IO_Control set ERROR_TEXT='人工暂停出库任务' where CONTROL_ID=" + fid); //20100304 switch (CStaticClass.ManDBFactory) { case "OracleDBFactory": dboM.ExceSQL("update IO_Control set CONTROL_END_TIME =sysdate, CONTROL_STATUS=" + errrcode + " where CONTROL_ID=" + fid); break; case "SQLServerDBFactory": dboM.ExceSQL("update IO_Control set CONTROL_END_TIME =GETDATE(), CONTROL_STATUS=" + errrcode + " where CONTROL_ID=" + fid); break; case "OleDBFactory": dtime = DateTime.Now.ToString("u"); dtime = dtime.Substring(0, dtime.Length - 1); dboM.ExceSQL("update IO_Control set CONTROL_END_TIME ='" + dtime + "', CONTROL_STATUS=" + errrcode + " where CONTROL_ID=" + fid); break; } } else if (errrcode != Model.CGeneralFunction.TASKCHANGEFORK)//20110525 { //完成FSTATUS=999 switch (CStaticClass.ManDBFactory) { case "OracleDBFactory": dboM.ExceSQL("update IO_Control set CONTROL_END_TIME =sysdate, CONTROL_STATUS=" + Model.CGeneralFunction.TASKFINISH + " where CONTROL_ID=" + fid); break; case "SQLServerDBFactory": if ((zxy[0] == 12043) && (zxy[3] == 18007 || zxy[3] == 12049 || zxy[3] == 12054)) { dboM.ExceSQL("update IO_Control set CONTROL_END_TIME =GETDATE(), CONTROL_STATUS=" + Model.CGeneralFunction.TASKPACKFINISH + ",END_DEVICE_CODE=" + zxy[3] + " where CONTROL_ID=" + fid); } else if (zxy[0] == 32080 && order == 7) { dboM.ExceSQL("update IO_Control set CONTROL_END_TIME =GETDATE(), CONTROL_STATUS=" + Model.CGeneralFunction.TASKUNPACKFINISH + " where CONTROL_ID=" + fid); } else { dboM.ExceSQL("update IO_Control set CONTROL_END_TIME =GETDATE(), CONTROL_STATUS=" + Model.CGeneralFunction.TASKFINISH + " where CONTROL_ID=" + fid); CreateMonitor.WcsToManageTaskOver(fid); } break; case "OleDBFactory": dtime = DateTime.Now.ToString("u"); dtime = dtime.Substring(0, dtime.Length - 1); dboM.ExceSQL("update IO_Control set CONTROL_END_TIME ='" + dtime + "', CONTROL_STATUS=" + Model.CGeneralFunction.TASKFINISH + " where CONTROL_ID=" + fid); break; } } } } else if (mti == 4) { cap = "手工任务"; } else { cap = "临时任务"; } if ((errrcode == Model.CGeneralFunction.TASKCHANGEFORK)&&(devKind==1)&&(devinfo.IfCorrelDoubleFork=="1"))//20101011换货叉处理 { //解除关联任务,更换货叉,追加两个任务,倒库位取货,送到真实货位,管理任务的FExceptionNO==null AppendMoveCellOperate(mti, fid, DeviceIdx, TaskIdx); } else {//20101011 //回写管理表//20091128 if ((ClearZero == Model.CGeneralFunction.TASKDELETE) || (ClearZero == Model.CGeneralFunction.TASKSTOPOUTPUT))//调度撤销删除调度任务900;人工暂停出库任务940 { ReturnManageInfo(fid, mti, cap, false); } else { ReturnManageInfo(fid, mti, cap, true); } } } #endregion } //被这个任务号锁定的设备全部解锁 dbo.ExceSQL("update T_Base_Device set F_LockedState=0 where F_LockedState=" + TaskIdx); dbo.ExceSQL("update T_Base_Device set F_CreateLock='0' where F_DeviceIndex=" + DeviceIdx); if (ClearZero != Model.CGeneralFunction.TASKDELETE)//20100710删除调度任务不置逻辑有物 { //堆垛机接货输送机完成时逻辑无货20100710 dvlane = dbo.ExceSQL("SELECT F_LaneGateDeviceIndex FROM T_Base_Lane_Gate where F_LaneGateDeviceIndex=" + DeviceIdx).Tables[0].DefaultView; if (dvlane.Count > 0) { dbo.ExceSQL("update T_Base_Device set F_HaveGoods=0 where F_DeviceIndex=" + DeviceIdx + " and F_HaveGoods=1"); } else {//AGV接货输送机完成时逻辑无货20100710 dvlane = dbo.ExceSQL("SELECT F_AGVGateDeviceIndex FROM T_Base_AGV_Gate where F_AGVGateDeviceIndex=" + DeviceIdx).Tables[0].DefaultView; if (dvlane.Count > 0) { dbo.ExceSQL("update T_Base_Device set F_HaveGoods=0 where F_DeviceIndex=" + DeviceIdx); } } } #region 堆垛机、AGV逻辑有物的处理20101011 if (ClearZero != Model.CGeneralFunction.TASKDELETE)//删除调度任务不置为逻辑有物 { if ((devKind == 1) && ((order == 4) || (order == 5) || (order == 6)))//20101011 { bool sh = false;//20101011 bool qh = false;//20101011 if (order == 5) sh = true;//20101011 if (order == 4) qh = true;//20101011 if (order == 6)//20101011 { sh = true; qh = true; } if (sh == true)//20101011 { //20090918给堆垛机送货的输送机增加逻辑有物 ////20100609改为使用巷道表关联 dvlane = dbo.ExceSQL("SELECT T_Base_Lane_Gate.F_LaneGateDeviceIndex from T_Base_Lane_Gate,T_Base_LaneInfo " + " where T_Base_Lane_Gate.F_LaneIndex = T_Base_LaneInfo.F_LaneDeviceIndex and T_Base_Lane_Gate.F_ZXY='" + zxystr + "' " + " and T_Base_LaneInfo.F_StackIndex=" + DeviceIdx).Tables[0].DefaultView; if (dvlane.Count > 0) { dbo.ExceSQL("update T_Base_Device set F_HaveGoods=1 where F_DeviceIndex=" + dvlane[0]["F_LaneGateDeviceIndex"]); } } if (qh == true)//在输送机取货,置输送机逻辑无物//20101011 { zxystr = (zxy[0].ToString().Length == 1 ? "0" + zxy[0].ToString() : zxy[0].ToString()) + "-" + ((zxy[1].ToString().Length == 1) ? ("0" + zxy[1].ToString()) : (zxy[1].ToString())) + "-" + ((zxy[2].ToString().Length == 1) ? ("0" + zxy[2].ToString()) : (zxy[2].ToString())); dvlane = dbo.ExceSQL("SELECT T_Base_Lane_Gate.F_LaneGateDeviceIndex from T_Base_Lane_Gate,T_Base_LaneInfo " + " where T_Base_Lane_Gate.F_LaneIndex = T_Base_LaneInfo.F_LaneDeviceIndex and T_Base_Lane_Gate.F_ZXY='" + zxystr + "' " + " and T_Base_LaneInfo.F_StackIndex=" + DeviceIdx).Tables[0].DefaultView; if (dvlane.Count > 0) { dbo.ExceSQL("update T_Base_Device set F_HaveGoods=0 where F_DeviceIndex=" + dvlane[0]["F_LaneGateDeviceIndex"]); dbo.ExecuteSql("update T_Base_PLC_Ask set F_TaskIndex=0,F_Remark='' where F_DeviceIndex=" + dvlane[0]["F_LaneGateDeviceIndex"]);//20101011 } } } else if ((devKind == 6) && (order == 2)&&(AgvNextDeviceKind==2))//AGV向输送机放货20100710 { dbo.ExceSQL("update T_Base_Device set F_HaveGoods=1 where F_DeviceIndex=" + zxy[4]); } } #endregion //dbo.TransCommit(); //给PLC发送应答头是2,其余都是零 //根据设备类型判断错误编号 //ISendDeviceOrder sdo; if (ClearZero == 1) { if ((devKind == 4) || (devKind == 2)) {//输送机、RGV故障清零 sdo = CommModeCreate.CreateSendDeviceOrder(DeviceIdx); sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0); } if ((devKind == 1)) //堆垛机 { sdo = CommModeCreate.CreateSendDeviceOrder(DeviceIdx); sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0, 0, 0, 0, 0, 0); } if (mti == 1) { dboM.ExceSQL("UPDATE IO_CONTROL SET ERROR_TEXT ='' WHERE CONTROL_ID=" + fid + " and CONTROL_STATUS<900"); } } if ((ccf.GetCorrel_DeviceIndex(DeviceIdx)==0) && (ControlType == 1)) { // dbo.ExecuteSql("update T_Base_PLC_Ask set F_TaskIndex=0,F_Remark='' where (F_DeviceIndex=" + DeviceIdx + ")"); } //20101220 每次叠盘任务完成时更新叠盘机条码信息 if (zxy != null && (zxy[3] == 12076 || zxy[3] == 12082 || zxy[3] == 12088 || zxy[3] == 22049 || zxy[3] == 32069)) { dbo.ExecuteSql("update T_Base_PLC_Ask set F_BarCode=F_BarCode +'" + ccf.GetBarCodeFromMonitor(TaskIdx) + "' where (F_BindingDevice=" + DeviceIdx + ")"); } //2013 记录完成的monitor dbo.ExceSQL("insert into t_bak_monitor_task select * from T_Monitor_Task where F_MonitorIndex=" + TaskIdx); dbo.ExceSQL("update T_BAK_Monitor_Task set F_EndTime ='" + DateTime.Now.ToString("u") + "' where F_MonitorIndex=" + TaskIdx); dbo.ExceSQL("delete from T_Monitor_Task where F_MonitorIndex=" + TaskIdx); } catch (Exception ex) { //dbo.TransRollback(); if (FrmControlMonitor.FormInstance.GetObjectText("tsStatus").IndexOf("报告完成时:" + ex.Message) < 0) { FrmControlMonitor.FormInstance.FlashPanit("tsStatus", "报告完成时:" + ex.Message, true); } //throw ex; } finally {//20100108 dvman=null ; dv=null ; dvlane=null ; } } /// /// 处理由于多线程产生死锁的SQL语句 /// public void ActionDeadLock() {//20100108 DataView dv; try { dv = dbo.ExceSQL("select * from T_DeadLock where f_flag=0 order by f_id asc").Tables[0].DefaultView; for (int i = 0; i < dv.Count; i++) { try { dbo.ExceSQL(dv[i]["f_SQL"].ToString()); dbo.ExceSQL("update T_DeadLock set f_flag=1 where f_id=" + dv[i]["f_id"] + ""); } catch { continue; } } }//20100108 catch (Exception ex) { throw ex; } finally { dv = null; } } /// /// 回写设备错误状态字(IO_Control,T_Manage_Task,T_Monitor_task) /// /// 设备索引 /// 设备指令索引 /// 错误编号 public void ActionError(int DeviceIdx, int TaskIdx,int ErrId) { //dbo.TransBegin(); //20100108 DataView dvmon; DataTable dt; DataView dv0; DataView dvm; //DataView dvIO; //DataRowView dr; //DataView DV; //DataView dvc; try { //090915 // string monsql = "SELECT F_MonitorIndex FROM T_Monitor_Task where F_Status =1 and F_DeviceIndex =" + DeviceIdx; //modify by zx 20121011 string monsql = "SELECT F_MonitorIndex FROM T_Monitor_Task where F_DeviceIndex =" + DeviceIdx; //20100108 dvmon = dbo.ExceSQL(monsql).Tables[0].DefaultView; if ((dvmon.Count > 0) && (TaskIdx == 0)) { TaskIdx = Convert.ToInt32(dvmon[0]["F_MonitorIndex"]); } //090915 //有过记录的故障设备的任务号,不再重复处理 string devstr = "SELECT F_DeviceIndex FROM T_Base_Device where F_DeviceIndex=" + DeviceIdx + " and F_ErrorTaskNo=" + TaskIdx + ""; //20100108 dt = dbo.ExceSQL(devstr).Tables[0]; if (dt.Rows.Count >= 1) { dbo.ExceSQL("update T_Monitor_Task set F_Status= " + ErrId + " where (F_MonitorIndex= " + TaskIdx + ") and ((F_Status<> " + ErrId + ") and (F_Status<> 3))"); return; } devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIdx); int devKind = ccf.GetDeviceKindIdx(DeviceIdx); if (GetManage_Kind(TaskIdx) == false) return; int fid = _fid; int mti = _mti; //string fwarehouse = ""; //string fcode = ""; //int flane = 0; errs = Model.CGetInfo.GetErrorInfo(Convert.ToInt32(devKind.ToString() + ErrId.ToString())); if (errs!=null && errs.ErrorIndex > 0) { //20100108 #region 报警时控制摄像头,并且用设备索引加锁 /* //摄像头设备类型29;每个设备的F_LocalPort代表摄像头设备索引(id);F_RemotePort代表摄像头划分的区域值(index)(1--12) //检查F_LocalPort代表摄像头设备索引的F_LockedState=0就把报警设备索引填入F_LockedState,否则不处理 int ic = dbo.ExecuteSql("update T_Base_Device set F_LockedState=" + DeviceIdx + " where F_DeviceIndex=" + devinfo.LocalPort + " and F_LockedState=0"); if (ic == 1) { string hrs = "http://" + CStaticClass.CameraIP + "/camera/ptz?command=preset&id=" + devinfo.LocalPort + "&index=" + devinfo.RemotePort + "&username=" + CStaticClass.CameraUsername + "&password=" + CStaticClass.CameraPassword; HttpWebRequest myReq =(HttpWebRequest)WebRequest.Create(hrs); myReq = null; } */ #endregion FrmMain.FormInstance.notifyIcon1.BalloonTipText = "警告:" +devinfo.DeviceName+","+ DeviceIdx + "发生故障:" + errs.ErrorName; FrmMain.FormInstance.notifyIcon1.ShowBalloonTip(10000, "警告", devinfo.DeviceName + "," + DeviceIdx + "发生故障:" + errs.ErrorName, System.Windows.Forms.ToolTipIcon.Warning); if (mti == 1) { dboM.ExceSQL("update IO_Control set ERROR_TEXT='" + devinfo.DeviceName + "," + DeviceIdx + errs.ErrorName + "' where CONTROL_ID=" + fid); } //20100108 dv0 = dbo.ExceSQL("SELECT F_DeviceIndex, F_ErrorIndex FROM T_Base_Device_Error_Log Where F_ManageTaskNo=" + fid + " and F_DeviceIndex=" + DeviceIdx + " and F_ErrorIndex=" + errs.ErrorIndex).Tables[0].DefaultView; string dtime = DateTime.Now.ToString("u");//20110603 dtime = dtime.Substring(0, dtime.Length - 1); if (dv0.Count > 0) {//20091107 dbo.ExceSQL("UPDATE T_Base_Device_Error_Log SET F_DateTime ='" + dtime + "' Where F_DeviceIndex=" + DeviceIdx + " and F_ErrorIndex=" + errs.ErrorIndex + " and F_ManageTaskNo=" + fid); } else { dbo.ExceSQL("INSERT INTO T_Base_Device_Error_Log (F_ManageTaskNo,F_DeviceIndex, F_ErrorIndex, F_DateTime) VALUES (" + fid + "," + DeviceIdx + "," + errs.ErrorIndex + ",'" + dtime + "')"); } } //20090925 #region 2240进的不是空托盘组 //&& (mti == 1) //if ((DeviceIdx == 2240)) //{ // if ((ErrId == 49)) // { // #region 如果调度任务rgv送货指令存在,不接受报警 // if (ccf.GetMonitorFromAssociate(TaskIdx) > 0) return; // #endregion // //2246,2243,2203,2212送回到2246 // //先把起点设备和货位改为2240,终点位置改为原来位置,然后重新拆分任务,最后报告完成 // string FSTARTDEVICE = "", FSTARTCELL = "", FENDDEVICE = "", FENDCELL = ""; // //20100108 // dvm = dbo.ExceSQL("SELECT * FROM T_Manage_Task where F_ManageTaskKindIndex=" + mti + " and FID=" + fid).Tables[0].DefaultView; // if (dvm.Count > 0) // { // if ((dvm[0]["FSTARTDEVICE"].ToString() == "2246") || (dvm[0]["FSTARTDEVICE"].ToString() == "2243") || (dvm[0]["FSTARTDEVICE"].ToString() == "2212") || (dvm[0]["FSTARTDEVICE"].ToString() == "2203")) // { // FSTARTDEVICE = "2246"; // FSTARTCELL = "-"; // } // else // { // FSTARTDEVICE = dvm[0]["FSTARTDEVICE"].ToString(); // FSTARTCELL = dvm[0]["FSTARTCELL"].ToString(); // } // FENDDEVICE = dvm[0]["FENDDEVICE"].ToString(); // FENDCELL = dvm[0]["FENDCELL"].ToString(); // } // else // { // return; // } // dbo.ExceSQL("update T_Base_Device set F_LockedState=0 where F_LockedState=" + TaskIdx); // dbo.ExceSQL("update T_Base_Device set F_CreateLock='0' where F_DeviceIndex=" + DeviceIdx); // dbo.ExceSQL("delete from T_Monitor_Task where F_MonitorIndex=" + TaskIdx); // dbo.ExceSQL("update T_Manage_Task set FCONTROLTASKTYPE=1,FSTATUS=0,FIntoStepOK='0',FENDDEVICE='" + FSTARTDEVICE + "',FENDCELL='" + FSTARTCELL + "',FSTARTDEVICE=2240,FSTARTCELL='-',FExceptionNO=" + Model.CGeneralFunction.TASKTYPEERROR + " where F_ManageTaskKindIndex=" + mti + " and FID=" + fid); // } //} #endregion //if (errs == null) if (errs == null) { errs = new Model.MError(); errs.ErrorName = "故障代码 " + ErrId + "未定义"; } //20090915 dbo.ExceSQL("update T_Monitor_Task set F_Status= " + ErrId + " where F_MonitorIndex= " + TaskIdx + " and (F_Status<> 3)"); //记录发生故障的设备正在执行的任务号 dbo.ExceSQL("update T_Base_Device set F_ErrorTaskNo= " + TaskIdx + " where F_DeviceIndex= " + DeviceIdx); dbo.ExceSQL("update T_Manage_Task set FERRORCODE='" + devinfo.DeviceName + "," + DeviceIdx + errs.ErrorName + "' where F_ManageTaskKindIndex=" + mti + " and FID=" + fid); if (CStaticClass.DeviceErrorAutoModifyRoutePath == "1") {//20091107 #region 堆垛机异常处理(取空和送重) if ((devKind == 1)&& (mti == 1))//堆垛机、调度任务//20100710重新定义双叉故障 { int rfid=-1; object obr = dbo.GetSingle("SELECT F_RELATIVECONTORLID FROM T_Manage_Task WHERE (FID = " + fid + ") AND (F_ManageTaskKindIndex = " + mti + ") and (F_RELATIVECONTORLID<>-1)"); if (obr != null) { rfid = Convert.ToInt32(obr); } string errAwayfork = "0"; if ((ErrId == Model.CGeneralFunction.STACKEMPTYOUTPUT) || (ErrId == Model.CGeneralFunction.STACKREPEATINPUT)) { errAwayfork = "0"; } if ((ErrId == Model.CGeneralFunction.STACKEMPTYOUTPUTAWAY) || (ErrId == Model.CGeneralFunction.STACKREPEATINPUTAWAY)) { errAwayfork = "1"; } if ((ErrId == Model.CGeneralFunction.STACKEMPTYOUTPUTDOUBLE) || (ErrId == Model.CGeneralFunction.STACKREPEATINPUTDOUBLE)) { errAwayfork = "-"; } #region 堆垛机的送货重//20100710 //43 放货时货架有货(近叉),近叉任务送出口,远叉任务报告完成 //60 放货时货架有货(远叉),远叉任务送出口,近叉任务报告完成 //61 放货时货架有货(双叉),双叉任务送出口 if ((ErrId == Model.CGeneralFunction.STACKREPEATINPUT) || (ErrId == Model.CGeneralFunction.STACKREPEATINPUTAWAY) || (ErrId == Model.CGeneralFunction.STACKREPEATINPUTDOUBLE)) { //堆垛机的送货重需要改路径处理48;异常完成970 #region 延吉版 //#region 堆垛机的送货重需要改路径处理 ////20091107 ////20100108 //dvIO = dboM.ExceSQL("select CONTROL_ID, CONTROL_STATUS from IO_Control where (CONTROL_ID = " + fid + ") AND ((CONTROL_STATUS=" + Model.CGeneralFunction.TASKREPEATINPUT + ") or (CONTROL_STATUS=" + Model.CGeneralFunction.TASKALTERROUTEREPLY + "))").Tables[0].DefaultView; //if (dvIO.Count <= 0) //{ // //向管理申请修改任务 // //20100108 // dvm = dbo.ExceSQL("select * from T_Manage_Task WHERE (FID = " + fid + ") AND (F_ManageTASKKINDINDEX =" + mti + ")").Tables[0].DefaultView; // if (dvm.Count > 0) // { // fwarehouse = dvm[0]["FWAREHOUSE"].ToString(); // flane = Convert.ToInt32(dvm[0]["FLANEWAY"]); // fcode = dvm[0]["FENDCELL"].ToString(); // if (ccf.QueryCellIfExit(fwarehouse, flane, fcode) == true) // { // //20091128 // //20100108 // dr = dvm[0]; // //20100108 // //DV = dboM.ExceSQL("select IO_CONTROL_APPLY_SEQ.NEXTVAL FROM DUAL").Tables[0].DefaultView; // int id = dboM.GetManageTableIndex("IO_CONTROL_APPLY"); // string dtime = DateTime.Now.ToString("u"); // dtime = dtime.Substring(0, dtime.Length - 1); // dboM.TransBegin(); // try // { // if (CStaticClass.ManDBFactory == "OracleDBFactory") // { // dboM.ExceSQL("update IO_Control set CONTROL_STATUS=" + Model.CGeneralFunction.TASKREPEATINPUT + ",ERROR_TEXT='" + DeviceIdx + errs.ErrorName + ";原货位:" + "'||END_DEVICE_CODE where CONTROL_ID=" + fid); // } // else // { // dboM.ExceSQL("update IO_Control set CONTROL_STATUS=" + Model.CGeneralFunction.TASKREPEATINPUT + ",ERROR_TEXT='" + DeviceIdx + errs.ErrorName + ";原货位:" + "'+END_DEVICE_CODE where CONTROL_ID=" + fid); // } // string sql = "INSERT INTO IO_CONTROL_APPLY (CONTROL_APPLY_ID, CONTROL_ID,CONTROL_APPLY_TYPE, WAREHOUSE_CODE, STOCK_BARCODE, DEVICE_CODE,APPLY_TASK_STATUS, FCREATETIME, FREMARK)" + // "VALUES (" + id + "," + dr["FID"] + ",2,'" + dr["FENDWAREHOUSE"] + "','" + dr["FPALLETBARCODE"] + "','" + dr["FENDDEVICE"] + "',0,'" + dtime + "',null)"; // dboM.ExceSQL(sql); // dboM.TransCommit(); // dbo.ExceSQL("update T_Manage_Task set FExceptionNO=" + Model.CGeneralFunction.TASKREPEATINPUT + ",FERRORCODE='" + DeviceIdx + errs.ErrorName + ";原货位:" + "'+ FENDCELL where (F_ManageTaskKindIndex = " + mti + ") AND (FID = " + fid + ")"); // //把ManageTaskIdx,ManageKindIdx 的调度任务全部申请改道 // dbo.ExceSQL("UPDATE T_Monitor_Task SET F_Status = 3 WHERE (F_ManageTaskIndex = " + fid + ") AND (F_ManageTASKKINDINDEX =" + mti + ")"); // } // catch (Exception ex) // { // _CGetStateError = "堆垛机送货时发生送重故障,改道时:" + ex.Message; // dboM.TransRollback(); // } // } // } //}//20091107 //#endregion #endregion #region 聊城版 //先清零,删除故障任务,解除lockstate,然后直接改道出口,如果是远叉任务,则到1442,近叉则到1441 //System.Threading.Thread.Sleep(3000); //20100710 int[] zxy = ccf.GetCoordinatesFromMonitorTask(TaskIdx); string zxystr = ""; if (zxy != null) { //堆垛机送货坐标 zxystr = (zxy[3].ToString().Length == 1 ? "0" + zxy[3].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())); } dvm = dbo.ExceSQL("SELECT F_ZXY FROM T_Base_Lane_Gate WHERE (F_ZXY = '" + zxystr + "')").Tables[0].DefaultView; if (dvm.Count > 0) {//巷道的出入口输送机对应的货位不处理送空报警 return; } if ((ErrId == Model.CGeneralFunction.STACKREPEATINPUT) || (ErrId == Model.CGeneralFunction.STACKREPEATINPUTAWAY)) { DataView dvr = dbo.ExceSQL("SELECT F_ManageTaskIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = " + fid + ") AND (F_ManageTaskKindIndex = " + mti + ") AND (F_UseAwayFork = '" + errAwayfork + "')").Tables[0].DefaultView; if (dvr.Count <= 0) { dvr = dbo.ExceSQL("SELECT FID FROM T_Manage_Task,T_Monitor_Task WHERE (F_RELATIVECONTORLID = " + fid + ") AND (T_Monitor_Task.F_ManageTaskKindIndex = " + mti + ") AND (F_UseAwayFork = '" + errAwayfork + "') AND (T_Monitor_Task.F_ManageTaskKindIndex=T_Manage_Task.F_ManageTaskKindIndex) AND (FID=F_ManageTaskIndex)").Tables[0].DefaultView; if (dvr.Count > 0) { //关联任务报警:双叉同步任务时自己报告完成 //if (Model.CGeneralFunction.DoubleForkIfSync(TaskIdx, DeviceIdx, 1) == true) //{ // ActionComplete(DeviceIdx, TaskIdx, 1); //} fid = Convert.ToInt16(dvr[0]["FID"]); } else { return; } } else {//自己报警:双叉同步任务的关联任务报告完成 //if (Model.CGeneralFunction.DoubleForkIfSync(TaskIdx, DeviceIdx, 1) == true) //{ // string[] df = Model.CGeneralFunction.GetDoubleForkMonitorInfo(TaskIdx, DeviceIdx); // if (df != null) // { // ActionComplete(DeviceIdx, Convert.ToInt32(df[0]), 1); // } //} } } sdo = CommModeCreate.CreateSendDeviceOrder(DeviceIdx); sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0, 0, 0, 0, 0, 0); AA: //堆垛机的送货重,只保留堆垛机的送货任务 //是应急站台,把原来的终点改为起点改道至应急站台 //删除任务后报告异常完成970 if (CStaticClass.ManDBFactory == "OracleDBFactory") { dboM.ExceSQL("update IO_Control set CONTROL_STATUS=" + Model.CGeneralFunction.TASKREPEATINPUT + ",ERROR_TEXT='" + DeviceIdx + errs.ErrorName + ";原货位:" + "'||END_DEVICE_CODE where CONTROL_ID=" + fid); } else { dboM.ExceSQL("update IO_Control set CONTROL_STATUS=" + Model.CGeneralFunction.TASKREPEATINPUT + ",ERROR_TEXT='" + DeviceIdx + errs.ErrorName + ";原货位:" + "'+END_DEVICE_CODE where CONTROL_ID=" + fid); } dbo.ExceSQL("update T_Monitor_Task set F_STATUS=3 where F_ManageTaskKindIndex=" + mti + " and F_ManageTaskIndex=" + fid ); dbo.ExceSQL("update T_Manage_Task set FExceptionNO=" + Model.CGeneralFunction.TASKREPEATINPUT + ",FERRORCODE= '"+devinfo.DeviceName + "," + DeviceIdx + errs.ErrorName+",原货位: '+FENDCELL where (F_ManageTaskKindIndex = " + mti + ") AND (FID = " + fid + ")"); if ((ErrId == Model.CGeneralFunction.STACKREPEATINPUTDOUBLE)) { if (rfid != -1) { fid = rfid; rfid = -1; goto AA; } } #endregion } #endregion #region 堆垛机的取空处理//20100710 //46 取货后货叉无货(近叉),近叉任务删除,远叉任务报告完成 //62 取货后货叉无货(远叉),远叉任务删除,近叉任务报告完成 //63 取货后货叉无货(双叉),双叉任务删除 if ((ErrId == Model.CGeneralFunction.STACKEMPTYOUTPUTDOUBLE) || (ErrId == Model.CGeneralFunction.STACKEMPTYOUTPUTAWAY) || (ErrId == Model.CGeneralFunction.STACKEMPTYOUTPUT)) { //20100710 int[] zxy = ccf.GetCoordinatesFromMonitorTask(TaskIdx); string zxystr = ""; if (zxy != null) { //堆垛机取货坐标 zxystr = (zxy[0].ToString().Length == 1 ? "0" + zxy[0].ToString() : zxy[0].ToString()) + "-" + ((zxy[1].ToString().Length == 1) ? ("0" + zxy[1].ToString()) : (zxy[1].ToString())) + "-" + ((zxy[2].ToString().Length == 1) ? ("0" + zxy[2].ToString()) : (zxy[2].ToString())); } dvm = dbo.ExceSQL("SELECT F_ZXY FROM T_Base_Lane_Gate WHERE (F_ZXY = '"+zxystr+"')").Tables[0].DefaultView; if (dvm.Count > 0) {//巷道的出入口输送机对应的货位不处理取空报警 return; } if ((ErrId == Model.CGeneralFunction.STACKEMPTYOUTPUTAWAY) || (ErrId == Model.CGeneralFunction.STACKEMPTYOUTPUT)) { DataView dvr = dbo.ExceSQL("SELECT F_ManageTaskIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = " + fid + ") AND (F_ManageTaskKindIndex = " + mti + ") AND (F_UseAwayFork = '" + errAwayfork + "')").Tables[0].DefaultView; if (dvr.Count <= 0) { dvr = dbo.ExceSQL("SELECT FID FROM T_Manage_Task,T_Monitor_Task WHERE (F_RELATIVECONTORLID = " + fid + ") AND (T_Monitor_Task.F_ManageTaskKindIndex = " + mti + ") AND (F_UseAwayFork = '" + errAwayfork + "') AND (T_Monitor_Task.F_ManageTaskKindIndex=T_Manage_Task.F_ManageTaskKindIndex) AND (FID=F_ManageTaskIndex)").Tables[0].DefaultView; if (dvr.Count > 0) { //关联任务报警:双叉同步任务时自己报告完成 if (Model.CGeneralFunction.DoubleForkIfSync(TaskIdx, DeviceIdx, 1) == true) { ActionComplete(DeviceIdx, TaskIdx, 1); } //关联任务报警 fid = Convert.ToInt16(dvr[0]["FID"]); } else { return; } } else { //自己报警:双叉同步任务的关联任务报告完成 if (Model.CGeneralFunction.DoubleForkIfSync(TaskIdx, DeviceIdx, 1) == true) { string[] df = Model.CGeneralFunction.GetDoubleForkMonitorInfo(TaskIdx, DeviceIdx); if (df != null) { ActionComplete(DeviceIdx, Convert.ToInt32(df[0]), 1); } } } } sdo = CommModeCreate.CreateSendDeviceOrder(DeviceIdx); sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0, 0, 0, 0, 0, 0); BB: //删除任务后报告异常完成980 dbo.ExceSQL("update T_Monitor_Task set F_STATUS=-1 where F_ManageTaskKindIndex=" + mti + " and F_ManageTaskIndex=" + fid + " and F_STATUS=0"); dbo.ExceSQL("update T_Manage_Task set FExceptionNO=" + Model.CGeneralFunction.TASKEMPTYOUTPUT + " where (F_ManageTaskKindIndex = " + mti + ") AND (FID = " + fid + ")"); //20100108 dvm = dbo.ExceSQL("select * from T_Monitor_Task WHERE (F_ManageTaskIndex = " + fid + ") AND (F_ManageTASKKINDINDEX =" + mti + ")").Tables[0].DefaultView; for (int i = 0; i < dvm.Count; i++) {//20091023 ActionComplete(Convert.ToInt32(dvm[i]["F_DeviceIndex"]), Convert.ToInt32(dvm[i]["F_MonitorIndex"]), Model.CGeneralFunction.TASKDELETE); } if (ErrId == Model.CGeneralFunction.STACKEMPTYOUTPUTDOUBLE) { if (rfid != -1) { fid = rfid; rfid = -1; goto BB; } } } #endregion } #endregion } if (devinfo.UseCommonDB == "1") { return; } //if (((devKind == 2) || (devKind == 4))) //{//输送机故障清零 // sdo = CommModeCreate.CreateSendDeviceOrder(DeviceIdx); // sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0); //} //if ((devKind == 1)) //堆垛机 //{ // sdo = CommModeCreate.CreateSendDeviceOrder(DeviceIdx); // sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0, 0, 0, 0, 0, 0); //} } catch (Exception ex) { //dbo.TransRollback(); if (FrmControlMonitor.FormInstance.GetObjectText("tsStatus").IndexOf("向管理反馈设备错误时:" + ex.Message) < 0) { FrmControlMonitor.FormInstance.FlashPanit("tsStatus", "向管理反馈设备错误时:" + ex.Message, true); } //throw ex; } finally {//20100108 dvmon=null; dt = null; dv0 = null; dvm = null; //dvIO = null; //dr = null; //DV = null; //dvc = null; } } /// /// 设备开始运行: /// 1-根据任务号和探物情况判断任务执行的位置回写本地管理表 /// 2-回写调度任务表的开始执行状态 /// 3-判断是否存在提前触发任务 /// /// /// 设备索引 /// 调度任务号 public void ActionStartRun(int DeviceIdx, int TaskIdx) { if (TaskIdx <= 0) return; int mti = ccf.GetManageTaskIndexfromMonitor(TaskIdx); int mtikind = ccf.GetManageTaskKindIndexFromMonitor(TaskIdx); //dbo.TransBegin(); //DataView dvma; //DataView dvma1; DataView dvlane; DataView dv; try { #region 修改调度任务状态 dbo.ExceSQL("update T_Monitor_Task set F_Status=2 where F_Status=1 and F_MonitorIndex=" + TaskIdx); #endregion #region 根据任务号和探物情况判断任务执行的位置回写本地管理表 dbo.ExceSQL("update T_Manage_Task set FCurrentLocation=" + DeviceIdx + " where F_ManageTaskKindIndex=" + mtikind + " and FID=" + mti + ""); //调度任务表也记录当前位置,主要是给输送机链用 dbo.ExceSQL("update T_Monitor_Task set F_CurrentLocation=" + DeviceIdx + " where F_MonitorIndex=" + TaskIdx); //设备逻辑有物 //20090918给堆垛机送货的输送机逻辑有物解锁F_HaveGoods=0 //20100108 dvlane = dbo.ExceSQL("SELECT F_LaneGateDeviceIndex FROM T_Base_Lane_Gate where F_LaneGateDeviceIndex=" + DeviceIdx).Tables[0].DefaultView; if (dvlane.Count > 0 || DeviceIdx == 12010) { if (DeviceIdx == 12010) { dbo.ExceSQL("update T_Base_Device set F_HaveGoods=0 where F_DeviceIndex=12012 and F_HaveGoods = 1"); } else { dbo.ExceSQL("update T_Base_Device set F_HaveGoods=0 where F_DeviceIndex=" + DeviceIdx); } } else {//20100710 dvlane = dbo.ExceSQL("SELECT F_AGVGateDeviceIndex FROM T_Base_AGV_Gate where F_AGVGateDeviceIndex=" + DeviceIdx).Tables[0].DefaultView; if (dvlane.Count > 0) { dbo.ExceSQL("update T_Base_Device set F_HaveGoods=0 where F_DeviceIndex=" + DeviceIdx); } } #endregion //dbo.TransCommit(); //RefreshControlMonitor(DeviceIdx); //20091107 if (CStaticClass.MovedDeviceAheadTrigger == "1") { #region 判断是否存在提前触发任务(设备号-调度任务号) //当设备运行时,触发调度任务号运行F_AheadTrigger //20100108 dv = dbo.ExceSQL("select F_AheadTrigger from T_Monitor_Task " + "where F_MonitorIndex=" + TaskIdx + " and F_AheadTrigger like '" + DeviceIdx.ToString() + "-" + "%'").Tables[0].DefaultView; if (dv.Count > 0) { //发送提前触发的命令调度任务 char[] cc = new char[1] { '-' }; string[] sp = dv[0]["F_AheadTrigger"].ToString().Split(cc); if (sp.GetLength(0) > 0) { int TriTask = Convert.ToInt32(sp[1]); //20100108 CControl ccl = new CControl(); if (ccl.SendMonitorTask(TriTask) == true) { //清除触发命令 dbo.ExceSQL("update T_Monitor_Task set F_AheadTrigger ='' where F_MonitorIndex=" + TaskIdx); } } } #endregion } #region 把TaskIdx的前一设备解锁;把自己加锁 //dbo.ExceSQL("update T_Base_Device set F_LockedState=0 where F_LockedState=" + TaskIdx); //dbo.ExceSQL("update T_Base_Device set F_LockedState="+TaskIdx+" where F_DeviceIndex=" + DeviceIdx); #endregion //zhangxy 聊城 当输送机运转时,给管理报一个状态 为12. //if ((DeviceIdx == 2141 || DeviceIdx == 2142 || DeviceIdx == 3141 || DeviceIdx == 3142) && (mtikind == 1)) //{ // dboM.ExceSQL("update IO_CONTROL set CONTROL_STATUS=12 where CONTROL_ID=" + mti); //} //20101220,当叠盘机执行送出指令时,置该任务完成 // if (DeviceIdx == 12076 || DeviceIdx == 12082 || DeviceIdx == 12088 || DeviceIdx == 22049 || DeviceIdx == 32069) if (DeviceIdx == 22049 || DeviceIdx == 32069 || DeviceIdx == 32080)//2层叠盘机和3层叠盘机,拆盘机,送出指令执行时即完成。 { int DeviceOrder = ccf.GetDeviceOrderFromMonitor(TaskIdx); if(DeviceOrder==6) { int endindex=ccf.GetEndTransDevice(DeviceIdx, TaskIdx); if (endindex>0) { ActionComplete(endindex,TaskIdx, 0); } } } if (DeviceIdx == 12074 || DeviceIdx == 12080 || DeviceIdx == 12086)//1层数据采集输送机,反转指令执行时即完成。 { //int DeviceOrder = ccf.GetDeviceOrderFromMonitor(TaskIdx); //if (DeviceOrder == 2) //{ // ActionComplete(DeviceIdx, TaskIdx, 0); //} } #region RGV调度策略 #region 4301入库携带出库 //4218称重出入口 //4211-4212出库;4207-4208出库;4203-4204出库; //4210-4209入库;4206-4205入库;4202-4201入库; //if (DeviceIdx == 4301) //{ // if (ccf.GetFCONTROLTASKTYPEFromManageTask(mtikind, mti) == 1) // { // //判断是否有出库任务被携带(终点到4220,优先级是9,第一个动作是输送机的送货命令) // //20100108 // dvma = dbo.ExceSQL("SELECT T_Manage_Task.F_ManageTaskKindIndex, T_Manage_Task.FID, T_Monitor_Task.F_MonitorIndex" + // " FROM T_Manage_Task ,T_Monitor_Task WHERE T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX " + // "AND T_Manage_Task.FID = T_Monitor_Task.F_ManageTaskIndex and T_Monitor_Task.F_MonitorTaskLevel = 9 and FENDDEVICE=4220 and " + // "FCONTROLTASKTYPE=2 and FSTATUS =2").Tables[0].DefaultView; // if (dvma.Count <= 0) // { // //不存在被携带的RGV出库任务,分配一个携带任务 // //20100108 // dvma1 = dbo.ExceSQL("SELECT T_Manage_Task.F_ManageTaskKindIndex, T_Manage_Task.FID " + // " FROM T_Manage_Task WHERE FENDDEVICE=4220 and " + // "FCONTROLTASKTYPE=2 and FSTATUS =2").Tables[0].DefaultView; // for (int i = 0; i < dvma1.Count; i++) // { // DataView dvmo = dbo.ExceSQL("SELECT F_MonitorIndex,F_DeviceIndex,F_DeviceCommandIndex FROM T_Monitor_Task " + // "where F_ManageTaskIndex=" + dvma1[i]["FID"] + " and F_ManageTASKKINDINDEX=" + dvma1[i]["F_ManageTaskKindIndex"] + // " and F_MonitorTaskLevel <> 9 order by F_MonitorIndex asc").Tables[0].DefaultView; // if (dvmo.Count > 0) // { // if ((dvmo[0]["F_DeviceCommandIndex"].ToString() == "3") && (ccf.GetDeviceKindIdx(Convert.ToInt32(dvmo[0]["F_DeviceIndex"])) == 2)) // { // dbo.ExceSQL("update T_Monitor_Task set F_MonitorTaskLevel=9 where F_ManageTaskIndex=" + dvma1[i]["FID"] + " and F_ManageTASKKINDINDEX=" + dvma1[i]["F_ManageTaskKindIndex"] + ""); // break; // } // } // } // } // } //} #endregion #endregion } catch (Exception ex) { _CGetStateError = "ControlSystem.CGetState发生错误:" + ex.Message; //dbo.TransRollback(); } finally {//20100108 //dvma = null; //dvma1 = null; dvlane = null; dv = null; } } public bool GetManage_Kind(int taskidx) {//20100108 DataSet ds; try { //CCommonFunction ccf=new CCommonFunction(); ds = dbo.ExceSQL("SELECT F_ManageTaskIndex, F_ManageTaskKindIndex, F_MonitorIndex FROM T_Monitor_Task Where F_MonitorIndex=" + taskidx); if (ds.Tables[0].DefaultView.Count > 0) { _fid = Convert.ToInt32(ds.Tables[0].DefaultView[0]["F_ManageTaskIndex"]); _mti = Convert.ToInt32(ds.Tables[0].DefaultView[0]["F_ManageTaskKindIndex"]); //if (_mti == 1) //{ // DataView dv = dbo.ExceSQL("SELECT FID, F_ManageTaskKindIndex, FCONTROLTASKTYPE, FENDDEVICE FROM T_Manage_Task where FID=" + _fid + " and F_ManageTaskKindIndex=" + _mti).Tables[0].DefaultView; // if (dv.Count > 0) // { // _endnode = Convert.ToInt32(dv[0]["FENDDEVICE"]); // _iotype = Convert.ToInt32(ccf.GetIOType(dv[0]["FCONTROLTASKTYPE"].ToString())); // } //} return true; } else { return false; } } catch (Exception ex) { throw ex; } finally {//20100108 ds = null; } } /// /// 判断此设备上是否有物体在搬运 /// /// 设备索引 /// public bool DevcieIfHaveGoods(int deviceIdx) { devinfo = Model.CGetInfo.GetDeviceInfo(deviceIdx); if (devinfo.BindingDevice!=null) { switch (devinfo.DeviceKind) { case 1://5,6 break; case 2://1,2,3 break; case 3: break; case 4: break; default: break; } //获取设备探物光电的值1,0 if (CStaticClass.GetDevicePhotoelectric(Convert.ToInt32(devinfo.BindingDevice)) == 1) { return true; } else { return false; } } else { return false; } } /// /// 是否需要软确认 /// /// 调度任务类型 /// 调度任务索引 /// public bool IfSoftConfirm(int mti, int fid) { try { DataSet ds = dbo.ExceSQL("SELECT FID,F_ManageTaskKindIndex,FCONTROLTASKTYPE, FCODE,FSOFTCONFIRM FROM T_Manage_Task,T_ITEMTASKTYPE where FCONTROLTASKTYPE =FCODE and FSOFTCONFIRM='1' and F_ManageTaskKindIndex=" + mti + " and FID= " + fid); if (ds.Tables[0].DefaultView.Count > 0) { return true; } else { return false; } } catch (Exception ex) { throw ex; } } public void SetStackPalletTask(int FMANAGEID) { try { //把FMANAGEID(一个码放托盘对应一个FMANAGEID)的码盘任务置成未拆分状态 dbo.ExceSQL("update T_Manage_Task set FIntoStepOK='0' where FIntoStepOK='-' and FMANAGEID=" +FMANAGEID); } catch (Exception ex) { throw ex; } } //刷新监控中心显示 public void RefreshControlMonitor(int devidx) {//_States[5] == DeviceIdx try { if (CStaticClass.RealRefresh == true) { //显示设备指令 DataSet ds = dbo1.ExceSQL("select * from V_Monitor_Task where " +CStaticClass.Monstatus); FrmControlMonitor.FormInstance.MonitorRefresh(ds.Tables[0].DefaultView); //显示调度任务 FrmControlMonitor.FormInstance.ManagerRefresh( dbo1.ExceSQL("select * from V_Manage_Task where "+CStaticClass.Manstatus).Tables[0].DefaultView); } //显示动画 DataSet dsD = dbo1.ExceSQL("SELECT F_DeviceIndex,F_DeviceKindIndex,F_BindingDevice FROM T_Base_Device where F_DeviceIndex=" + devidx); DataView DvD = dsD.Tables[0].DefaultView; if (DvD.Count > 0) { switch (Convert.ToInt32(DvD[0]["F_DeviceKindIndex"])) { case 1://堆垛机 FlashStack(Convert.ToInt32(DvD[0]["F_DeviceIndex"])); break; case 4://RGV穿梭车 FlashRGV(Convert.ToInt32(DvD[0]["F_DeviceIndex"])); break; case 6://AGV/LGV FlashAGV(Convert.ToInt32(DvD[0]["F_DeviceIndex"])); break; default://其它设备 FlashElseDevice(Convert.ToInt32(DvD[0]["F_DeviceIndex"])); break; } //if ((DvD[0]["F_BindingDevice"] != DBNull.Value) && ((DvD[0]["F_BindingDevice"].ToString().Trim() != "")))//有捆绑设备 //{ // FlashBindDevice(DvD[0]["F_BindingDevice"].ToString()); //} } } catch (Exception ex) { throw ex; } } //2字任务号,5字设备号 public void FlashStack(int devindex) { try { if (_States == null) return; char[] cc=new char[1]{';'}; string[] split; string strflag; int laneno; int x; string strGet; strGet = GetControl_Picture(devindex); if (strGet != "") { split = strGet.Split(cc); } else//不用图像显示 { return; } if (_States == null) return; if (_States[1] >= 30)//故障 { strflag = "Err"; } else if (_States[1] == 1)//完成 { strflag = ""; } else//运行 { strflag = "Goods"; } ////////////////////////////// /////////////////////////////// //第4字:堆垛机x坐标,列-沿轨道方向.当大于或等于16时是2#巷道,小于16时是1#巷道 //应该在T_Base_StackInfo找到巷道编号 if (_States[3] >= 16)//2#巷道 { laneno = 2; x=_States[3]-16; } else//1#巷道 { laneno = 1; x=15-_States[3]; } ResourceManager rm = new ResourceManager("ControlSystem.Properties.Resources", this.GetType().Assembly); char[] dot = new char[1] { '.'}; string[] picfile = split[1].Split(dot); FrmControlMonitor.FormInstance.FlashPanit(split[0], (System.Drawing.Image)rm.GetObject(strflag + picfile[0])); DataSet ds = dbo.ExceSQL("select * from t_base_LaneInfo where F_LaneDeviceIndex="+laneno ); DataView dv = ds.Tables[0].DefaultView; if (dv.Count > 0) { FrmControlMonitor.FormInstance.FlashPanit(split[0],Convert.ToInt32(dv[0]["F_LeftY"]),(Convert.ToInt32(dv[0]["F_LeftX"]) + x * Convert.ToInt32(dv[0]["F_ShelfWidth"]))); } } catch (Exception ex) { if (FrmControlMonitor.FormInstance.GetObjectText("tsStatus").IndexOf("堆垛机动画模拟时:" + ex.Message) < 0) { FrmControlMonitor.FormInstance.FlashPanit("tsStatus", "堆垛机动画模拟时:" + ex.Message, true); } //throw ex; } } public void FlashAGV(int devindex) { try { char[] cc = new char[1] { ';' }; string[] split; string strflag; string strGet; strGet = GetControl_Picture(devindex); if (strGet != "") { split = strGet.Split(cc); } else//不用图像显示 { return; } if (_States[1] >= 30)//故障 { strflag = "Err"; } else if (_States[1] == 1)//完成 { strflag = ""; } else//运行 { strflag = "Goods"; } ResourceManager rm = new ResourceManager("ControlSystem.Properties.Resources", this.GetType().Assembly); char[] dot = new char[1] { '.' }; string[] picfile = split[1].Split(dot); FrmControlMonitor.FormInstance.FlashPanit(split[0], (System.Drawing.Image)rm.GetObject(strflag + picfile[0])); DataSet ds = dbo.ExceSQL("select * from T_Base_AGV_Gate where F_Address='" + _States[3] +"'"); DataView dv = ds.Tables[0].DefaultView; if (dv.Count > 0) { FrmControlMonitor.FormInstance.FlashPanit(split[0],Convert.ToInt32(dv[0]["F_Top"]), Convert.ToInt32(dv[0]["F_Left"])); } FrmControlMonitor.FormInstance.FlashPanit(split[0],System.Windows.Forms.ImageLayout.Stretch); } catch (Exception ex) { if (FrmControlMonitor.FormInstance.GetObjectText("tsStatus").IndexOf("AGV动画模拟时:" + ex.Message) < 0) { FrmControlMonitor.FormInstance.FlashPanit("tsStatus", "AGV动画模拟时:" + ex.Message, true); } //throw ex; } } public void FlashRGV(int devindex) { try { char[] cc = new char[1] { ';' }; string[] split; string strflag; string strGet; strGet = GetControl_Picture(devindex); if (strGet != "") { split = strGet.Split(cc); } else//不用图像显示 { return; } if (_States[1] >= 30)//故障 { strflag = "Err"; } else if (_States[1] == 1)//完成 { strflag = ""; } else//运行 { strflag = "Goods"; } ResourceManager rm = new ResourceManager("ControlSystem.Properties.Resources", this.GetType().Assembly); char[] dot = new char[1] { '.' }; string[] picfile = split[1].Split(dot); FrmControlMonitor.FormInstance.FlashPanit(split[0],(System.Drawing.Image)rm.GetObject(strflag + picfile[0])); DataSet ds = dbo.ExceSQL("select * from T_Base_RGV_Gate where F_Address='" + _States[3] + "'"); DataView dv = ds.Tables[0].DefaultView; if (dv.Count > 0) { FrmControlMonitor.FormInstance.FlashPanit(split[0],Convert.ToInt32(dv[0]["F_Top"]), Convert.ToInt32(dv[0]["F_Left"])); } FrmControlMonitor.FormInstance.FlashPanit(split[0],System.Windows.Forms.ImageLayout.Stretch); } catch (Exception ex) { if (FrmControlMonitor.FormInstance.GetObjectText("tsStatus").IndexOf("RGV动画模拟时:" + ex.Message) < 0) { FrmControlMonitor.FormInstance.FlashPanit("tsStatus", "RGV动画模拟时:" + ex.Message, true); } //throw ex; } } public void FlashElseDevice(int devindex) { try { char[] cc = new char[1] { ';' }; string[] split; string strflag; string strGet; strGet = GetControl_Picture(devindex); if (strGet != "") { split = strGet.Split(cc); } else//不用图像显示 { return; } if (_States == null) return; if (_States[1] >= 10)//故障 { strflag = "Err"; } else if ((_States[1] == 1) || (_States[1] == 2) || (_States[1] == 3) || (_States[1] == 4) || (_States[1] ==5 ) || (_States[1] ==6 ) || (_States[1] ==7 ) || (_States[1] ==8 ))//完成 { strflag = ""; } else//运行 { strflag = "Goods"; } ResourceManager rm = new ResourceManager("ControlSystem.Properties.Resources", this.GetType().Assembly); char[] dot = new char[1] { '.' }; string[] picfile = split[1].Split(dot); FrmControlMonitor.FormInstance.FlashPanit(split[0],(System.Drawing.Image)rm.GetObject(strflag + picfile[0])); } catch (Exception ex) { if (FrmControlMonitor.FormInstance.GetObjectText("tsStatus").IndexOf("设备动画模拟时:" + ex.Message) < 0) { FrmControlMonitor.FormInstance.FlashPanit("tsStatus", "设备动画模拟时:" + ex.Message, true); } //throw ex; } } public void FlashBindDevice(string BindDevice) { try { char[] cc = new char[1] { ';' }; string[] split = BindDevice.Split(cc); string StrGet; string[] pic; int[] States; ResourceManager rm = new ResourceManager("ControlSystem.Properties.Resources", this.GetType().Assembly); char[] dot = new char[1] { '.' }; string[] picfile; for (int i = split.GetLowerBound(0); i <= split.GetUpperBound(0); i++) { StrGet = GetControl_Picture(Convert.ToInt32(split[i])); if (StrGet != "") { pic = StrGet.Split(cc); picfile = pic[1].Split(dot); gds = CommModeCreate.CreateGetDeviceState(Convert.ToInt32(split[i])); States = gds.GetDeviceState(Convert.ToInt32(split[i]), 64777);//1完成,2任务号,5设备号 if (States != null) { if (States[0] == 1) { FrmControlMonitor.FormInstance.FlashPanit(pic[0], true); FrmControlMonitor.FormInstance.FlashPanit(pic[0], (System.Drawing.Image)rm.GetObject(picfile[0])); } else { FrmControlMonitor.FormInstance.FlashPanit(pic[0], false); } } else { FrmControlMonitor.FormInstance.FlashPanit(pic[0],false); } } } } catch (Exception ex) { throw ex; } } /// /// F_ControlName监控画面对应的控件名称;F_Picture设备空闲时的图片名 /// /// /// public string GetControl_Picture(int devindex) { try { string data; DataSet ds = dbo.ExceSQL("SELECT F_DeviceIndex, F_Picture, F_ControlName FROM T_Base_Device Where F_DeviceIndex =" + devindex + " and F_DeviceVisual=1 "); if (ds.Tables[0].DefaultView.Count > 0) { data = ds.Tables[0].DefaultView[0]["F_ControlName"].ToString() + ";" + ds.Tables[0].DefaultView[0]["F_Picture"].ToString(); } else { data = ""; } return data; } catch (Exception ex) { throw ex; } } /// /// 判断是否为此路径中该设备的最后一个命令 /// /// 路径索引 /// 设备索引 /// 命令索引 /// public bool IFDeviceLastOrder(int DetailIdx,int DevIdx,int order) { char[] cc = new char[1] { ';' }; string[] split; DataView dv = dbo.ExceSQL("SELECT F_DetailIndex,F_DeviceIndex, F_Orders FROM T_Base_Route_Detail Where F_DeviceIndex=" + DevIdx + " and F_DetailIndex="+DetailIdx ).Tables[0].DefaultView; if (dv.Count > 0) { if (dv[0]["F_Orders"].ToString().IndexOf(';') >= 0) { split = dv[0]["F_Orders"].ToString().Split(cc); if (order ==Convert.ToInt32( split[split.GetUpperBound(0)])) { return true; } else return false; } else { return true; } } else { return false; } } public string GetDetailIndexFromMonitor(int taskIdx) { DataView dv = dbo.ExceSQL("select F_DetailIndex,F_DeviceCommandIndex from T_Monitor_Task where F_MonitorIndex=" + taskIdx).Tables[0].DefaultView; if (dv.Count > 0) { return dv[0]["F_DetailIndex"].ToString() + "-" + dv[0]["F_DeviceCommandIndex"].ToString(); } else return ""; } public void ReturnManageInfo(int fid, int mti, string cap, bool IFOK) { string dtime = DateTime.Now.ToString("u");//20101028 dtime = dtime.Substring(0, dtime.Length - 1);//20101028 char[] cc = new char[1] { '-' }; string[] fcc; DataView dv; try { //200906240111增加货位记录:入库1-结束位置有货;出库2-起始位置无货;倒库3-起始位置无货,结束位置有货 //20100108 dv = dbo.ExceSQL("SELECT * FROM T_Manage_Task where F_ManageTaskKindIndex=" + mti + " and FID=" + fid + "").Tables[0].DefaultView; if (dv.Count > 0) { if (IFOK == true) { switch (dv[0]["FCONTROLTASKTYPE"].ToString()) { case "1": if (dv[0]["FENDCELL"].ToString().IndexOf("-")>0)//20100905 { fcc = dv[0]["FENDCELL"].ToString().Split(cc); dbo.ExceSQL("UPDATE ST_CELL SET FRUNSTATUS=0,FCELLSTATUS = 1,FPALLETBARCODE='" + dv[0]["FPALLETBARCODE"] + "' WHERE (FLaneWay=" + dv[0]["FENDDEVICE"] + " and F_Z='" + fcc[0] + "' and F_X='" + fcc[1] + "' and F_Y='" + fcc[2] + "')"); } break; case "2": // if (CStaticClass.StopTestLane == true) { if (dv[0]["FSTARTCELL"].ToString().IndexOf("-") > 0)//20100905 { fcc = dv[0]["FSTARTCELL"].ToString().Split(cc); dbo.ExceSQL("UPDATE ST_CELL SET FRUNSTATUS=0,FCELLSTATUS =0,FPALLETBARCODE='-' WHERE (FLaneWay=" + dv[0]["FSTARTDEVICE"] + " and F_Z=" + fcc[0] + " and F_X=" + fcc[1] + " and F_Y=" + fcc[2] + ")"); } } break; case "3": if (CStaticClass.StopTestLane == true) { if (dv[0]["FENDCELL"].ToString().IndexOf("-") > 0)//20100905 { fcc = dv[0]["FENDCELL"].ToString().Split(cc);//FRUNSTATUS=0, dbo.ExceSQL("UPDATE ST_CELL SET FCELLSTATUS = 1,FPALLETBARCODE='" + dv[0]["FPALLETBARCODE"] + "' WHERE (FLaneWay=" + dv[0]["FENDDEVICE"] + " and F_Z=" + fcc[0] + " and F_X=" + fcc[1] + " and F_Y=" + fcc[2] + ")"); } if (dv[0]["FSTARTCELL"].ToString().IndexOf("-") > 0)//20100905 { fcc = dv[0]["FSTARTCELL"].ToString().Split(cc);//FRUNSTATUS=0, dbo.ExceSQL("UPDATE ST_CELL SET FCELLSTATUS =0,FPALLETBARCODE='-' WHERE (FLaneWay=" + dv[0]["FSTARTDEVICE"] + " and F_Z=" + fcc[0] + " and F_X=" + fcc[1] + " and F_Y=" + fcc[2] + ")"); } } else {//巷道内测试 string nextcell = GetNextCell((int)dv[0]["FLANEWAY"], dv[0]["FSTARTCELL"].ToString(),dv[0]["FENDCELL"].ToString()); string cell = ""; int laneway = (int)dv[0]["FLANEWAY"]; if (nextcell.Contains(";") == true) { char[] ccc = new char[1] { ';' }; string[] sp = nextcell.Split(ccc); cell = sp[1]; laneway = Convert.ToInt32(sp[0]); } else { cell = nextcell; } int AutoManageIdx = ccf.GetTempManageIdx(); //插入临时调度任务T_Manage_Task(监控下的调度任务): //ccf.RecordMaxTempManageTaskFID(AutoManageIdx); dbo.ExceSQL("INSERT INTO T_Manage_Task(FID, F_ManageTaskKindIndex, FCONTROLTASKTYPE," + " FSTARTDEVICE, FSTARTCELL, FENDDEVICE, FENDCELL, FLANEWAY, FSTACK)VALUES " + "(" + AutoManageIdx + ",2,3,'" + dv[0]["FLANEWAY"] + "','" + dv[0]["FENDCELL"].ToString() + "','" + laneway + "','" + cell + "'," + laneway + "," + dv[0]["FSTACK"] + ")"); ccf.SetRunStatus(ccf.GetWarehouseIndex(), Convert.ToInt32(dv[0]["FLANEWAY"]), dv[0]["FENDCELL"].ToString(), "1"); ccf.SetRunStatus(ccf.GetWarehouseIndex(), laneway, cell, "1"); } break; default: break; } //if (CStaticClass.TestTemp == true) //{ // //测试时把入库任务根据FISRETURN直接出库 // if (dv[0]["FCONTROLTASKTYPE"].ToString() == "1") // { // int AutoManageIdx = ccf.GetTempManageIdx(); // //插入临时调度任务T_Manage_Task(监控下的调度任务): // //ccf.RecordMaxTempManageTaskFID(AutoManageIdx); // dbo.ExceSQL("INSERT INTO T_Manage_Task(FID,FPALLETBARCODE, F_ManageTaskKindIndex, FCONTROLTASKTYPE, FWAREHOUSE," + // " FSTARTDEVICE, FSTARTCELL, FENDDEVICE, FENDCELL, FLANEWAY, FSTACK)VALUES " + // "(" + AutoManageIdx + ",'" + dv[0]["FPALLETBARCODE"] + "',2,2,12," + dv[0]["FLANEWAY"] + ",'" + dv[0]["FENDCELL"].ToString() + // "'," + dv[0]["FISRETURN"] + ",'-'," + dv[0]["FLANEWAY"] + "," + dv[0]["FSTACK"] + ")"); // } //} //20101028 dbo.ExceSQL("update T_Manage_Task set FSTATUS=999,FENDTIME='"+dtime+"' where FID=" + fid + " and F_ManageTaskKindIndex= " + mti); //add by zx 20121213 当正常完成任务时如果为送入叠盘机的任务,记录送入表的箱条码 int enddevice = Convert.ToInt32(dv[0]["FENDDEVICE"]); RecordBarCodeForDiePan(fid, enddevice); SendMsgtoLamp(fid); //add by zx 20121213 当正常完成任务时如果为送入叠盘机的任务,记录送入表的箱条码 } else { switch (dv[0]["FCONTROLTASKTYPE"].ToString()) { case "1": if (dv[0]["FENDCELL"].ToString().IndexOf("-") > 0)//20100905 { fcc = dv[0]["FENDCELL"].ToString().Split(cc); dbo.ExceSQL("UPDATE ST_CELL SET FRUNSTATUS=0,FPALLETBARCODE='' WHERE (FLaneWay=" + dv[0]["FENDDEVICE"] + " and F_Z='" + fcc[0] + "' and F_X='" + fcc[1] + "' and F_Y='" + fcc[2] + "')"); } break; case "2": if (dv[0]["FSTARTCELL"].ToString().IndexOf("-") > 0)//20100905 { fcc = dv[0]["FSTARTCELL"].ToString().Split(cc); dbo.ExceSQL("UPDATE ST_CELL SET FRUNSTATUS=0,FPALLETBARCODE='" + dv[0]["FPALLETBARCODE"] + "' WHERE (FLaneWay=" + dv[0]["FSTARTDEVICE"] + " and F_Z=" + fcc[0] + " and F_X=" + fcc[1] + " and F_Y=" + fcc[2] + ")"); } break; case "3": if (dv[0]["FENDCELL"].ToString().IndexOf("-") > 0)//20100905 { fcc = dv[0]["FENDCELL"].ToString().Split(cc); dbo.ExceSQL("UPDATE ST_CELL SET FRUNSTATUS=0,FPALLETBARCODE='' WHERE (FLaneWay=" + dv[0]["FENDDEVICE"] + " and F_Z=" + fcc[0] + " and F_X=" + fcc[1] + " and F_Y=" + fcc[2] + ")"); } if (dv[0]["FSTARTCELL"].ToString().IndexOf("-") > 0)//20100905 { fcc = dv[0]["FSTARTCELL"].ToString().Split(cc); dbo.ExceSQL("UPDATE ST_CELL SET FRUNSTATUS=0,FPALLETBARCODE='" + dv[0]["FPALLETBARCODE"] + "' WHERE (FLaneWay=" + dv[0]["FSTARTDEVICE"] + " and F_Z=" + fcc[0] + " and F_X=" + fcc[1] + " and F_Y=" + fcc[2] + ")"); } break; default: break; } //20101028 dbo.ExceSQL("update T_Manage_Task set FSTATUS=900,FENDTIME='" + dtime + "' where FID=" + fid + " and F_ManageTaskKindIndex= " + mti); } } dbo.ExceSQL("delete from T_Manage_Task where FID=" + fid + " and F_ManageTaskKindIndex= " + mti); } catch (Exception ex) { throw ex; } finally { dv = null; } } /// /// 分类查找设备状态 /// /// 设备指令索引 /// 设备编号 /// /// 调度路径的子路径的编号 public void GetKindDeviceState(int TaskIdx, int DeviceIdx,int RouteIDSub) { int[] States; try { // DateTime dt1 = DateTime.Now; States = CStaticClass.GetDeviceState(DeviceIdx);//1完成,2任务号,5设备号 // DateTime dt2 = DateTime.Now; // System.Diagnostics.Trace.WriteLine(DeviceIdx + "******" + Convert.ToString(dt2 - dt1)); } catch (Exception ex) { if (FrmControlMonitor.FormInstance.GetObjectText("tsStatus").IndexOf("获取状态时:" + ex.Message) < 0) { FrmControlMonitor.FormInstance.FlashPanit("tsStatus", "获取状态时:" + ex.Message, true); } return; } if (DeviceIdx == 12012) { } _States = States; if (States == null)//没接收到任何返回值 { return; } else { TaskIdx = States[2]; int runstatus =States[1]; if (TaskIdx <= 0 || runstatus <=0) { //拆盘机特殊控制。发送后2秒钟后系统自动报告完成 if (DeviceIdx == 12028) { DataView dvtemp = dbo.ExceSQL("select F_MonitorIndex ,F_StartTime from T_Monitor_Task where F_DeviceIndex =12028 and F_DeviceCommandIndex in (7,8) and F_Status =1").Tables[0].DefaultView; if (dvtemp.Count > 0) { if (Information.IsDate(dvtemp[0]["F_StartTime"]))//20110513 { if (Convert.ToDateTime(dvtemp[0]["F_StartTime"]).AddSeconds(2) > DateTime.Now)// { TaskIdx = Convert.ToInt32(dvtemp[0]["F_MonitorIndex"]); ActionComplete(DeviceIdx, TaskIdx, 1); } } } } return; } int fid = ccf.GetManageTaskIndexfromMonitor(TaskIdx); int mti = ccf.GetManageTaskKindIndexFromMonitor(TaskIdx); if (States[1] >= 10)//故障 { //回写设备错误状态字(IO_Control,T_Manage_Task,T_Monitor_task) ActionError(DeviceIdx, TaskIdx, States[1]);// #region 双叉关联任务能同步运行的同时报告故障 //devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIdx); //if (devinfo.IfCorrelDoubleFork == "1") //{ // if (Model.CGeneralFunction.DoubleForkIfSync(TaskIdx, DeviceIdx, 1) == true) // { // string[] df = Model.CGeneralFunction.GetDoubleForkMonitorInfo(TaskIdx, DeviceIdx); // if (df != null) // { // ActionError(Convert.ToInt32(df[2]), Convert.ToInt32(df[0]), States[1]); // } // } //} #endregion //刷新监控中心显示 } switch (ccf.GetDeviceKindIdx(DeviceIdx)) { //正在运行的设备如果有探物就是说托盘运行到此设备 //根据任务号判断是否为调度任务,改写T_Manage_Task的当前位置 //根据任务号和当前位置判断是否有提前触发任务 //任务号传递到当前设备时,把本路径的前一设备的运行锁解除, //同时把当前设备加运行锁 case 1://堆垛机: //1-正在运行 2-完成;3-要求调度重发命令; //4-通知调度取消当前任务;其它值表示错误 if ((States[1] == 1))//开始运行,设置T_Monitor_Task的F_Status=2// || (States[0] == 2) {//正在运行的设备如果有探物就是说托盘运行到此设备 // CommonClassLib.CCarryConvert.WriteDarkCasket("ActionStartRun", "start", DeviceIdx.ToString(), string.Empty); ActionStartRun(DeviceIdx, TaskIdx); // CommonClassLib.CCarryConvert.WriteDarkCasket("ActionStartRun", "end", DeviceIdx.ToString(), string.Empty); if (mti == 1) {//20100714 dboM.ExecuteSql("update IO_CONTROL set CONTROL_STATUS=11 where CONTROL_ID=" + fid + ""); } #region 双叉关联任务,能同步的同时报告运行 //20100323 devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIdx); if (devinfo.IfCorrelDoubleFork == "1") { if (Model.CGeneralFunction.DoubleForkIfSync(TaskIdx, DeviceIdx, 1) == true) { string[] df = Model.CGeneralFunction.GetDoubleForkMonitorInfo(TaskIdx, DeviceIdx); if (df != null) { ActionStartRun(Convert.ToInt32( df[2]),Convert.ToInt32( df[0])); if (mti == 1) {//20100714 fid = ccf.GetManageTaskIndexfromMonitor(Convert.ToInt32(df[0])); dboM.ExecuteSql("update IO_CONTROL set CONTROL_STATUS=11 where CONTROL_ID=" + fid + ""); } } } } #endregion //刷新监控中心显示 } if (States[1] == 2)//报告完成,应该也有坐标 { string[] df = Model.CGeneralFunction.GetDoubleForkMonitorInfo(TaskIdx, DeviceIdx); bool snyc=Model.CGeneralFunction.DoubleForkIfSync(TaskIdx, DeviceIdx, 1) ; //20100702 int dfm = ccf.GetCorrelDoubleForkFromMonitor(TaskIdx); // CommonClassLib.CCarryConvert.WriteDarkCasket("ActionComplete", "start", DeviceIdx.ToString(), string.Empty ); ActionComplete(DeviceIdx, TaskIdx,1); // CommonClassLib.CCarryConvert.WriteDarkCasket("ActionComplete", "end", DeviceIdx.ToString(), string.Empty); //刷新监控中心显示 #region 双叉关联任务,能同步的同时报告完成;异步的直接执行关联的命令 //20100323 devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIdx); if ((devinfo.IfCorrelDoubleFork == "1") && (df != null))//20100702 { if (snyc== true)//20100702 { ActionComplete(DeviceIdx, Convert.ToInt32(df[0]), 1);//20100702 } else {//20100702 ccl.SendMonitorTask(Convert.ToInt32( df[0])); } } #endregion } break; case 2://输送机 if ((States[1] == 1))//开始运行,设置T_Monitor_Task的F_Status=2// || (States[0] == 2) {//正在运行的设备如果有探物就是说托盘运行到此设备 // CommonClassLib.CCarryConvert.WriteDarkCasket("ActionStartRun", "start", DeviceIdx.ToString(), string.Empty); if (DeviceIdx == 12012) { } ActionStartRun(DeviceIdx, TaskIdx); // CommonClassLib.CCarryConvert.WriteDarkCasket("ActionStartRun", "end", DeviceIdx.ToString(), string.Empty); #region 双叉关联任务,能同步的同时报告运行 //20100323 devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIdx); if (devinfo.IfCorrelDoubleFork == "1") { if (Model.CGeneralFunction.DoubleForkIfSync(TaskIdx, DeviceIdx, 2) == true) { string[] df = Model.CGeneralFunction.GetDoubleForkMonitorInfo(TaskIdx, DeviceIdx); if (df != null) { ActionStartRun(Convert.ToInt32(df[2]), Convert.ToInt32(df[0])); } } } #endregion //刷新监控中心显示 } if (States[1] == 2)//报告完成 { string[] df = Model.CGeneralFunction.GetDoubleForkMonitorInfo(TaskIdx, DeviceIdx); bool snyc = Model.CGeneralFunction.DoubleForkIfSync(TaskIdx, DeviceIdx, 2); devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIdx); if (devinfo.IfCorrelDoubleFork == "1")//20101220 { int updowndevice=ccf.GetUpAndDownDevices(DeviceIdx,devinfo.Dbw1Address); if(-1!=updowndevice) { GetKindDeviceState(0,updowndevice,0); } } //20100702 int dfm = ccf.GetCorrelDoubleForkFromMonitor(TaskIdx); // CommonClassLib.CCarryConvert.WriteDarkCasket("ActionComplete", "start", DeviceIdx.ToString(), string.Empty); ActionComplete(DeviceIdx, TaskIdx, 1); // CommonClassLib.CCarryConvert.WriteDarkCasket("ActionComplete", "end", DeviceIdx.ToString(), string.Empty); //刷新监控中心显示 #region 双叉关联任务,能同步的同时报告完成;异步的直接执行关联的命令 //20100323 //devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIdx); if (devinfo.IfCorrelDoubleFork == "1") { if ((devinfo.IfCorrelDoubleFork == "1") && (df != null))//20100702 { if (snyc == true)//20100702 { ActionComplete(DeviceIdx, Convert.ToInt32(df[0]), 1);//20100702 } else {//20100702 ccl.SendMonitorTask(Convert.ToInt32(df[0])); } } } #endregion } break; case 4://穿梭车 if ((States[1] == 1)) //开始运行,设置T_Monitor_Task的F_Status=2// || (States[0] == 2) {//正在运行的设备如果有探物就是说托盘运行到此设备 ActionStartRun(DeviceIdx, TaskIdx); //刷新监控中心显示 } if (States[1] == 2)//报告完成 { ActionComplete(DeviceIdx, TaskIdx,1); //刷新监控中心显示 } break; case 5://叠盘机 break; case 6://AGV车 break; case 7://条码扫描仪:需要在IO_ControlDetail表比对条码值 break; case 8://称重设备:向IO_ControlDetail表写入重量值 break; case 9://站台 break; case 10://巷道 break; case 11://分拣机 break; case 12://虚拟端点 break; case 13://空设备 break; case 14://确认按钮 break; case 15://定时器 break; case 16://指示灯 break; case 17://码垛机 break; case 18://检测开关 break; } } } /// /// 取得所有光电开关的信号 /// public void GetAllLESwitch() { //IGetDeviceState gds; int[] States; CCommonFunction ccf = new CCommonFunction(); DataView dv = new DataView(); int temp; char[] cc = new char[1] { ';' }; ResourceManager rm = new ResourceManager("ControlSystem.Properties.Resources", this.GetType().Assembly); char[] dot = new char[1] { '.' }; string[] picfile; string StrGet; string[] pic; int IfVis = 0; try { dv = dbo.ExceSQL("SELECT F_DeviceIndex,F_DBW2Address FROM T_Base_Device WHERE (F_DeviceKindIndex = 28)").Tables[0].DefaultView; if (dv.Count > 0) { gds = CommModeCreate.CreateGetDeviceState(Convert.ToInt32(dv[0]["F_DeviceIndex"])); States = gds.GetDeviceState(Convert.ToInt32(dv[0]["F_DeviceIndex"]), 0); } else return; if (States != null) { DataView dvle = dbo.ExceSQL("SELECT F_DeviceIndex, F_DeviceKindIndex,F_DBWGetLength," + " F_DBW2Address, F_DeviceVisual FROM T_Base_Device WHERE (F_DeviceVisual = 1)" + " AND (F_DeviceKindIndex = 18) and (F_DBWGetLength is not NULL) and (F_DBW2Address is not NULL)").Tables[0].DefaultView; int glen = 0; for (int i = 0; i < dvle.Count; i++) { temp = Convert.ToInt32(dvle[i]["F_DBWAddress"]) - Convert.ToInt32(dv[0]["F_DBWAddress"]); if (Convert.ToInt32((Convert.ToDecimal(dvle[i]["F_DBWGetLength"]) * 16 - 1)) > 7) { glen = Convert.ToInt32((Convert.ToDecimal(dvle[i]["F_DBWGetLength"]) * 16 - 1)) - 8; temp = temp + 1; } else { glen = Convert.ToInt32((Convert.ToDecimal(dvle[i]["F_DBWGetLength"]) * 16 - 1)); } if (temp >= 0) { IfVis = CommonClassLib.CCarryConvert.GetBitFromInteger(States[temp], glen); } else { return; } StrGet = GetControl_Picture(Convert.ToInt32(dvle[i]["F_DeviceIndex"])); if (StrGet != "") { pic = StrGet.Split(cc); picfile = pic[1].Split(dot); if (IfVis == 1) { FrmControlMonitor.FormInstance.FlashPanit(pic[0], true); FrmControlMonitor.FormInstance.FlashPanit(pic[0], (System.Drawing.Image)rm.GetObject(picfile[0])); } else { FrmControlMonitor.FormInstance.FlashPanit(pic[0], false); } } else continue; } } else { if (gds.CommLayerError != null) { if (FrmControlMonitor.FormInstance.GetObjectText("tsStatus").IndexOf("取得所有光电开关的信号时:" + gds.CommLayerError) < 0) { FrmControlMonitor.FormInstance.FlashPanit("tsStatus", "取得所有光电开关的信号时:" + gds.CommLayerError, true); } } } } catch (Exception ex) { if (FrmControlMonitor.FormInstance.GetObjectText("tsStatus").IndexOf("取得所有光电开关的信号时:" + ex.Message) < 0) { FrmControlMonitor.FormInstance.FlashPanit("tsStatus", "取得所有光电开关的信号时:" + ex.Message, true); } return; } } string GetNextCell(int lane, string strcell,string endcell) { //int laneNew = 2801; char[] cc = new char[1] { '-' }; string[] sp = strcell.Split(cc); string[] ep = endcell.Split(cc); if (sp.Length > 2) { #region 逐个货位倒库 //DataView dv = dbo.ExceSQL("SELECT * FROM ST_CELL WHERE (FLaneWay=" + lane + " and F_Z=" + // sp[0] + " and F_X=" + sp[1] + " and F_Y=" + sp[2] + ")").Tables[0].DefaultView; //if (dv.Count > 0) //{ // DataView dv0 = dbo.ExceSQL("SELECT * FROM ST_CELL WHERE FLaneWay=" + lane + " and FID>" + dv[0]["FID"] + " order by fid asc").Tables[0].DefaultView; // if (dv0.Count > 0) // { // if (lane == 2801) // { // if ((dv0[0]["FCELLCODE"].ToString() == "2-1-8") || (dv0[0]["FCELLCODE"].ToString() == "2-2-8")) // { // return "2-3-1"; // } // } // return dv0[0]["FCELLCODE"].ToString(); // } // else // { // return "1-1-1"; // } //} //else //{ // return "1-1-1"; //} #endregion #region 货架对角倒库 //switch (lane) //{ // case 2801: // if (Convert.ToInt32(sp[1]) <= 1) // { // DataView dv0 = dbo.ExceSQL("SELECT * FROM ST_CELL WHERE FLaneWay=" + lane + " and FCELLSTATUS=0 and FRUNSTATUS=0 order by fid desc").Tables[0].DefaultView; // if (dv0.Count > 0) // { // return lane.ToString() + ";" + dv0[0]["FCELLCODE"].ToString(); // } // return "2-36-1"; // } // else // { // return "1-1-1"; // } // case 2802: // if (Convert.ToInt32(sp[1]) <= 1) // { // DataView dv0 = dbo.ExceSQL("SELECT * FROM ST_CELL WHERE FLaneWay=" + lane + " and FCELLSTATUS=0 and FRUNSTATUS=0 order by fid desc").Tables[0].DefaultView; // if (dv0.Count > 0) // { // return lane.ToString() + ";" + dv0[0]["FCELLCODE"].ToString(); // } // return "2-36-1"; // } // else // { // return "1-1-1"; // } // case 2803: // if (Convert.ToInt32(sp[1]) <= 1) // { // DataView dv0 = dbo.ExceSQL("SELECT * FROM ST_CELL WHERE FLaneWay=" + lane + " and FCELLSTATUS=0 and FRUNSTATUS=0 order by fid desc").Tables[0].DefaultView; // if (dv0.Count > 0) // { // return lane.ToString() + ";" + dv0[0]["FCELLCODE"].ToString(); // } // return "2-36-1"; // } // else // { // return "1-1-1"; // } // default: // return "1-1-1"; //} #endregion #region 巷道间倒库 //switch (lane) //{ // case 2801: // //return "2802;1-36-8"; // laneNew = 2802; // break; // case 2802: // //return "2803;1-36-8"; // laneNew = 2803; // break; // case 2803: // //return "2801;1-36-8"; // laneNew = 2801; // break; // default: // //return "2801;1-1-1"; // laneNew = 2801; // break; //} //DataView dv0 = dbo.ExceSQL("SELECT * FROM ST_CELL WHERE FLaneWay=" + laneNew + " and FCELLSTATUS=0 and FRUNSTATUS=0 order by fid desc").Tables[0].DefaultView; //if (dv0.Count > 0) //{ // return laneNew.ToString() + ";" + dv0[0]["FCELLCODE"].ToString(); //} //else //{ // return "2801;1-1-1"; //} #endregion int f_xx = Convert.ToInt32(sp[1]); int f_yy = Convert.ToInt32(sp[2]); int f_zz = Convert.ToInt32(sp[0]); DataView dv00 = dbo.ExceSQL("select F_StartCol, F_EndCol ,F_LeftY from T_Base_LaneInfo where F_LaneDeviceIndex =" + lane).Tables[0].DefaultView; int F_EndCol = Convert.ToInt32(dv00[0]["F_EndCol"]); int F_LeftY = Convert.ToInt32(dv00[0]["F_LeftY"]); int F_StartCol = Convert.ToInt32(dv00[0]["F_StartCol"]); f_xx = f_xx + 1; if (f_zz == 5 ) { do { f_xx++; } while ((f_xx == 2 || f_xx == 3 || f_xx == 42 || f_xx == 15 || f_xx == 16 || f_xx == 17 || f_xx == 28 || f_xx == 29|| f_xx == 30 || f_xx == 43)); } if (f_xx > F_EndCol) { f_xx = F_StartCol; } f_yy = f_yy + 1; if (f_yy > F_LeftY) { f_yy = 1; } DataView dv0 = dbo.ExceSQL("SELECT * FROM ST_CELL WHERE (FLaneWay=" + lane + ") and F_X=" + f_xx + " and F_Y= " + f_yy + "and F_Z =" + f_zz).Tables[0].DefaultView; if (dv0.Count > 0) { return dv0[0]["FCELLCODE"].ToString(); } else { CommonClassLib.CCarryConvert.WriteDarkCasket("GetNextCell", dv0[0]["FCELLCODE"].ToString(), string.Empty , string.Empty); return "1-1-1"; } } else { return "2801;1-1-1"; } } /// /// 追加倒库货位至真实终点货位的取货和送货指令 /// /// 任务类型 /// 调度任务索引 /// 设备索引 /// 设备指令索引 void AppendMoveCellOperate(int mti, int fid, int device,int monitorindex) { //获取管理任务送货坐标,当前调度任务的路径,条码,优先级;远近货叉,提前检测 string manzxy = dbo.GetSingle("SELECT FENDCELL FROM T_Manage_Task WHERE (FID = " + fid + ") AND (F_ManageTaskKindIndex = " + mti + ")").ToString(); char[] cc = new char[1] { '-' }; string[] spcell = manzxy.Split(cc); string newuseawayfork; DataView dv = dbo.ExceSQL("select F_NumParam4, F_NumParam5,F_NumParam6, F_RouteID,F_MonitorTaskLevel, F_UseAwayFork, F_TxtParam from T_Monitor_Task where F_MonitorIndex=" + monitorindex).Tables[0].DefaultView; if (dv[0]["F_UseAwayFork"].ToString() == "1") { newuseawayfork = "0"; } else { newuseawayfork = "1"; } dbo.ExecuteSql("update T_Manage_Task set FExceptionNO=NULL,FUseAwayFork='" + newuseawayfork + "' where F_ManageTaskKindIndex=" + mti + " and FID=" + fid); int lev=int.Parse( dv[0]["F_MonitorTaskLevel"].ToString()); int routeid=int.Parse( dv[0]["F_RouteID"].ToString()); int fnp1=int.Parse( dv[0]["F_NumParam4"].ToString()); int fnp2=int.Parse( dv[0]["F_NumParam5"].ToString()); int fnp3=int.Parse( dv[0]["F_NumParam6"].ToString()); string pcode=dv[0]["F_TxtParam"].ToString(); //string aheaddetect=; int mindex = ccf.GetMonitorIndex(fid, mti); dbo.ExecuteSql("INSERT INTO T_Monitor_Task (F_ManageTaskIndex, F_ManageTASKKINDINDEX, F_MonitorIndex, F_MonitorTaskLevel," + " F_DeviceIndex, F_DeviceCommandIndex, F_RouteID, F_Status,F_NumParam1, F_NumParam2, F_NumParam3, F_NumParam4, F_NumParam5," + " F_NumParam6, F_TxtParam, F_AheadDetect, F_UseAwayFork)VALUES " + "(" + fid + "," + mti + "," + mindex + "," + lev + "," + device + ",4," + routeid + ",0," + fnp1 + "," + fnp2 + "," + fnp3 + "," + spcell[0] + "," + spcell[1] + "," + spcell[2] + ",'"+pcode+"',NULL,'"+newuseawayfork+"')"); mindex = ccf.GetMonitorIndex(fid, mti); dbo.ExecuteSql("INSERT INTO T_Monitor_Task (F_ManageTaskIndex, F_ManageTASKKINDINDEX, F_MonitorIndex, F_MonitorTaskLevel," + " F_DeviceIndex, F_DeviceCommandIndex, F_RouteID, F_Status,F_NumParam1, F_NumParam2, F_NumParam3, F_NumParam4, F_NumParam5," + " F_NumParam6, F_TxtParam, F_AheadDetect, F_UseAwayFork)VALUES " + "(" + fid + "," + mti + "," + mindex + "," + lev + "," + device + ",5," + routeid + ",0," + fnp1 + "," + fnp2 + "," + fnp3 + "," + spcell[0] + "," + spcell[1] + "," + spcell[2] + ",'" + pcode + "',NULL,'" + newuseawayfork + "')"); } /// /// 记录送入叠盘机任务的箱条码 /// /// void RecordBarCodeForDiePan(int fid, int enddevice) { StringBuilder sb = new StringBuilder(); string STOCK_BARCODE = string.Empty; int startdevice = 0; DataView dvs = dbo.ExceSQL("select * from T_Manage_Task t where (t.FENDDEVICE = 12853 or t.FENDDEVICE =12839) and FExceptionNO is null and fid =" + fid).Tables[0].DefaultView; if (dvs.Count <= 0) { return; } else { STOCK_BARCODE = dvs[0]["FPALLETBARCODE"].ToString(); startdevice = Convert.ToInt32(dvs[0]["FSTARTDEVICE"]); } DataView dvAsk = dbo.ExceSQL("select * from T_Base_PLC_Ask t where t.F_BindingDevice = " + enddevice).Tables[0].DefaultView; if (dvAsk.Count > 0) { if (dvAsk[0]["F_BarCode"] != DBNull.Value || dvAsk[0]["F_BarCode"].ToString() != string.Empty) { sb.Append(dvAsk[0]["F_BarCode"].ToString()); } } if (sb.ToString().Contains(STOCK_BARCODE)) { CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "记录叠盘信息失败", startdevice.ToString(), "本次记录的叠盘信息:" + STOCK_BARCODE + "已存在"); return; } sb.Append(STOCK_BARCODE).Append("|"); dbo.ExceSQL("update T_Base_PLC_Ask set F_BarCode ='" + sb.ToString() + "' where F_BindingDevice = " + enddevice); CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "记录叠盘信息成功", startdevice.ToString(), sb.ToString()); } /// /// 条码比对不正确的任务,箱到达12835异常口,塔灯亮起,提示操作者该箱子为异常箱 /// void SendMsgtoLamp(int fid ) { try { DataView dv = dbo.ExceSQL("select top 1 * from T_Manage_Task inner join T_Monitor_Task on T_Manage_Task .FID =T_Monitor_Task .F_ManageTaskIndex where T_Manage_Task .FID =" + fid + " and T_Manage_Task .F_ManageTaskKindIndex =1 and T_Manage_Task .FExceptionNO =990 order by T_Monitor_Task.F_MonitorIndex ").Tables[0].DefaultView; if (dv.Count > 0) { if (Convert.ToInt32(dv[0]["F_NumParam1"]) == 12918 && Convert.ToInt32(dv[0]["F_NumParam4"]) == 12835) { StringBuilder[] wv = new StringBuilder[1] { new StringBuilder("") }; StringBuilder[] witemnames = new StringBuilder[1] { new StringBuilder("") }; witemnames[0].Remove(0, witemnames[0].Length); wv[0].Remove(0, wv[0].Length); devinfo = Model.CGetInfo.GetDeviceInfo(12835); sdo = CommModeCreate.CreateSendDeviceOrder(12835); witemnames[0].Append("DB2,byte").Append(Convert.ToString((devinfo.Dbw2Address + 4))); wv[0].Append("1"); sdo.WriteDBData(witemnames, wv, 12835); CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "条码比对错误,12835出口绿灯亮起", "任务号" + dv[0]["FID"].ToString(), "起点货位" + dv[0]["FSTARTCELL"].ToString() + ";终点设备" + dv[0]["FENDDEVICE"].ToString()); } } } catch (Exception ex) { throw ex; } } } }