东风铸造整件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6013 lines
316 KiB

using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System;
using CommLayerFactory;
using ICommLayer;
using DBFactory;
using CommonLib;
namespace WcfControlMonitorLib
{
/// <summary>
/// Creator:Richard.liu
/// 监控调度类
/// </summary>
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;
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;
//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 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();
try
{
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);
if (CStaticClass.DBFactory == "OracleDBFactory")
{//20151120调度系统oracle的特殊语句
sql.Append("select min(F_MonitorIndex) as minMidx,f_status from T_Monitor_Task where rownum=1 and ").Append(taskkind.ToString()).Append(" and F_ManageTaskIndex = ").Append(dv[i]["MIndex"]).Append(" GROUP BY F_MonitorIndex, F_Status");
}
else
{//20151120调度系统SQLServer的特殊语句
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;//20151120调度系统oracle的特殊语句
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();
}
}
/// <summary>
/// 提取每个管理单据的第一个设备是否被锁定,true表示被锁定;false表示空闲
/// </summary>
/// <param name="minMidx">调度任务号</param>
/// <returns>true表示被锁定;false表示空闲</returns>
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
//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<int,string[]> 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<int,string[]> 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())
{
if (_DeviceIdx == 25001 || _DeviceIdx == 25002 || _DeviceIdx == 25003 || _DeviceIdx == 15701 || _DeviceIdx == 15201)
{
;// 20201122 双鹿电池德玛提升机多任务控制,不需要预约检测
}
else
{
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 LHDF 输送线分站台
if (devinfo.DeviceKind == 2 )
{
if (_NumParam4 > 0)
{
Model.MDevice devinfoR = Model.CGetInfo.GetDeviceInfo(_NumParam4);
if (devinfoR != null)
{
if (devinfoR.DeviceKind == 2 && devinfoR.DeviceVisual == 1)
{
AssignConveyorNo(devinfoR.DeviceIndex, minMidx, ManageKindIdx, ManageTaskIdx, StartDevice );
return true;
}
}
}
}
#endregion
#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<int, string[]> mforkmonitorinfo = Model.CGeneralFunction.GetDoubleForkMonitorInfo(minMidx, _DeviceIdx);
foreach (int i in mforkmonitorinfo.Keys)
{
if (Array.IndexOf<int>(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();
}
}
/// <summary>
/// 检测指定设备命令的执行先决条件是否成立
/// </summary>
/// <param name="minMidx">监控唯一索引</param>
/// <returns>是否检测通过,true表示设备执行命令的先决条件成立</returns>
public bool AheadDetectOK(int minMidx, string _AheadDetect)
{
//string strTime = DateTime.Now.ToLongTimeString() + ":" + DateTime.Now.Millisecond;
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);
int StartDevice = _StartDevice;//当前调度任务起点
int EndDevice = _EndDevice;//当前调度任务终点
int CONTROLTASKTYPE = ccf.GetFCONTROLTASKTYPEFromManageTask(mti, fid);
#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;
}
}
if (DeviceKind == 1 && order==1)//回原点检测条件20120110
{
if (devinfo.RunState == 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
#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;
#region 查找所有禁用设备//20141201张磊发现错误,应该增加设备是否被停用
sql.Remove(0, sql.Length);
sql.Append("SELECT F_DeviceIndex FROM T_Base_Device WHERE (F_LockedState = - 1) ");
DataView dvJY = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;//20141201张磊发现错误,应该增加设备是否被停用
dvJY.Sort = "F_DeviceIndex";//20141201张磊发现错误,应该增加设备是否被停用
#endregion
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)
{
#region 双鹿德玛提升机可以执行多个任务,状态小于30就行
if (idev == 25001 || idev == 25002 || idev == 25003 || idev == 15701 || idev == 15201)
{
if (States[1]< 30)
{
States[1] = 0;// 运行完成都看成空闲
}
else
{
s = s + States[1];
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "设备不空闲!");
}
continue;
}
#endregion
//if ((States[1] == 5) && (ccf.GetDeviceKindIdx(Convert.ToInt32(AheadDetect[i].Trim().Substring(1))) == 2))
//{//20120409只有输送机的完成可作为空闲
// States[1] = 0;
//}
if (States[1] != 0)//20110505
{
AheadDetectUnallow.Replace(AheadDetect[i].Trim().Substring(1)+"设备不空闲!","");
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "设备不空闲!");
}
if (DeviceHandTaskIfRun(Convert.ToInt32(AheadDetect[i].Trim().Substring(1))) == true)
{//20120207
AheadDetectUnallow.Replace(AheadDetect[i].Trim().Substring(1) + "手工任务或者避让任务正在运行!", "");
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "手工任务或者避让任务正在运行!");
States[1] = 1;
}
#region 20210622 双鹿电池,库后12106 入库,分时操作,检查反向出库任务12111(7-11巷道)
if (idev == 12106)
{
if (CheckLaneIfHaveRunningOut(12111,"18007","18011") > 0)
{
AheadDetectUnallow.Replace(AheadDetect[i].Trim().Substring(1) + "有反向出库任务正在执行!", "");
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "有反向出库任务正在执行!");
States[1] = 1;
}
}
#endregion
s = s + States[1];
}
if (dvJY.Find(idev) >= 0)
{//20141201张磊发现错误,应该增加设备是否被停用
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "设备被停用!");
s += 1;
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
continue;
}
#endregion
#region U 检测F_NumParam1,F_NumParam4设备无正在运行的任务
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "U")//检测F_NumParam1,F_NumParam4设备无正在运行的任务
{
sql.Clear();
sql.Append(string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_NumParam1 = {0} or F_NumParam4 = {0}) AND (F_Status > 0)", Convert.ToInt32(AheadDetect[i].Trim().Substring(1))));
dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdv.Count > 0)
{
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "有任务正在执行!");
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
else
{
s = s + 0;
}
continue;
}
#endregion
#region E 检测F_NumParam1设备无正在运行的任务 LHDF
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "E")//检测F_NumParam1设备无正在运行的任务
{
sql.Clear();
sql.Append(string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_NumParam1 = {0}) AND (F_Status > 0)", Convert.ToInt32(AheadDetect[i].Trim().Substring(1))));
dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdv.Count > 0)
{
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "有任务正在执行!");
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
else
{
s = s + 0;
}
continue;
}
#endregion
#region F 检测F_NumParam4设备无正在运行的任务 LHDF
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "F")//检测F_NumParam4设备无正在运行的任务
{
sql.Clear();
sql.Append(string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_NumParam4 = {0}) AND (F_Status > 0)", Convert.ToInt32(AheadDetect[i].Trim().Substring(1))));
dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdv.Count > 0)
{
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "有任务正在执行!");
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
else
{
s = s + 0;
}
continue;
}
#endregion
#region A 检测F_NumParam1-F_NumParam4设备无正在运行的任务 LHDF
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "A")//检测F_NumParam1,F_NumParam4设备无正在运行的任务
{
string[] strStation = AheadDetect[i].Trim().Substring(1).Split('-');
sql.Clear();
sql.Append(string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_NumParam1 = {0} and F_NumParam4 = {1}) AND (F_Status > 0)", Convert.ToInt32(strStation[0]), Convert.ToInt32(strStation[1])));
dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdv.Count > 0)
{
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "有任务正在执行!"+strStation [0]+strStation [1]);
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
else
{
s = s + 0;
}
continue;
}
#endregion
#region T 检测F_NumParam4设备无任务 LHDF
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "T")//检测F_NumParam4设备无任务
{
sql.Clear();
sql.Append(string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_NumParam4 = {0}) ", Convert.ToInt32(AheadDetect[i].Trim().Substring(1))));
dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdv.Count > 0)
{
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "有任务!");
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
else
{
s = s + 0;
}
continue;
}
#endregion
#region J检测积放线正在执行任务个数
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "J")//检测积放线正在执行任务个数(J12008,2)
{
cc[0] = ',';
sp = AheadDetect[i].Trim().Substring(1).Split(cc);
if (sp.GetLength(0) == 2)
{
sql.Clear();
sql.Append(string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_DeviceIndex={0}) AND (F_Status > 0)", Convert.ToInt32(sp[0])));
dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdv.Count >= Convert.ToInt32(sp[1]))
{
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "积放任务超限!");
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
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("预约!");
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
else
{
s = s + 0;
}
}
continue;
}
#endregion
#region D 检测设备光电信号
//检测设备的光电信号: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;
}
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 M 检测两段穿梭车或堆垛机之间的双向输送线互锁
//检测设备是否双向互锁,检查输送线是否有出库任务M+输送线号
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "M")
{
string EndLane = string.Empty;// 检测的终点巷道,是否有堆垛机出库任务正在执行
sql.Clear();
sql.Append(string.Format("select fenddevice from T_Manage_Task where FID = (select F_ManageTaskIndex from T_Monitor_Task where F_MonitorIndex = {0})", minMidx));
dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdv.Count <= 0)
{
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "的调度任务:").Append(minMidx.ToString()).Append("找不到终点巷道!");
continue;
}
EndLane = dvdv[0]["fenddevice"].ToString();
sql.Clear();
sql.Append(string.Format("select * from T_Monitor_Task,T_Base_Device where F_ManageTaskIndex in(select FID from T_Manage_Task where FCONTROLTASKTYPE = 2 and FSTARTDEVICE = {0})"
+" and (F_DeviceCommandIndex = 4 or F_DeviceCommandIndex = 5) and F_Status > 0 and T_Monitor_Task.F_DeviceIndex = T_Base_Device.F_DeviceIndex and T_Base_Device.F_DeviceKindIndex = 1", EndLane));
dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
for (int j = 0; j < dvdv.Count; j++)
{
// 有反向出库任务在堆垛机执行
// 出库任务有两条路径,检查路径上是否有检查的设备
int iF_ManageTaskIndex = Convert.ToInt32(dvdv[j]["F_ManageTaskIndex"]);
sql.Clear();
sql.Append(string.Format(" select F_DeviceCommandIndex from T_Monitor_Task where F_ManageTaskIndex = {0} and F_DeviceIndex = {1}", iF_ManageTaskIndex, Convert.ToInt32(AheadDetect[i].Trim().Substring(1))));
object obr = dbo.GetSingle(sql.ToString());
if (obr != null)
{
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "的调度任务:").Append(minMidx.ToString()).Append("有出库" + iF_ManageTaskIndex + "任务在" + AheadDetect[i].Trim().Substring(1) + "执行!");
}
}
// 检查输送线.1开关无货(近货架)
int sssn = CStaticClass.GetDevicePhotoelectric(Convert.ToInt32(AheadDetect[i].Trim().Substring(1)), 1);
if (sssn != 0)
{
s = s + sssn;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + ".1 光电开关遮挡!");
}
continue;
}
#endregion
#region S 检测起点是对应设备的入库任务,用于出入库双向输送线互锁检测
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "S")
{
int idev = Convert.ToInt32(AheadDetect[i].Trim().Substring(1));
sql.Clear();
sql.Append(string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} AND FID<> {1} AND FSTATUS =0", idev, fid));//and FCONTROLTASKTYPE = 1 LHDF
dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdv.Count > 0)
{
// 判断12106的入库,可以增加逻辑,每条入库任务已经执行,且FCurrentLocation大于出库station 可以执行
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "有入库任务未执行!");
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
else
{
s = s + 0;
}
continue;
}
#endregion
#region V 检测终点是对应设备的出库任务,用于出入库双向输送线互锁检测
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "V")
{
int idev = Convert.ToInt32(AheadDetect[i].Trim().Substring(1));
sql.Clear();
sql.Append(string.Format(" select F_MonitorIndex from T_MONITOR_Task where F_NumParam1 = {0} AND F_Status> 0 AND F_DeviceIndex =23001 AND F_DeviceCommandIndex =3 ", idev));//and FCONTROLTASKTYPE = 1 LHDF
dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdv.Count > 0)
{
// 判断12106的入库,可以增加逻辑,每条入库任务已经执行,且FCurrentLocation大于出库station 可以执行
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "有出库任务正在执行!");
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
else
{
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记录的不相同不再执行任务
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)
{
// 20201124 双鹿增加T_Base_PLC_Ask,标记 F_Controltype=5,判断是否需要条码比对
//sql.Remove(0, sql.Length);
//sql.Append("SELECT F_Controltype FROM T_Base_PLC_Ask where F_BindingDevice=").Append(devinfo.DeviceIndex);
//object obr2 = dbo.GetSingle(sql.ToString());
//if (obr2 != null && obr2.ToString() != "5")// F_Controltype=5 不进行对比
//{
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
#region CDDT6输送机与堆垛机互锁信号校验
//if (DeviceKind == 2)
//{
// string strSql = string.Format("SELECT F_ZXY FROM T_Base_Lane_Gate WHERE (F_LaneGateDeviceIndex = {0})", DeviceIdx);
// dvdv = dbo.ExceSQL(strSql).Tables[0].DefaultView;
// if (dvdv.Count > 0)
// {
// int isig = CStaticClass.GetDevicePhotoelectric(DeviceIdx, 4); //.4 -堆垛机允许输送线动作(1-允许,0-不允许)
// if (isig == 0)
// {
// s = s + 1;
// AheadDetectUnallow.Append(DeviceIdx + "输送线与堆垛机交互信号为0,不允许输送线动作!");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// else
// {
// s = s + 0;
// }
// }
//}
//if (DeviceKind == 1 && (order == 4 ))// 取货,送货
//{
// int[] zxy = ccf.GetCoordinatesFromMonitorTask(minMidx);
// if (zxy != null)
// {
// string pickcell = string.Format("{0:D2}-{1:D2}-{2:D2}", zxy[0], zxy[1], zxy[2]);//lanegate 坐标
// string strSql = string.Format("SELECT F_LaneGateDeviceIndex FROM T_Base_Lane_Gate WHERE (F_ZXY = '{0}')", pickcell);
// dvdv = dbo.ExceSQL(strSql).Tables[0].DefaultView;
// if (dvdv.Count > 0)
// {
// int isig = CStaticClass.GetDevicePhotoelectric(Convert.ToInt32(dvdv[0]["F_LaneGateDeviceIndex"].ToString()), 5);//.5 -输送线允许堆垛机动作(1-允许,0-不允许)
// if (isig == 0)
// {
// s = s + 1;
// AheadDetectUnallow.Append(DeviceIdx + "堆垛机与输送线交互信号为0,不允许堆垛机动作!");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// else
// {
// s = s + 0;
// }
// }
// }
//}
//if (DeviceKind == 1 && (order == 5))// 取货,送货
//{
// int[] zxy = ccf.GetCoordinatesFromMonitorTask(minMidx);
// string sendcell = string.Format("{0:D2}-{1:D2}-{2:D2}", zxy[3], zxy[4], zxy[5]);//lanegate 坐标
// string strSql = string.Format("SELECT F_LaneGateDeviceIndex FROM T_Base_Lane_Gate WHERE (F_ZXY = '{0}')", sendcell);
// dvdv = dbo.ExceSQL(strSql).Tables[0].DefaultView;
// if (dvdv.Count > 0)
// {
// int isig = CStaticClass.GetDevicePhotoelectric(Convert.ToInt32(dvdv[0]["F_LaneGateDeviceIndex"].ToString()), 5);//.5 -输送线允许堆垛机动作(1-允许,0-不允许)
// if (isig == 0)
// {
// s = s + 1;
// AheadDetectUnallow.Append(DeviceIdx + "堆垛机与输送线交互信号为0,不允许堆垛机动作!");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// else
// {
// s = s + 0;
// }
// }
//}
#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
#region 双伸位的堆垛机在执行起点是里位(1,4排)的任务时,判读是否有起点是外位(2,3排)的任务
if (devinfo.StackReach == 2 && DeviceKind == 1 && (order == 4))// 双伸堆垛机, 取货
{
int[] zxy = ccf.GetCoordinatesFromMonitorTask(minMidx);
string neighborzxy = string.Empty;
string sqlstrzxy = string.Empty;//
string sqlman = string.Empty;
//bool insidecell = false;//当前任务对应的里位还是外位
bool check = false;
if (zxy != null)
{
int getZ = zxy[0];//取货的排坐标
int sendZ = zxy[3]; //送货位置对应的排坐标
int newZ, newX, newY;
int tempZ = getZ;
if (tempZ >= 4)//20210207 4列问题
{
tempZ = getZ % 4;
}
if (tempZ == 1 || tempZ == 0 || getZ > 22)//里位取货时,要判读是否有外位的取货任务
{//获取外位坐标
if (tempZ == 1)
{
newZ = getZ + 1;
}
else
{
newZ = getZ - 1;
}
if (devinfo.DeviceIndex == 11012)
{
newZ = getZ == 29? 28 : getZ+4;
}
neighborzxy = string.Format("{0:D2}-{1:D2}-{2:D2}", newZ, zxy[1], zxy[2]);//获得外位坐标
sqlstrzxy = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_DeviceCommandIndex =4) and (F_NumParam1 = {0}) AND (F_NumParam2 = {1}) AND (F_NumParam3 = {2}) and (F_DeviceIndex={3})", newZ, zxy[1], zxy[2], DeviceIdx);
//sqlstrzxy
sqlman = string.Format("SELECT FID FROM T_Manage_Task WHERE (FSTATUS = 0) AND(FSTARTDEVICE = {0}) AND (FSTARTCELL = '{1}') ", StartDevice, neighborzxy);
//sqlstrzxy
check = true;
if (check)
{
dvdv = dbo.ExceSQL(sqlstrzxy).Tables[0].DefaultView;
if (dvdv.Count > 0)//
{
AheadDetectUnallow.Append(string.Format("存在相邻货位{0}的优先任务,该任务暂时不能执行! ", neighborzxy));
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;//不能执行出库任务
}
dvdv = dbo.ExceSQL(sqlman).Tables[0].DefaultView;
if (dvdv.Count > 0)//
{
AheadDetectUnallow.Append(string.Format("存在相邻货位{0}的优先任务,该任务暂时不能执行! ", neighborzxy));
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;//不能执行出库任务
}
}
}
tempZ = sendZ;
if (tempZ >= 4)//20210207 4列问题
{
tempZ = sendZ % 4;
}
if (tempZ == 2 || tempZ == 3 || sendZ >22)//近叉送货时,要判读是否有远叉的送货任务
{//获取里位坐标
if (tempZ == 2)
{
newZ = sendZ - 1;
}
else
{
newZ = sendZ + 1;
}
if (devinfo.DeviceIndex == 11012)
{
newZ = sendZ == 28 ? 29 : sendZ + 4;//20210128
}
neighborzxy = string.Format("{0:D2}-{1:D2}-{2:D2}", newZ, zxy[4], zxy[5]);//获得外位坐标
sqlstrzxy = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE ( F_DeviceCommandIndex =5) and (F_NumParam4 = {0}) AND (F_NumParam5 = {1}) AND (F_NumParam6 = {2}) and (F_DeviceIndex={3})", newZ, zxy[4], zxy[5], DeviceIdx);
sqlman = string.Format("SELECT FID FROM T_Manage_Task WHERE (FSTATUS = 0) AND(FENDDEVICE = {0}) AND (FENDCELL = '{1}') ", EndDevice, neighborzxy);
check = true;
if (check)
{
dvdv = dbo.ExceSQL(sqlstrzxy).Tables[0].DefaultView;
if (dvdv.Count > 0)//
{
AheadDetectUnallow.Append(string.Format("存在相邻货位{0}的优先任务,该任务暂时不能执行! ", neighborzxy));
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;//不能执行出库任务
}
dvdv = dbo.ExceSQL(sqlman).Tables[0].DefaultView;
if (dvdv.Count > 0)//
{
AheadDetectUnallow.Append(string.Format("存在相邻货位{0}的优先任务,该任务暂时不能执行! ", neighborzxy));
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;//不能执行出库任务
}
}
}
}
}
#endregion
#region 输送线送出命令,检查是否有AGV送货命令到终点输送线,并且取货或者送货命令已经发送
if (DeviceKind == 2 && order == 6)
{
int CheckConv = _NumParam4;
dvdv = dbo.ExceSQL("select * from T_Base_AGV_Gate where F_AGVGateDeviceIndex = " + CheckConv).Tables[0].DefaultView;
if (dvdv.Count > 0)
{
// 查看AGV终点是CheckConv的任务,运动,取货,送货,取送货都算
dv = dbo.ExceSQL("select * from T_Monitor_Task where F_DeviceIndex = 23001 and F_NumParam5 = "+ CheckConv +" and F_Status > 0").Tables[0].DefaultView;
if (dv.Count > 0)
{
AheadDetectUnallow.Append(string.Format("输送线{0}有AGV送货任务没有通过节点,暂时不能执行该任务! ", CheckConv));
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
}
}
#endregion
#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<int, string[]> 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<int, string[]> 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<int, string[]> 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 调度任务和自动任务, 入库任务堆垛机在入库站台取货时,判断有2条以上堆垛机取货任务满足执行条件且未发送
if ((order == 4) && (mti == 1 || mti == 2) && (DeviceKind == 1))
{
int[] zxy = ccf.GetCoordinatesFromMonitorTask(TaskIdx);
StringBuilder zxystr = new StringBuilder();
if (zxy != null)
{
zxystr.Append((zxy[0].ToString().Length == 1 ? "0" + zxy[0].ToString() : zxy[0].ToString())).Append("-").Append(
((zxy[1].ToString().Length == 1) ? ("0" + zxy[1].ToString()) : (zxy[1].ToString()))).Append("-").Append(
((zxy[2].ToString().Length == 1) ? ("0" + zxy[2].ToString()) : (zxy[2].ToString())));
}
sql.Clear();
sql.Append(string.Format("select * from T_Base_Lane_Gate where F_ZXY='{0}'", zxystr.ToString()));
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)//入库站台
{
sql.Clear();
sql.Append(string.Format("select * from T_Monitor_Task where F_DeviceIndex={0} and F_NumParam1= {1} and F_NumParam2= {2} and F_NumParam3= {3} and F_DeviceCommandIndex = {4} and F_Status=0 and F_MonitorIndex in (SELECT min(F_MonitorIndex) as minMidx FROM T_Monitor_Task,T_Manage_Task where T_Manage_Task.FID=T_Monitor_Task.F_ManageTaskIndex and T_Manage_Task. F_ManageTaskKindIndex=T_Monitor_Task.F_ManageTASKKINDINDEX and T_Manage_Task. FCONTROLTASKTYPE=1 group by F_ManageTaskIndex) ", DeviceIdx, zxy[0], zxy[1], zxy[2], order));
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count >= 2)
{
AheadDetectUnallow.Append(DeviceIdx.ToString ()+"堆垛机有多条入库任务满足执行条件,需人工查看处理!");
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
}
}
#endregion
#region 调度任务和自动任务,判断输送机任务发送时,要判断同起点有2条以上满足执行条件的输送任务未发送
if (mti != 4 && (DeviceKind == 2))
{
sql.Clear();
sql.Append(string.Format("select * from T_Monitor_Task where F_DeviceIndex={0} and F_Status=0 and F_MonitorIndex in (SELECT min(F_MonitorIndex) as minMidx FROM T_Monitor_Task,T_Manage_Task where T_Manage_Task.FID=T_Monitor_Task.F_ManageTaskIndex and T_Manage_Task. F_ManageTaskKindIndex=T_Monitor_Task.F_ManageTASKKINDINDEX and ( T_Manage_Task. F_ManageTaskKindIndex<>4) group by F_ManageTaskIndex) ", DeviceIdx));
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count >= 2)
{
AheadDetectUnallow.Append(DeviceIdx.ToString ()+"输送机有多条任务满足执行条件且未发送,需人工查看处理");
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
}
#endregion
#region 调度任务和自动任务,判断输送机任务发送时,要判断堆垛机送货站台送出指令与记录条码一致
//if (mti != 4 && (DeviceKind == 2))
//{
// string barcode = ccf.GetBarCodeFromMonitor(TaskIdx);
// sql.Clear();
// sql.Append(string.Format("select * from T_Base_Lane_Gate where F_LaneGateDeviceIndex={0}", DeviceIdx));
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// if (barcode != dv[0]["F_LaneGateBarcode"].ToString())
// {
// AheadDetectUnallow.Append(dv[0]["F_LaneGateDeviceIndex"].ToString() + "送出时,任务条码与站台记录条码比对不一致");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// }
//}
#endregion
#region 调度任务和自动任务,判断堆垛机在入库站台取货时,校验入库站台条码与堆垛机取货任务条码一致
if ((order == 4) && (mti == 1 || mti == 2) && (DeviceKind == 1))
{
string barcode = ccf.GetBarCodeFromMonitor(TaskIdx);
int[] zxy = ccf.GetCoordinatesFromMonitorTask(TaskIdx);
StringBuilder zxystr = new StringBuilder();
if (zxy != null)
{
zxystr.Append((zxy[0].ToString().Length == 1 ? "0" + zxy[0].ToString() : zxy[0].ToString())).Append("-").Append(
((zxy[1].ToString().Length == 1) ? ("0" + zxy[1].ToString()) : (zxy[1].ToString()))).Append("-").Append(
((zxy[2].ToString().Length == 1) ? ("0" + zxy[2].ToString()) : (zxy[2].ToString())));
}
sql.Clear();
//sql.Append(string.Format("select * from T_Base_Lane_Gate where F_ZXY='{0}'", zxystr.ToString()));
//dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
//if (dv.Count > 0)
//{
// if (barcode != dv[0]["F_LaneGateBarcode"].ToString())
// {
// AheadDetectUnallow.Append("堆垛机在站台" + dv[0]["F_LaneGateDeviceIndex"].ToString() + "取货时,任务条码与站台记录条码比对不一致");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
//}
}
#endregion
#region 调度任务和自动任务,判断穿梭车在取货站台取货时,校验取货站台条码与穿梭车取货任务条码一致 LHDF注释
//if ((order == 2) && (mti == 1 || mti == 2) && (DeviceKind == 4))
//{
// string barcode = ccf.GetBarCodeFromMonitor(TaskIdx);
// int[] zxy = ccf.GetCoordinatesFromMonitorTask(TaskIdx);
// int RGVgate = zxy[0];
// sql.Clear();
// sql.Append(string.Format("select * from T_Base_RGV_Gate where F_RGVGateDeviceIndex={0}", RGVgate));
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)//RGV在站台取货
// {
// if (barcode != dv[0]["F_RGVGateBarcode"].ToString())
// {
// AheadDetectUnallow.Append("RGV在站台" + dv[0]["F_RGVGateDeviceIndex"].ToString() + "取货时,任务条码与站台记录条码比对不一致");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// }
//}
#endregion
//string strETime = DateTime.Now.ToLongTimeString() + ":" + DateTime.Now.Millisecond;
//CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "提前检测", DeviceIdx.ToString(), "开始时间:" + strTime +"结束时间:"+strETime );
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();
if (CStaticClass.DBFactory == "OracleDBFactory")
{//20151120调度系统oracle的特殊语句
sql.Append(string.Format("SELECT F_DeviceIndex,F_Status FROM T_Monitor_Task WHERE rownum=1 and (F_ManageTASKKINDINDEX = {0}) and F_ManageTaskIndex={1} order by F_MonitorIndex asc", Convert.ToInt32(dv[i]["F_ManageTASKKINDINDEX"]), Convert.ToInt32(dv[i]["F_ManageTASKINDEX"])));
}
else
{
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;//20151120调度系统oracle的特殊语句
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();
}
}
/// <summary>
/// 获得发送信息
/// </summary>
/// <param name="minMidx">设备指令索引</param>
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();
}
}
/// <summary>
/// 发送指定调度任务号的命令
/// </summary>
/// <param name="MonitorIndex"></param>
/// <returns></returns>
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);
devinfo = Model.CGetInfo.GetDeviceInfo(deviceIdx);
if (((deviceKind == 1 && (devinfo.YCoor == 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 (devinfo.RunState!=0)
{
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) || (deviceKind == 6 )|| (deviceKind == 50))
{
sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, 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(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<int, string[]> 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) || (deviceKind == 6) || (deviceKind == 50))
{
//1:堆垛机;6:AGV,50: 环形穿梭车 如果需要优化调度(设备表的F_NeedOptimize='1')
//直接写入表:T_Monitor_Task_Child,不发送命令
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]);
}
}
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 == 8)
{//20130510在订阅处理称重任务和重量
//#region 称重
////DataView dv = dbo.ExceSQL(string.Format("SELECT F_BoxBarcode FROM T_Base_PLC_Ask WHERE F_BoxBarcode<>'0' and T_Base_PLC_Ask.F_DeviceIndex = {0}", deviceIdx)).Tables[0].DefaultView;
////if (dv.Count > 0)
////{
//// //向管理写入重量
//// dboM.ExecuteSql(string.Format("UPDATE IO_CONTROL SET CONTROL_REMARK ={0} WHERE CONTROL_ID={1}", dv[0][0].ToString(), manageTaskIdx));
//// Model.CGeneralFunction.ActionComplete(deviceIdx, MonitorIndex, 0);
//// dbo.ExecuteSql(string.Format("UPDATE T_Base_PLC_Ask SET F_BoxBarcode = '0' WHERE (F_DeviceIndex = {0})", deviceIdx));
////}
//#endregion
//return true;
sendok = true;
}
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//发送命令成功
{
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);
#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();
}
}
/// <summary>
/// 获取可用的目标位置:入库的巷道或者出库站台
/// </summary>
/// <param name="manageTaskIdx">调度任务索引</param>
/// <param name="manageKindIdx">调度任务类别</param>
/// <returns></returns>
bool GetUsableDestination(int manageTaskIdx,int manageKindIdx )
{
//20100610查找一个路径可用,任务数最少的终点设备
Dictionary<int, int> advDev=new Dictionary<int,int>();
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<int, int> advDev=new Dictionary<int,int>();
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();
}
}
/// <summary>
/// 返回在顶升处入库任务可以多叉关联的调度任务索引
/// </summary>
/// <param name="controlTaskType">控制任务类型</param>
/// <param name="devindex">设备索引</param>
/// <returns></returns>
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();
}
}
/// <summary>
/// 获得堆垛机在对等站台取货的多叉关联任务
/// </summary>
/// <param name="controlTaskType">控制任务类型</param>
/// <param name="Stackdevindex">堆垛机设备索引</param>
/// <param name="StationDevice">站台设备索引</param>
/// <param name="FID">调度任务索引</param>
/// <returns></returns>
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();
}
}
/// <summary>
///
/// </summary>
/// <param name="Mankind">调度任务类型索引</param>
/// <param name="FID">调度任务索引</param>
/// <param name="ControlTaskType">调度任务类型</param>
/// <param name="UseAwayFork">最后分配的远、近货叉</param>
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)
{
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<int, string[]> 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;
}
}
/// <summary>
/// 同轨两个堆垛机组合作业,通过中转货位交替作业
/// </summary>
/// <param name="taskindex"></param>
/// <param name="ChangeStackCell"></param>
/// <param name="StackIndex"></param>
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;
}
}
/// <summary>
/// 返回AGV双叉的关联站台,“-1”代表没有关联
/// </summary>
/// <param name="taskindex">设备指令索引</param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 返回AGV在此站台取货的调度任务索引
/// </summary>
/// <param name="controltype">控制任务类型</param>
/// <param name="stationIndex">AGV站台索引</param>
/// <returns></returns>
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);
if (CStaticClass.DBFactory == "OracleDBFactory")
{//20151120调度系统oracle的特殊语句
sql.Append("SELECT F_MonitorIndex ").Append(" FROM T_Monitor_Task where rownum=1 and 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");
}
else
{//20151120调度系统SQLServer的特殊语句
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;//20151120调度系统oracle的特殊语句
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
}
/// <summary>
/// 如果是倒叉货位,那它后执行
/// </summary>
/// <param name="TaskIndex"></param>
/// <returns></returns>
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();
}
}
/// <summary>
/// 分配实际工作的堆垛机设备索引20111020
/// </summary>
/// <param name="deviceIndex">虚拟堆垛机设备索引</param>
/// <param name="taskIndex">设备指令索引</param>
/// <param name="manKind">调度任务类型</param>
/// <param name="fid">调度任务索引</param>
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();
}
}
/// <summary>
/// 分配实际输送机站台 LHDF
/// </summary>
/// <param name="deviceIndex">虚拟输送机设备索引</param>
/// <param name="taskIndex">设备指令索引</param>
/// <param name="manKind">调度任务类型</param>
/// <param name="fid">调度任务索引</param>
bool AssignConveyorNo(int deviceIndex, int taskIndex, int manKind, int fid,int startDevice)
{
DataView dv = new DataView();
Model.MDevice devinfo,devinfoR; int resDev = 0;
object obj0 = 0;
int iDevice = deviceIndex;
try
{
switch (iDevice)
{
case 41001:
#region
int[] iStation = {12015,12012};
devinfo = Model.CGetInfo.GetDeviceInfo(iStation[0]);
devinfoR = Model.CGetInfo.GetDeviceInfo(iStation[1]);
if (startDevice == 18002) //12012无物,无12012入库任务,无终点位置到12012送出指令,12015有物或者有12015入库任务或者有终点位置到12015送出指令,没有18001到41001出库任务
{
int s = 0; int r = 0;
string str = string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} ", iStation[1]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
str = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_NumParam4 = {0})", iStation[1]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
str = string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} ", iStation[0]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
r = r + 1;
}
str = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_NumParam4 = {0})", iStation[0]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
r = r + 1;
}
str = string.Format(" select * from T_Manage_Task where FENDDEVICE = {0} AND FSTARTDEVICE = 18001", iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
int iRoutID = CDisassembleTask.MinRouteID(startDevice,iStation[1], obj0);
int iRoutIDR = CDisassembleTask.MinRouteID(startDevice, iStation[0],obj0);
if ((devinfoR.SplitByte_0 == 0 && s == 0 && (devinfo.SplitByte_0 == 1 || r > 0)) || (iRoutID != -1 && iRoutIDR ==-1))
{
object obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iStation[1], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_MonitorIndex = {0}", taskIndex, iStation[1], obj.ToString()));
}
else
{
object obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_RouteID in ("
+"select F_RouteID from T_Base_Route_Device where F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} )) ", iStation[0], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_MonitorIndex = {0}", taskIndex, iStation[0], obj.ToString()));
}
}
else //if (startDevice == 18001) //startDevice==12017//12015无物,无12015入库任务,无终点位置到12015送出指令,12012有物或者有12012入库任务或者有终点位置到12012送出指令,没有18002到41001出库任务
{
int s = 0; int r = 0;
string str = string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} ", iStation[0]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
str = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_NumParam4 = {0})", iStation[0]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
str = string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} ", iStation[1]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
r = r + 1;
}
str = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_NumParam4 = {0})", iStation[1]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
r = r + 1;
}
str = string.Format(" select * from T_Manage_Task where FENDDEVICE = {0} AND FSTARTDEVICE = 18002", iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s+ 1;
}
int iRoutID = CDisassembleTask.MinRouteID(startDevice, iStation[0], obj0);
int iRoutIDR = CDisassembleTask.MinRouteID(startDevice, iStation[1],obj0);
if ((devinfo.SplitByte_0 == 0 && s == 0 && (devinfoR.SplitByte_0 == 1 || r > 0)) || (iRoutID !=-1 && iRoutIDR ==-1))
{
object obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_RouteID in ("+
"select F_RouteID from T_Base_Route_Device where F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} )) ", iStation[0], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_MonitorIndex = {0}", taskIndex, iStation[0], obj.ToString()));
}
else
{
object obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iStation[1], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_MonitorIndex = {0}", taskIndex, iStation[1], obj.ToString()));
}
}
break;
#endregion
case 41002:
#region //12049-12050,12053-12047,18003-12050,12059、18004、18005-12047
int[] iEndStation = {12053,12053,12047};
int[] iEndStationR = {12049, 12049, 12050 };
if (startDevice == 18003)
//12047、12053、12055无物,无12047入库任务,无终点位置到12047、12053送出指令,//
//12050、12048、12049有物或者有12050入库任务或者有终点位置到12050,12049送出指令,没有18004、18005到41002出库任务
{
int r = 0; int s = 0;
foreach (int i in iEndStation)
{
devinfo = Model.CGetInfo.GetDeviceInfo(i);
if (devinfo.SplitByte_0 == 1)
{
s = s + 1;
}
}
string str = string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} ", iEndStation[2]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
str = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE F_ManageTaskIndex <> {2} and F_NumParam1<>{3} and (F_NumParam4 = {0} or F_NumParam4 = {1})", iEndStation[2], iEndStation[0], fid, iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
foreach (int i in iEndStationR)
{
devinfoR = Model.CGetInfo.GetDeviceInfo(i);
if (devinfoR.SplitByte_0 == 1)
{
r = r + 1;
}
}
str = string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} ", iEndStationR[2]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
r = r + 1;
}
str = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE F_ManageTaskIndex <> {2} and F_NumParam1<>{3} and (F_NumParam4 = {0} or F_NumParam4 = {1})", iEndStationR[2], iEndStationR[0], fid, iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
r = r + 1;
}
str = string.Format(" select * from T_Manage_Task where FENDDEVICE = {0} AND (FSTARTDEVICE = 18004 or FSTARTDEVICE = 18005)", iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
int iRoutID = CDisassembleTask.MinRouteID(startDevice, iEndStation[2], obj0);
int iRoutIDR = CDisassembleTask.MinRouteID(startDevice, iEndStationR[2], obj0);
if ((s == 0 && r > 0) || (iRoutID !=-1 && iRoutIDR ==-1)) //12053-12047
{
object obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iEndStation[0], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_MonitorIndex = {0}", taskIndex, iEndStation[0], obj.ToString()));
obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_DeviceOrder <8 and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iEndStation[2], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_DeviceIndex = {3},F_NUMPARAM1 = {3},F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_ManageTaskIndex = {0} and F_NUMPARAM1 = {4}", fid, iEndStation[2], obj.ToString(), iEndStation[0], iDevice));
obj = "D-" + iEndStation[2].ToString() + ".0;" + "I" + iEndStation[2].ToString();
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_DeviceIndex = {1},F_NUMPARAM1 = {1},F_AheadDetect = '{2}' WHERE F_ManageTaskIndex = {0} AND F_DeviceCommandIndex =9", fid, iEndStation[2], obj.ToString()));
}
else
{
object obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_RouteID in ("+
"select F_RouteID from T_Base_Route_Device where F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} )) ", iEndStationR[0], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_MonitorIndex = {0}", taskIndex, iEndStationR[0], obj.ToString()));
obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_DeviceOrder <8 and F_RouteID in (" +
"select F_RouteID from T_Base_Route_Device where F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} )) ", iEndStationR[2], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_DeviceIndex = {3},F_NUMPARAM1 = {3},F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_ManageTaskIndex = {0} and F_NUMPARAM1 = {4}", fid, iEndStationR[2], obj.ToString(), iEndStationR[0], iDevice));
obj = "D-" + iEndStationR[2].ToString() + ".0;" + "I" + iEndStationR[2].ToString();
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_DeviceIndex = {1},F_NUMPARAM1 = {1},F_AheadDetect = '{2}' WHERE F_ManageTaskIndex = {0} AND F_DeviceCommandIndex =9", fid, iEndStationR[2], obj.ToString()));
}
}
else if (startDevice == 18004)//12048、12049、12050无物,无12050入库任务,无终点位置到12048、12050送出指令,
//12047、12053、12055有物或者有12047入库任务或者有终点位置到12047、12053送出指令,没有18005到41002出库任务
{
int r = 0; int s = 0;
foreach (int i in iEndStationR)
{
devinfoR = Model.CGetInfo.GetDeviceInfo(i);
if (devinfoR.SplitByte_0 == 1)
{
s = s + 1;
}
}
string str = string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} ", iEndStationR[2]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
str = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE F_ManageTaskIndex <> {2} and F_NumParam1<>{3} and (F_NumParam4 = {0} or F_NumParam4 = {1})", iEndStationR[2], iEndStationR[0], fid, iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
foreach (int i in iEndStation)
{
devinfo = Model.CGetInfo.GetDeviceInfo(i);
if (devinfo.SplitByte_0 == 1)
{
r = r + 1;
}
}
str = string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} ", iEndStation[2]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
r = r + 1;
}
str = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE F_ManageTaskIndex <> {2} and F_NumParam1<>{3} and (F_NumParam4 = {0} or F_NumParam4 = {1})", iEndStation[2], iEndStation[0], fid, iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
r = r + 1;
}
str = string.Format(" select * from T_Manage_Task where FENDDEVICE = {0} AND (FSTARTDEVICE = 18005)", iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
int iRoutID = CDisassembleTask.MinRouteID(startDevice, iEndStationR[2], obj0);
int iRoutIDR = CDisassembleTask.MinRouteID(startDevice, iEndStation[2], obj0);
if ((s == 0 && r > 0) || (iRoutID != -1 && iRoutIDR == -1)) //12048-12050
{
object obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_RouteID in (" +
"select F_RouteID from T_Base_Route_Device where F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) )", iEndStationR[0], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_MonitorIndex = {0}", taskIndex, iEndStationR[0], obj.ToString()));
obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_DeviceOrder <8 and F_RouteID in (" +
"select F_RouteID from T_Base_Route_Device where F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} )) ", iEndStationR[2], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_DeviceIndex = {3},F_NUMPARAM1 = {3},F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_ManageTaskIndex = {0} and F_NUMPARAM1 = {4}", fid, iEndStationR[2], obj.ToString(), iEndStationR[0], iDevice));
obj = "D-" + iEndStationR[2].ToString() + ".0;" + "I" + iEndStationR[2].ToString();
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_DeviceIndex = {1},F_NUMPARAM1 = {1},F_AheadDetect = '{2}' WHERE F_ManageTaskIndex = {0} AND F_DeviceCommandIndex =9", fid, iEndStationR[2], obj.ToString()));
}
else
{
object obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iEndStation[0], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_MonitorIndex = {0}", taskIndex, iEndStation[0], obj.ToString()));
obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_DeviceOrder <8 and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iEndStation[2], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_DeviceIndex = {3},F_NUMPARAM1 = {3},F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_ManageTaskIndex = {0} and F_NUMPARAM1 = {4}", fid, iEndStation[2], obj.ToString(), iEndStation[0], iDevice));
obj = "D-" + iEndStation[2].ToString() + ".0;" + "I" + iEndStation[2].ToString();
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_DeviceIndex = {1},F_NUMPARAM1 = {1},F_AheadDetect = '{2}' WHERE F_ManageTaskIndex = {0} AND F_DeviceCommandIndex =9", fid, iEndStation[2], obj.ToString()));
}
}
else //18005、12059//12048、12049、12050无物,无12050入库任务,无终点位置到12048、12050送出指令,
//12047、12053、12055有物或者有12047入库任务或者有终点位置到12047、12055送出指令,没有18003、18004到41002出库任务
{
int r = 0; int s = 0;
foreach (int i in iEndStationR)
{
devinfoR = Model.CGetInfo.GetDeviceInfo(i);
if (devinfoR.SplitByte_0 == 1)
{
s = s + 1;
}
}
string str = string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} ", iEndStationR[2]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
str = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE F_ManageTaskIndex <> {2} and F_NumParam1<>{3} and (F_NumParam4 = {0} or F_NumParam4 = {1})", iEndStationR[2], iEndStationR[0], fid, iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
foreach (int i in iEndStation)
{
devinfo = Model.CGetInfo.GetDeviceInfo(i);
if (devinfo.SplitByte_0 == 1)
{
r = r + 1;
}
}
str = string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} ", iEndStation[2]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
r = r + 1;
}
str = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE F_ManageTaskIndex <> {2} and F_NumParam1<>{3} and (F_NumParam4 = {0} or F_NumParam4 = {1})", iEndStation[2], iEndStation[0], fid, iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
r = r + 1;
}
str = string.Format(" select * from T_Manage_Task where FENDDEVICE = {0} AND (FSTARTDEVICE = 18003 or FSTARTDEVICE = 18004)", iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
int iRoutID = CDisassembleTask.MinRouteID(startDevice, iEndStationR[2], obj0);
int iRoutIDR = CDisassembleTask.MinRouteID(startDevice, iEndStation[2], obj0);
if ((s == 0 && r > 0) || (iRoutID !=-1 && iRoutIDR ==-1)) //12048-12050
{
object obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_RouteID in (" +
"select F_RouteID from T_Base_Route_Device where F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} )) ", iEndStationR[0], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_MonitorIndex = {0}", taskIndex, iEndStationR[0], obj.ToString()));
obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_DeviceOrder <8 and F_RouteID in (" +
"select F_RouteID from T_Base_Route_Device where F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) )", iEndStationR[2], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_DeviceIndex = {3},F_NUMPARAM1 = {3},F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_ManageTaskIndex = {0} and F_NUMPARAM1 = {4}", fid, iEndStationR[2], obj.ToString(), iEndStationR[0], iDevice));
obj = "D-" + iEndStationR[2].ToString() + ".0;" + "I" + iEndStationR[2].ToString();
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_DeviceIndex = {1},F_NUMPARAM1 = {1},F_AheadDetect = '{2}' WHERE F_ManageTaskIndex = {0} AND F_DeviceCommandIndex =9", fid, iEndStationR[2], obj.ToString()));
}
else
{
object obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iEndStation[0], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_MonitorIndex = {0}", taskIndex, iEndStation[0], obj.ToString()));
obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_DeviceOrder <8 and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iEndStation[2], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_DeviceIndex = {3},F_NUMPARAM1 = {3},F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_ManageTaskIndex = {0} and F_NUMPARAM1 = {4}", fid, iEndStation[2], obj.ToString(), iEndStation[0], iDevice));
obj = "D-" + iEndStation[2].ToString() + ".0;" + "I" + iEndStation[2].ToString();
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_DeviceIndex = {1},F_NUMPARAM1 = {1},F_AheadDetect = '{2}' WHERE F_ManageTaskIndex = {0} AND F_DeviceCommandIndex =9", fid, iEndStation[2], obj.ToString()));
}
}
break;
#endregion
case 41003:
#region //12045-12054,12056-12058,18003-12054,18004、18005-12058
int[] iSendStation = {12058,12058};
int[] iSendStationR = { 12054,12054 };
if (startDevice == 18003)
//12056、12058无物,无12058入库任务,无终点位置到12058、12056送出指令,//
//12045、12054有物或者有12054入库任务或者有终点位置到12054,12045送出指令,没有18004、18005到41003出库任务
{
int r = 0; int s = 0;
foreach (int i in iSendStation)
{
devinfo = Model.CGetInfo.GetDeviceInfo(i);
if (devinfo.SplitByte_0 == 1)
{
s = s + 1;
}
}
string str = string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} ", iSendStation[1]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
str = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE F_ManageTaskIndex <> {2} and F_NumParam1<>{3} and (F_NumParam4 = {0} or F_NumParam4 = {1})", iSendStation[1], iSendStation[0], fid, iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
foreach (int i in iSendStationR)
{
devinfoR = Model.CGetInfo.GetDeviceInfo(i);
if (devinfoR.SplitByte_0 == 1)
{
r = r + 1;
}
}
str = string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} ", iSendStationR[1]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
r = r + 1;
}
str = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE F_ManageTaskIndex <> {2} and F_NumParam1<>{3} and (F_NumParam4 = {0} or F_NumParam4 = {1})", iSendStationR[1], iSendStationR[0], fid, iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
r = r + 1;
}
str = string.Format(" select * from T_Manage_Task where FENDDEVICE = {0} AND (FSTARTDEVICE = 18004 or FSTARTDEVICE = 18005)", iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
int iRoutID = CDisassembleTask.MinRouteID(startDevice, iSendStation[1], obj0);
int iRoutIDR = CDisassembleTask.MinRouteID(startDevice, iSendStationR[1],obj0);
if ((s == 0 && r > 0) || (iRoutID !=-1 && iRoutIDR ==-1))//12056-12058
{
object obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iSendStation[0], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_MonitorIndex = {0}", taskIndex, iSendStation[0], obj.ToString()));
//obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_DeviceOrder <8 and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iSendStation[1], taskIndex));
//dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM1 = {3},F_NUMPARAM4 = {1},F_AheadDetect = {2} WHERE F_ManageTaskIndex = {0} and F_NUMPARAM1 = {4}", fid, iSendStation[1], obj.ToString(), iSendStation[0], iDevice));
}
else
{
object obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_RouteID in (" +
"select F_RouteID from T_Base_Route_Device where F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} )) ", iSendStationR[0], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_MonitorIndex = {0}", taskIndex, iSendStationR[0], obj.ToString()));
//obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_DeviceOrder <8 and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iSendStationR[1], taskIndex));
//dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM1 = {3},F_NUMPARAM4 = {1},F_AheadDetect = {2} WHERE F_ManageTaskIndex = {0} and F_NUMPARAM1 = {4}", fid, iSendStationR[1], obj.ToString(), iSendStationR[0], iDevice));
}
}
else if (startDevice == 18004)//12048、12049、12050无物,无12050入库任务,无终点位置到12048、12050送出指令,
//12047、12053、12055有物或者有12047入库任务或者有终点位置到12047、12053送出指令,没有18005到41002出库任务
{
int r = 0; int s = 0;
foreach (int i in iSendStationR)
{
devinfoR = Model.CGetInfo.GetDeviceInfo(i);
if (devinfoR.SplitByte_0 == 1)
{
s = s + 1;
}
}
string str = string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} ", iSendStationR[1]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
str = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE F_ManageTaskIndex <> {2} and F_NumParam1<>{3} and (F_NumParam4 = {0} or F_NumParam4 = {1})", iSendStationR[1], iSendStationR[0], fid, iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
foreach (int i in iSendStation)
{
devinfo = Model.CGetInfo.GetDeviceInfo(i);
if (devinfo.SplitByte_0 == 1)
{
r = r + 1;
}
}
str = string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} ", iSendStation[1]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
r = r + 1;
}
str = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE F_ManageTaskIndex <> {2} and F_NumParam1<>{3} and (F_NumParam4 = {0} or F_NumParam4 = {1})", iSendStation[1], iSendStation[0], fid, iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
r = r + 1;
}
str = string.Format(" select * from T_Manage_Task where FENDDEVICE = {0} AND (FSTARTDEVICE = 18003)", iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
int iRoutID = CDisassembleTask.MinRouteID(startDevice, iSendStationR[1], obj0);
int iRoutIDR = CDisassembleTask.MinRouteID(startDevice, iSendStation [1], obj0);
if ((s == 0 && r > 0) || (iRoutID !=-1 && iRoutID ==-1)) //12048-12050
{
object obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_RouteID in (" +
"select F_RouteID from T_Base_Route_Device where F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} )) ", iSendStationR[0], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_MonitorIndex = {0}", taskIndex, iSendStationR[0], obj.ToString()));
//obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_DeviceOrder <8 and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iSendStationR[1], taskIndex));
//dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM1 = {3},F_NUMPARAM4 = {1},F_AheadDetect = {2} WHERE F_ManageTaskIndex = {0} and F_NUMPARAM1 = {4}", fid, iSendStationR[1], obj.ToString(), iSendStationR[0], iDevice));
}
else
{
object obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iSendStation[0], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_MonitorIndex = {0}", taskIndex, iSendStation[0], obj.ToString()));
//obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_DeviceOrder <8 and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iSendStation[1], taskIndex));
//dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM1 = {3},F_NUMPARAM4 = {1},F_AheadDetect = {2} WHERE F_ManageTaskIndex = {0} and F_NUMPARAM1 = {4}", fid, iSendStationR[1], obj.ToString(), iSendStation[0], iDevice));
}
}
else //18005、12059//12048、12049、12050无物,无12050入库任务,无终点位置到12048、12050送出指令,
//12047、12053、12055有物或者有12047入库任务或者有终点位置到12047、12055送出指令,没有18003、18004到41002出库任务
{
int r = 0; int s = 0;
foreach (int i in iSendStationR)
{
devinfoR = Model.CGetInfo.GetDeviceInfo(i);
if (devinfoR.SplitByte_0 == 1)
{
s = s + 1;
}
}
string str = string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} ", iSendStationR[1]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
str = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE F_ManageTaskIndex <> {2} and F_NumParam1<>{3} and (F_NumParam4 = {0} or F_NumParam4 = {1})", iSendStationR[1], iSendStationR[0], fid, iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
foreach (int i in iSendStation)
{
devinfo = Model.CGetInfo.GetDeviceInfo(i);
if (devinfo.SplitByte_0 == 1)
{
r = r + 1;
}
}
str = string.Format(" select * from T_Manage_Task where FSTARTDEVICE = {0} ", iSendStation[1]);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
r = r + 1;
}
str = string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE F_ManageTaskIndex <> {2} and F_NumParam1<>{3} and (F_NumParam4 = {0} or F_NumParam4 = {1})", iSendStation[1], iSendStation[0], fid, iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
r = r + 1;
}
str = string.Format(" select * from T_Manage_Task where FENDDEVICE = {0} AND (FSTARTDEVICE = 18003 or FSTARTDEVICE = 18004)", iDevice);
dv = dbo.ExceSQL(str).Tables[0].DefaultView;
if (dv.Count > 0)
{
s = s + 1;
}
int iRoutID = CDisassembleTask.MinRouteID(startDevice, iSendStationR[1], obj0);
int iRoutIDR = CDisassembleTask.MinRouteID(startDevice, iSendStation[1], obj0);
if ((s == 0 && r > 0) ||(iRoutID !=-1 && iRoutIDR ==-1)) //12048-12050
{
object obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_RouteID in (" +
"select F_RouteID from T_Base_Route_Device where F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} )) ", iSendStationR[0], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_MonitorIndex = {0}", taskIndex, iSendStationR[0], obj.ToString()));
//obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_DeviceOrder <8 and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iSendStationR[1], taskIndex));
//dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM1 = {3},F_NUMPARAM4 = {1},F_AheadDetect = {2} WHERE F_ManageTaskIndex = {0} and F_NUMPARAM1 = {4}", fid, iSendStationR[1], obj.ToString(), iSendStationR[0], iDevice));
}
else
{
object obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iSendStation[0], taskIndex));
dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM4 = {1},F_AheadDetect = '{2}' WHERE F_MonitorIndex = {0}", taskIndex, iSendStation[0], obj.ToString()));
//obj = dbo.GetSingle(string.Format("select F_AheadDetect from t_base_route_device where F_DeviceIndex = {0} and F_DeviceOrder <8 and F_RouteIDSub in (select F_RouteID from t_monitor_task where F_MonitorIndex = {1} ) ", iSendStation[1], taskIndex));
//dbo.ExecuteSql(string.Format(" UPDATE T_MONITOR_TASK SET F_NUMPARAM1 = {3},F_NUMPARAM4 = {1},F_AheadDetect = {2} WHERE F_ManageTaskIndex = {0} and F_NUMPARAM1 = {4}", fid, iSendStationR[1], obj.ToString(), iSendStation[0], iDevice));
}
}
break;
#endregion
default :
break;
}
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();
}
}
/// <summary>
/// 插入避让指令
/// </summary>
/// <param name="stackno">避让堆垛机</param>
/// <param name="order">指令</param>
/// <param name="Barcodecoor">避让到达的条码坐标</param>
/// <param name="layerhigh">避让堆垛机的货物层高度</param>
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)
{
sql.Clear();
if (CStaticClass.DBFactory == "OracleDBFactory")
{//20151120调度系统oracle的特殊语句
sql.Append(string.Format("SELECT ABS(MIN(BarcodeCoor - {0})) AS Expr1, XCoor, ZCoor FROM T_Base_BarcodeCoor where rownum=1 and BarcodeCoor<={0} and layerhigh<={1} and (brorder=0 or brorder={2}) GROUP BY XCoor, ZCoor ORDER BY Expr1", Barcodecoor, layerhigh, order));
}
else
{//20151120调度系统SQLServer的特殊语句
sql.Append(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));
}
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;//20151120调度系统oracle的特殊语句
}
else
{
sql.Clear();
if (CStaticClass.DBFactory == "OracleDBFactory")
{//20151120调度系统oracle的特殊语句
sql.Append(string.Format("SELECT ABS(MIN(BarcodeCoor - {0})) AS Expr1, XCoor, ZCoor FROM T_Base_BarcodeCoor where rownum=1 and BarcodeCoor>={0} and layerhigh<={1} and (brorder=0 or brorder={2}) GROUP BY XCoor, ZCoor ORDER BY Expr1", Barcodecoor, layerhigh, order));
}
else
{//20151120调度系统SQLServer的特殊语句
sql.Append(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));
}
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;//20151120调度系统oracle的特殊语句
}
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();
}
}
/// <summary>
/// 设备指令队列中是否存在可以关联堆垛机的取货命令
/// </summary>
/// <param name="Stackdev">堆垛机</param>
/// <param name="zxy">取货货位</param>
/// <param name="Correlzxy">关联货位</param>
/// <param name="nottaskindex">此次设备指令索引</param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 判断调度表T_Monitor_Task是否存在调度任务的设备和命令
/// </summary>
/// <param name="Mankind">调度任务类型</param>
/// <param name="ManFID">调度任务索引</param>
/// <param name="DeviceIndex">设备所引</param>
/// <param name="Order">设备命令</param>
/// <returns></returns>
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() ;
}
}
/// <summary>
/// 堆垛机是否存在避让指令正在运行
/// </summary>
/// <param name="DeviceIndex"></param>
/// <returns></returns>
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();
}
}
/// <summary>
/// 堆垛机是否存在避让指令等待运行
/// </summary>
/// <param name="DeviceIndex"></param>
/// <returns></returns>
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();
}
}
/// <summary>
/// 获取可关联的任务进行配多叉关联
/// </summary>
/// <param name="DevLanewayIOInfo">巷道出入口信息</param>
/// <param name="TaskIdx">设备指令索引</param>
/// <param name="CONTROLTASKTYPE">控制任务类型</param>
/// <param name="mti">控制任务类别</param>
/// <param name="fid">控制任务编号</param>
/// <param name="dtime">当前时间</param>
/// <returns></returns>
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();
}
}
/// <summary>
/// 计算输送线是否可以申请空托盘出库
/// </summary>
/// <param name="iMaxCount">输送线最大可以缓存空托盘数量</param>
/// <param name="istation">输送线申请位置</param>
/// <param name="ConveyorToCheck">需要检查载物的输送线组</param>
/// <param name="iMaxTask">可以同时存在的空托盘最大任务数量(此数量不大于最大缓存数量)</param>
/// <returns></returns>
bool CheckEmptyOutOK(int iMaxCount, int station, string ConveyorToCheck, int iMaxTask)
{
DataView dv = new DataView();
try
{
dv = dbo.ExceSQL(string.Format(" select * from T_Monitor_Task where F_DeviceCommandIndex = 6 and F_NumParam4 = {0} and F_Status > 0", station)).Tables[0].DefaultView;
if (dv.Count > iMaxTask)
{
return false;// 现有已经发送的送出命令大于设定值,可能有人工的任务
}
else
{
iMaxCount = iMaxCount - dv.Count;
}
//dv = dbo.ExceSQL(string.Format(" select * from T_Manage_Task where FENDDEVICE = {0}", station)).Tables[0].DefaultView;
//if (dv.Count > iMaxTask)
//{
// return false;// 现有出库任务大于设定值,可能有人工出库的任务
//}
//else
//{
// iMaxCount = iMaxCount - dv.Count;
//}
#region 检查输送线有货状态
char[] cc = new char[1];
cc[0] = ';';
string[] Conveyor = ConveyorToCheck.Split(cc);
for (int i = Conveyor.GetLowerBound(0); i <= Conveyor.GetUpperBound(0); i++)
{
if (Conveyor[i].Trim().Length <= 0) continue;
Model.MDevice devNext = Model.CGetInfo.GetDeviceInfo(Convert.ToInt32(Conveyor[i])); // 检测下一个输送机开关和设备状态
if ((devNext.RunState > 1 && devNext.RunState < 5) || devNext.SplitByte_0 != 0)
{
// 故障,离线,停用状态认为有货,防止出库任务多
iMaxCount--;
}
}
#endregion
// 检查任务申请表是否有未处理的申请
//dv = dboM.ExceSQL(string.Format(" select * from io_control_apply where device_code = {0} and apply_task_status = 0", station)).Tables[0].DefaultView;
//if (dv.Count > 0)
//{
// iMaxCount -= dv.Count;
// // return false;
//}
// 检查io_control 是否有没有获取的任务
//dv = dboM.ExceSQL(string.Format("select * from io_control where control_status = 0 and end_device_code = '{0}'", station)).Tables[0].DefaultView;
//if (dv.Count > 0)
//{
// iMaxCount -= dv.Count;
// // return false;
//}
// 还可以加入时间间隔校验
if (iMaxCount <= 0)
{
return false; //20150719 没有缓存位,返回
}
return true;
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
/// <summary>
/// 检查是否有指定终点的出库任务正在执行,返回正在执行任务数量。
/// </summary>
/// <param name="EndDevice">出库终点输送线</param>
/// <param name="startLane">检查巷道起点编号</param>
/// <param name="endLane">检查巷道终点编号</param>
/// <returns>返回正在执行中的出库任务数量</returns>
int CheckLaneIfHaveRunningOut(int iEndDevice, string startLane, string endLane)
{
DataView dv = new DataView();
try
{
dv = dbo.ExceSQL(string.Format("select * from T_Manage_Task where FENDDEVICE = {0} and FSTATUS > 0 and (FSTARTDEVICE between {1} and {2})", iEndDevice,startLane,endLane)).Tables[0].DefaultView;
return dv.Count;
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
}
}