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.
2986 lines
144 KiB
2986 lines
144 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
using System.Data.SqlClient;
|
|
using CommonLib;
|
|
using DBFactory;
|
|
using System.Data;
|
|
namespace WcfControlMonitorLib
|
|
{
|
|
static class CGeneralFunction
|
|
{
|
|
static StringBuilder sql = new StringBuilder();
|
|
static DBOperator dbo = CListenAGVState.dbo;
|
|
|
|
/// <summary>
|
|
/// 多叉关联任务是否能同步运行
|
|
/// </summary>
|
|
/// <param name="monitorIndex">设备指令索引</param>
|
|
/// <returns></returns>
|
|
public static bool DoubleForkIfSync(int monitorIndex, int devIndex, int devKind)
|
|
{//查找关联的调度任务(主任务或者辅助任务);输送机与堆垛机区别对待
|
|
//如果只能找到关联任务未被拆分,那么认为能同步运行20100323
|
|
int mankind = GetManageTaskKindIndexFromMonitor(monitorIndex);
|
|
int FID = GetManageTaskIndexfromMonitor(monitorIndex);
|
|
int devOrder = GetDeviceOrderFromMonitor(monitorIndex);
|
|
int dfx = GetDoubleForkX(mankind, FID, devIndex, devOrder);
|
|
int mx = GetXCoorFromMonitor(monitorIndex, devIndex, devOrder);
|
|
int dfy = GetDoubleForkY(mankind, FID, devIndex, devOrder);
|
|
int my = GetYCoorFromMonitor(monitorIndex, devIndex, devOrder);
|
|
int dfz = GetDoubleForkZ(mankind, FID, devIndex, devOrder);
|
|
int mz = GetZCoorFromMonitor(monitorIndex, devIndex, devOrder);
|
|
if (GetDoubleForkUnIntoStep(monitorIndex) == true) return true;
|
|
|
|
switch (devKind)
|
|
{
|
|
case 1:
|
|
//如果主任务和副任务的列数都是1列,则是1121、1122顶升机构,可以同步
|
|
if (1 == GetDoubleForkX(mankind, FID, devIndex, devOrder) && (GetXCoorFromMonitor(monitorIndex, devIndex, devOrder) == 1))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
//堆垛机的同排,同层,临列可以同步并且ST_CELL的FDoubleFork值匹配
|
|
|
|
|
|
if ((Math.Abs(dfx - mx) == 1) && (dfy == my) && (mz == dfz))
|
|
{
|
|
if (EqualMonitorDoubleFork(mankind, FID, devIndex, devOrder) == true)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
|
|
case 2:
|
|
//输送机同步
|
|
return true;
|
|
case 6:
|
|
//AGV临列可以同步并且ST_CELL的F_UseAwayFork值匹配
|
|
|
|
|
|
if (Math.Abs(dfx - mx) == 1)
|
|
{
|
|
if (EqualAGVGateDoubleFork(mankind, FID, devIndex, devOrder) == true)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
|
|
|
|
default:
|
|
return false;
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 获得双叉控制的堆垛机的送货任务(已经分配远货叉或者近货叉的任务)的值
|
|
/// </summary>
|
|
/// <param name="monitorIndex">设备指令索引</param>
|
|
/// <returns></returns>
|
|
public static string GetUseAwayFork(int monitorIndex)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_UseAwayFork FROM T_Monitor_Task WHERE (F_MonitorIndex = " ).Append( monitorIndex ).Append( ")");
|
|
DataView dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return dv[0][0].ToString();
|
|
}
|
|
else
|
|
{
|
|
return "-";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取双叉控制的堆垛机的取货任务(尚未指定应该使用哪个货叉)是否使用远货叉(主货叉):0,近货叉;1远货叉
|
|
/// </summary>
|
|
/// <param name="z">排</param>
|
|
/// <param name="x">列</param>
|
|
/// <param name="y">层</param>
|
|
/// <param name="FWAREHOUSE">库房索引</param>
|
|
/// <param name="Mankind">任务类型</param>
|
|
/// <param name="ManFID">调度任务索引</param>
|
|
/// <param name="devIndex">设备索引</param>
|
|
/// <param name="devOrder">指令</param>
|
|
/// <returns></returns>
|
|
public static int GetUseAwayFork(int monitorIndex, int devIndex, int devOrder)
|
|
{
|
|
int z = GetZCoorFromMonitor(monitorIndex, devIndex, devOrder);
|
|
int x = GetXCoorFromMonitor(monitorIndex, devIndex, devOrder);
|
|
int y = GetYCoorFromMonitor(monitorIndex, devIndex, devOrder);
|
|
|
|
string FWAREHOUSE = GetWAREHOUSEFromSTCELL(devIndex);
|
|
int Mankind = GetManageTaskKindIndexFromMonitor(monitorIndex);
|
|
int ManFID = GetManageTaskIndexfromMonitor(monitorIndex);
|
|
|
|
DataView dv; int UseAwayFork = 1;
|
|
try
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FDoubleFork FROM ST_CELL WHERE (FWAREHOUSE='" ).Append( FWAREHOUSE
|
|
).Append( "') and (F_Z = " ).Append( z ).Append( ") AND (F_X = " ).Append( x ).Append( ") AND (F_Y = " ).Append( y ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
UseAwayFork = Convert.ToInt32(dv[0][0]);
|
|
}
|
|
else
|
|
{
|
|
UseAwayFork = 0;
|
|
}
|
|
switch (UseAwayFork)
|
|
{
|
|
case 0://可用任何一个货叉:
|
|
int xcoor = GetDoubleForkX(Mankind, ManFID, devIndex, devOrder);
|
|
if (xcoor != -1)
|
|
{
|
|
//根据关联任务的货位判断使用近货叉(列坐标小)或者远货叉(列坐标大)
|
|
if (xcoor != x)
|
|
{
|
|
if (xcoor < x)
|
|
{
|
|
UseAwayFork = 1;
|
|
}
|
|
else
|
|
{
|
|
UseAwayFork = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//列坐标相同的,判断层坐标,近货叉(层坐标小)或者远货叉(层坐标大)
|
|
int ycoor = GetDoubleForkY(Mankind, ManFID, devIndex, devOrder);
|
|
if (ycoor != -1)
|
|
{
|
|
if (ycoor != y)
|
|
{
|
|
if (ycoor < y)
|
|
{
|
|
UseAwayFork = 1;
|
|
}
|
|
else
|
|
{
|
|
UseAwayFork = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//列和层都相同的,判断排坐标,近货叉(排坐标小)或者远货叉(排坐标大)
|
|
int zcoor = GetDoubleForkZ(Mankind, ManFID, devIndex, devOrder);
|
|
if (zcoor != -1)
|
|
{
|
|
if (zcoor != z)
|
|
{
|
|
if (zcoor < z)
|
|
{
|
|
UseAwayFork = 1;
|
|
}
|
|
else
|
|
{
|
|
UseAwayFork = 0;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
UseAwayFork = 1;
|
|
}
|
|
break;
|
|
case 1://只能用近叉
|
|
UseAwayFork = 0;
|
|
break;
|
|
case 2://只能用远叉
|
|
UseAwayFork = 1;
|
|
break;
|
|
}
|
|
return UseAwayFork;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
}
|
|
}
|
|
|
|
public static int GetDoubleForkFromST_CELL(int z, int x, int y, string FWAREHOUSE)
|
|
{
|
|
DataView dv; int UseAwayFork = 1;
|
|
try
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FDoubleFork FROM ST_CELL WHERE (FWAREHOUSE='" ).Append( FWAREHOUSE
|
|
).Append( "') and (F_Z = " ).Append( z ).Append( ") AND (F_X = " ).Append( x ).Append( ") AND (F_Y = " ).Append( y ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
UseAwayFork = Convert.ToInt32(dv[0][0]);
|
|
}
|
|
else
|
|
{
|
|
UseAwayFork = 0;
|
|
}
|
|
|
|
return UseAwayFork;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
}
|
|
}
|
|
|
|
|
|
public static string GetWAREHOUSEFromSTCELL(int stackIndex)
|
|
{
|
|
DataView dv;
|
|
try
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FWAREHOUSE FROM ST_CELL WHERE (FStack = " ).Append( stackIndex ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return dv[0][0].ToString();
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally { dv = null; }
|
|
}
|
|
/// <summary>
|
|
/// 查找多叉关联任务的列坐标
|
|
/// </summary>
|
|
/// <param name="mankind">任务类型</param>
|
|
/// <param name="fid">调度任务索引</param>
|
|
/// <param name="devIdx">设备索引</param>
|
|
/// <param name="devOrder">设备指令</param>
|
|
/// <returns></returns>
|
|
public static int GetDoubleForkX(int mankind, int fid, int devIdx, int devOrder)
|
|
{
|
|
DataView dv;
|
|
string xc = "F_NumParam2";
|
|
if (GetDeviceKindIdx(devIdx) == 1)
|
|
{
|
|
if (devOrder == 4)
|
|
{
|
|
xc = "F_NumParam2";
|
|
}
|
|
else if (devOrder == 5)
|
|
{
|
|
xc = "F_NumParam5";
|
|
}
|
|
}
|
|
try
|
|
{
|
|
//查找被关联辅助设备指令索引的列坐标
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT " ).Append( xc ).Append( " FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.F_RELATIVECONTORLID = T_Monitor_Task.F_ManageTaskIndex " ).Append(
|
|
" AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " ).Append( mankind ).Append( ") AND (FID = " ).Append(
|
|
fid ).Append( ") and (F_DeviceIndex=" ).Append( devIdx ).Append( " and F_DeviceCommandIndex=" ).Append( devOrder ).Append( ")");
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0][xc]);
|
|
}
|
|
|
|
//查找关联自己的主设备指令索引的列坐标
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT " ).Append( xc ).Append( " FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.FID = T_Monitor_Task.F_ManageTaskIndex " ).Append(
|
|
" AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " ).Append( mankind ).Append( ") AND (F_RELATIVECONTORLID = " ).Append(
|
|
fid ).Append( ") and (F_DeviceIndex=" ).Append( devIdx ).Append( " and F_DeviceCommandIndex=" ).Append( devOrder ).Append( ")");
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0][xc]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 查找多叉关联任务的层坐标
|
|
/// </summary>
|
|
/// <param name="mankind">任务类型</param>
|
|
/// <param name="fid">调度任务索引</param>
|
|
/// <param name="devIdx">设备索引</param>
|
|
/// <param name="devOrder">设备指令</param>
|
|
/// <returns></returns>
|
|
public static int GetDoubleForkY(int mankind, int fid, int devIdx, int devOrder)
|
|
{
|
|
DataView dv;
|
|
string yc = "F_NumParam3";
|
|
if (GetDeviceKindIdx(devIdx) == 1)
|
|
{
|
|
if (devOrder == 4)
|
|
{
|
|
yc = "F_NumParam3";
|
|
}
|
|
else if (devOrder == 5)
|
|
{
|
|
yc = "F_NumParam6";
|
|
}
|
|
}
|
|
try
|
|
{
|
|
//查找被关联辅助设备指令索引的层坐标
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT " ).Append( yc ).Append( " FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.F_RELATIVECONTORLID = T_Monitor_Task.F_ManageTaskIndex " ).Append(
|
|
" AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " ).Append( mankind ).Append( ") AND (FID = " ).Append(
|
|
fid ).Append( ") and (F_DeviceIndex=" ).Append( devIdx ).Append( " and F_DeviceCommandIndex=" ).Append( devOrder ).Append( ")");
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0][yc]);
|
|
}
|
|
|
|
//查找关联自己的主设备指令索引的层坐标
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT " ).Append( yc ).Append( " FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.FID = T_Monitor_Task.F_ManageTaskIndex " ).Append(
|
|
" AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " ).Append( mankind ).Append( ") AND (F_RELATIVECONTORLID = " ).Append(
|
|
fid ).Append( ") and (F_DeviceIndex=" ).Append( devIdx ).Append( " and F_DeviceCommandIndex=" ).Append( devOrder ).Append( ")");
|
|
;
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0][yc]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 查找多叉关联任务的排坐标
|
|
/// </summary>
|
|
/// <param name="mankind">任务类型</param>
|
|
/// <param name="fid">调度任务索引</param>
|
|
/// <param name="devIdx">设备索引</param>
|
|
/// <param name="devOrder">设备指令</param>
|
|
/// <returns></returns>
|
|
public static int GetDoubleForkZ(int mankind, int fid, int devIdx, int devOrder)
|
|
{
|
|
DataView dv;
|
|
string zc = "F_NumParam1";
|
|
if (GetDeviceKindIdx(devIdx) == 1)
|
|
{
|
|
if (devOrder == 4)
|
|
{
|
|
zc = "F_NumParam1";
|
|
}
|
|
else if (devOrder == 5)
|
|
{
|
|
zc = "F_NumParam4";
|
|
}
|
|
}
|
|
try
|
|
{
|
|
//查找被关联辅助设备指令索引的排坐标
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT " ).Append( zc ).Append( " FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.F_RELATIVECONTORLID = T_Monitor_Task.F_ManageTaskIndex " ).Append(
|
|
" AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " ).Append( mankind ).Append( ") AND (FID = " ).Append(
|
|
fid ).Append( ") and (F_DeviceIndex=" ).Append( devIdx ).Append( " and F_DeviceCommandIndex=" ).Append( devOrder ).Append( ")");
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0][zc]);
|
|
}
|
|
|
|
//查找关联自己的主设备指令索引的排坐标
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT " ).Append( zc ).Append( " FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.FID = T_Monitor_Task.F_ManageTaskIndex " ).Append(
|
|
" AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " ).Append( mankind ).Append( ") AND (F_RELATIVECONTORLID = " ).Append(
|
|
fid ).Append( ") and (F_DeviceIndex=" ).Append( devIdx ).Append( " and F_DeviceCommandIndex=" ).Append( devOrder ).Append( ")");
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0][zc]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查找多叉关联任务的ST_CELL表的使用哪个货叉属性是否相同
|
|
/// </summary>
|
|
/// <param name="mankind">任务类型</param>
|
|
/// <param name="fid">调度任务索引</param>
|
|
/// <param name="devIdx">设备索引</param>
|
|
/// <param name="devOrder">设备指令</param>
|
|
/// <returns></returns>
|
|
public static bool EqualMonitorDoubleFork(int mankind, int fid, int devIdx, int devOrder)
|
|
{
|
|
DataView dv; char DoubleFork = '0', DoubleFork1 = '0';
|
|
string xc = "F_NumParam2"; string yc = "F_NumParam3"; string zc = "F_NumParam1";
|
|
if (GetDeviceKindIdx(devIdx) == 1)
|
|
{
|
|
if ((devOrder == 4) || (devOrder == 2))
|
|
{
|
|
xc = "F_NumParam2";
|
|
yc = "F_NumParam3";
|
|
zc = "F_NumParam1";
|
|
}
|
|
else if ((devOrder == 5) || (devOrder == 3))
|
|
{
|
|
xc = "F_NumParam5";
|
|
yc = "F_NumParam6";
|
|
zc = "F_NumParam4";
|
|
}
|
|
}
|
|
|
|
|
|
try
|
|
{
|
|
|
|
int z = 0, x = 0, y = 0, z1 = 0, x1 = 0, y1 = 0;
|
|
//查找被关联辅助设备指令索引的列坐标
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT " ).Append( zc ).Append( "," ).Append( xc ).Append( "," ).Append( yc ).Append( ",F_UseAwayFork FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.F_RELATIVECONTORLID = T_Monitor_Task.F_ManageTaskIndex " ).Append(
|
|
" AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " ).Append( mankind ).Append( ") AND (FID = " ).Append(
|
|
fid ).Append( ") and (F_DeviceIndex=" ).Append( devIdx ).Append( " and F_DeviceCommandIndex=" ).Append( devOrder ).Append( ")");
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
z = Convert.ToInt32(dv[0][zc]);
|
|
x = Convert.ToInt32(dv[0][xc]);
|
|
y = Convert.ToInt32(dv[0][yc]);
|
|
DoubleFork = Convert.ToChar(dv[0]["F_UseAwayFork"]);
|
|
}
|
|
else
|
|
{
|
|
//查找关联自己的主设备指令索引的列坐标
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT " ).Append( zc ).Append( "," ).Append( xc ).Append( "," ).Append( yc ).Append( ",F_UseAwayFork FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.FID = T_Monitor_Task.F_ManageTaskIndex " ).Append(
|
|
" AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " ).Append( mankind ).Append( ") AND (F_RELATIVECONTORLID = " ).Append(
|
|
fid ).Append( ") and (F_DeviceIndex=" ).Append( devIdx ).Append( " and F_DeviceCommandIndex=" ).Append( devOrder ).Append( ")");
|
|
;
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
z = Convert.ToInt32(dv[0][zc]);
|
|
x = Convert.ToInt32(dv[0][xc]);
|
|
y = Convert.ToInt32(dv[0][yc]);
|
|
DoubleFork = Convert.ToChar(dv[0]["F_UseAwayFork"]);
|
|
}
|
|
|
|
}
|
|
if ((z == 0) && (x == 0) && (y == 0))
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT " ).Append( zc ).Append( "," ).Append( xc ).Append( "," ).Append( yc ).Append( ",F_UseAwayFork FROM T_Monitor_Task Where ( F_ManageTASKKINDINDEX = " ).Append( mankind ).Append( ") AND (F_ManageTaskIndex = " ).Append(
|
|
fid ).Append( ") and (F_DeviceIndex=" ).Append( devIdx ).Append( " and F_DeviceCommandIndex=" ).Append( devOrder ).Append( ")");
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
z1 = Convert.ToInt32(dv[0][zc]);
|
|
x1 = Convert.ToInt32(dv[0][xc]);
|
|
y1 = Convert.ToInt32(dv[0][yc]);
|
|
DoubleFork1 = Convert.ToChar(dv[0]["F_UseAwayFork"]);
|
|
if (((x1 > x) && (DoubleFork1 > DoubleFork)) || ((x > x1) && (DoubleFork > DoubleFork1)))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查找多叉关联任务的T_Base_AGV_Gate表的货叉属性是否匹配
|
|
/// </summary>
|
|
/// <param name="mankind">任务类型</param>
|
|
/// <param name="fid">调度任务索引</param>
|
|
/// <param name="devIdx">设备索引</param>
|
|
/// <param name="devOrder">设备指令</param>
|
|
/// <returns></returns>
|
|
public static bool EqualAGVGateDoubleFork(int mankind, int fid, int devIdx, int devOrder)
|
|
{
|
|
//20110110 1运行,2取货,3送货,4取送货,5允许AGV移载
|
|
DataView dv;
|
|
string xc = "F_NumParam2";
|
|
if (GetDeviceKindIdx(devIdx) == 6)
|
|
{
|
|
if (devOrder == 1)
|
|
{
|
|
xc = "F_NumParam5";
|
|
}
|
|
else if ((devOrder == 2) || (devOrder == 5))
|
|
{
|
|
xc = "F_NumParam2";
|
|
}
|
|
else if (devOrder == 3)
|
|
{
|
|
xc = "F_NumParam5";
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
|
|
int x = 0, x1 = 0;
|
|
int channelleft = 0, channelleft1 = 0, xd = 0, xd1 = 0;
|
|
//查找被关联辅助设备指令索引的列坐标
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT " ).Append( xc ).Append( " FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.F_RELATIVECONTORLID = T_Monitor_Task.F_ManageTaskIndex " ).Append(
|
|
" AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " ).Append( mankind ).Append( ") AND (FID = " ).Append(
|
|
fid ).Append( ") and (F_DeviceIndex=" ).Append( devIdx ).Append( " and F_DeviceCommandIndex=" ).Append( devOrder ).Append( ")");
|
|
;
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
|
|
xd = Convert.ToInt32(dv[0][xc]);
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_Sequence FROM T_Base_AGV_Gate WHERE (F_AGVGateDeviceIndex = " ).Append( xd ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
x = Convert.ToInt32(dv[0]["F_Sequence"]);
|
|
}
|
|
else
|
|
{
|
|
x = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//查找关联自己的主设备指令索引的列坐标
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT " ).Append( xc ).Append( " FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.FID = T_Monitor_Task.F_ManageTaskIndex " ).Append(
|
|
" AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " ).Append( mankind ).Append( ") AND (F_RELATIVECONTORLID = " ).Append(
|
|
fid ).Append( ") and (F_DeviceIndex=" ).Append( devIdx ).Append( " and F_DeviceCommandIndex=" ).Append( devOrder ).Append( ")");
|
|
;
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
xd = Convert.ToInt32(dv[0][xc]);
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_Sequence FROM T_Base_AGV_Gate WHERE (F_AGVGateDeviceIndex = " ).Append( xd ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
x = Convert.ToInt32(dv[0]["F_Sequence"]);
|
|
}
|
|
else
|
|
{
|
|
x = 0;
|
|
}
|
|
}
|
|
|
|
}
|
|
if (x == 0)
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT " ).Append( xc ).Append( " FROM T_Monitor_Task Where ( F_ManageTASKKINDINDEX = " ).Append( mankind ).Append( ") AND (F_ManageTaskIndex = " ).Append(
|
|
fid ).Append( ") and (F_DeviceIndex=" ).Append( devIdx ).Append( " and F_DeviceCommandIndex=" ).Append( devOrder ).Append( ")");
|
|
;
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
xd1 = Convert.ToInt32(dv[0][xc]);
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_Sequence FROM T_Base_AGV_Gate WHERE (F_AGVGateDeviceIndex = " ).Append( xd1 ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
x1 = Convert.ToInt32(dv[0]["F_Sequence"]);
|
|
}
|
|
else
|
|
{
|
|
x1 = 0;
|
|
}
|
|
int DoubleFork = 0, DoubleFork1 = 0;
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_UseAwayFork,F_IfChannelLeft FROM T_Base_AGV_Gate WHERE F_AGVGateDeviceIndex =" ).Append( xd);
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
DoubleFork = Convert.ToInt32(dv[0]["F_UseAwayFork"]);
|
|
channelleft = Convert.ToInt32(dv[0]["F_IfChannelLeft"]);
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_UseAwayFork,F_IfChannelLeft FROM T_Base_AGV_Gate WHERE F_AGVGateDeviceIndex =" ).Append( xd1);
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
DoubleFork1 = Convert.ToInt32(dv[0]["F_UseAwayFork"]);
|
|
channelleft1 = Convert.ToInt32(dv[0]["F_IfChannelLeft"]);
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
if ((((x1 > x) && (DoubleFork1 > DoubleFork)) || ((x > x1) && (DoubleFork > DoubleFork1))) && (channelleft == channelleft1))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 在设备指令队列表获取Z 排坐标
|
|
/// </summary>
|
|
/// <param name="monitorIndex">设备指令索引</param>
|
|
/// <returns></returns>
|
|
public static int GetZCoorFromMonitor(int monitorIndex, int devIdx, int devOrder)
|
|
{
|
|
DataView dv;
|
|
string zc = "F_NumParam1";
|
|
if (GetDeviceKindIdx(devIdx) == 1)
|
|
{
|
|
if (devOrder == 4)
|
|
{
|
|
zc = "F_NumParam1";
|
|
}
|
|
else if (devOrder == 5)
|
|
{
|
|
zc = "F_NumParam4";
|
|
}
|
|
}
|
|
try
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT " ).Append( zc ).Append( " 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][0]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 在设备指令队列表获取X 列坐标
|
|
/// </summary>
|
|
/// <param name="monitorIndex">设备指令索引</param>
|
|
/// <returns></returns>
|
|
public static int GetXCoorFromMonitor(int monitorIndex, int devIdx, int devOrder)
|
|
{
|
|
DataView dv;
|
|
string xc = "F_NumParam2";
|
|
if (GetDeviceKindIdx(devIdx) == 1)
|
|
{
|
|
if (devOrder == 4)
|
|
{
|
|
xc = "F_NumParam2";
|
|
}
|
|
else if (devOrder == 5)
|
|
{
|
|
xc = "F_NumParam5";
|
|
}
|
|
}
|
|
try
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT " ).Append( xc ).Append( " 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][0]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 在设备指令队列表获取Y 层坐标
|
|
/// </summary>
|
|
/// <param name="monitorIndex">设备指令索引</param>
|
|
/// <returns></returns>
|
|
public static int GetYCoorFromMonitor(int monitorIndex, int devIdx, int devOrder)
|
|
{
|
|
DataView dv;
|
|
string yc = "F_NumParam3";
|
|
if (GetDeviceKindIdx(devIdx) == 1)
|
|
{
|
|
if (devOrder == 4)
|
|
{
|
|
yc = "F_NumParam3";
|
|
}
|
|
else if (devOrder == 5)
|
|
{
|
|
yc = "F_NumParam6";
|
|
}
|
|
}
|
|
try
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT " ).Append( yc ).Append( " 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][0]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回多叉关联设备指令信息:【0】设备指令索引【1】提前检测【2】设备索引【3】路径
|
|
/// </summary>
|
|
/// <param name="monitorIndex">设备指令索引</param>
|
|
/// <param name="devIdx">设备索引</param>
|
|
/// <returns></returns>
|
|
public static string[] GetDoubleForkMonitorInfo(int monitorIndex, int devIdx)
|
|
{
|
|
DataView dv;
|
|
|
|
string[] rr = null;
|
|
try
|
|
{
|
|
int mankind = GetManageTaskKindIndexFromMonitor(monitorIndex);
|
|
int fid = GetManageTaskIndexfromMonitor(monitorIndex);
|
|
int devOrder = GetDeviceOrderFromMonitor(monitorIndex);
|
|
//查找被关联辅助设备指令索引的列坐标
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_MonitorIndex,F_AheadDetect,F_DeviceIndex,F_RouteID FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.F_RELATIVECONTORLID = T_Monitor_Task.F_ManageTaskIndex " ).Append(
|
|
" AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " ).Append( mankind ).Append( ") AND (FID = " ).Append(
|
|
fid ).Append( ") and (F_DeviceIndex=" ).Append( devIdx ).Append( " and F_DeviceCommandIndex=" ).Append( devOrder ).Append( ")");
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
rr = new string[4];
|
|
rr[0] = dv[0]["F_MonitorIndex"].ToString();
|
|
rr[1] = dv[0]["F_AheadDetect"].ToString();
|
|
rr[2] = dv[0]["F_DeviceIndex"].ToString();
|
|
rr[3] = dv[0]["F_RouteID"].ToString();
|
|
}
|
|
else
|
|
{
|
|
//查找关联自己的主设备指令索引的列坐标
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_MonitorIndex,F_AheadDetect,F_DeviceIndex,F_RouteID FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.FID = T_Monitor_Task.F_ManageTaskIndex " ).Append(
|
|
" AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " ).Append( mankind ).Append( ") AND (F_RELATIVECONTORLID = " ).Append(
|
|
fid ).Append( ") and (F_DeviceIndex=" ).Append( devIdx ).Append( " and F_DeviceCommandIndex=" ).Append( devOrder ).Append( ")");
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
rr = new string[4];
|
|
rr[0] = dv[0]["F_MonitorIndex"].ToString();
|
|
rr[1] = dv[0]["F_AheadDetect"].ToString();
|
|
rr[2] = dv[0]["F_DeviceIndex"].ToString();
|
|
rr[3] = dv[0]["F_RouteID"].ToString();
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
return rr;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
rr = null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回未拆分的多叉关联设备指令,true 代表有未拆分的多叉关联设备指令
|
|
/// </summary>
|
|
/// <param name="monitorIndex">设备指令索引</param>
|
|
/// <returns></returns>
|
|
public static bool GetDoubleForkUnIntoStep(int monitorIndex)
|
|
{
|
|
DataView dv;
|
|
try
|
|
{
|
|
int mankind = GetManageTaskKindIndexFromMonitor(monitorIndex);
|
|
int fid = GetManageTaskIndexfromMonitor(monitorIndex);
|
|
//查找被关联辅助设备指令索引的列坐标
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_RELATIVECONTORLID FROM T_Manage_Task Where (T_Manage_Task.F_RELATIVECONTORLID <>-1 ) and ( F_ManageTaskKindIndex = " ).Append( mankind ).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 FID FROM T_Manage_Task Where ( F_ManageTaskKindIndex = " ).Append( mankind ).Append( ") AND (FID = " ).Append(
|
|
dv[0][0] ).Append( " and FIntoStepOK<>'1')");
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
//查找关联自己的主设备指令索引的列坐标
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FID FROM T_Manage_Task Where ( F_ManageTaskKindIndex = " ).Append( mankind ).Append( ") AND (F_RELATIVECONTORLID = " ).Append(
|
|
fid ).Append( ")");
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FID FROM T_Manage_Task Where ( F_ManageTaskKindIndex = " ).Append( mankind ).Append( ") AND (FID = " ).Append(
|
|
dv[0][0] ).Append( " and FIntoStepOK<>'1')");
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
}
|
|
}
|
|
|
|
public static int GetManageTaskIndexfromMonitor(int monitorIdx)
|
|
{
|
|
//20100108
|
|
DataView dv;
|
|
try
|
|
{
|
|
//20100108
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_ManageTaskIndex FROM T_Monitor_Task WHERE (F_MonitorIndex = " ).Append( monitorIdx ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_ManageTaskIndex"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dv = null;
|
|
}
|
|
}
|
|
public static int GetManageTaskKindIndexFromMonitor(int monitorIdx)
|
|
{//20100108
|
|
DataView dv;
|
|
try
|
|
{
|
|
//20100108
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_ManageTaskKindIndex FROM T_Monitor_Task WHERE (F_MonitorIndex = " ).Append( monitorIdx ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_ManageTaskKindIndex"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dv = null;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 在调度队列中找到设备命令
|
|
/// </summary>
|
|
/// <param name="MonitorIndex">调度所引</param>
|
|
/// <returns></returns>
|
|
public static int GetDeviceOrderFromMonitor(int MonitorIndex)
|
|
{
|
|
//20100108
|
|
DataView dv;
|
|
try
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select F_DeviceCommandIndex from T_Monitor_Task where (F_DeviceCommandIndex IS NOT NULL) and F_MonitorIndex=" ).Append( MonitorIndex);
|
|
;
|
|
//20100108
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_DeviceCommandIndex"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
}
|
|
}
|
|
|
|
public static int GetDeviceKindIdx(int devIdx)
|
|
{
|
|
object ob;
|
|
try
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_DeviceKindIndex FROM T_Base_Device WHERE (F_DeviceIndex = " ).Append( devIdx ).Append( ")");
|
|
ob = dbo.GetSingle(sql.ToString());
|
|
|
|
if (ob != null)
|
|
{
|
|
return Convert.ToInt32(ob);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public static int GetDeviceIndexFromMonitor(int MonitorIndex)
|
|
{
|
|
//20100108
|
|
DataView dv;
|
|
try
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select F_DeviceIndex from T_Monitor_Task where (F_DeviceIndex IS NOT NULL) and F_MonitorIndex=" ).Append( MonitorIndex);
|
|
|
|
//20100108
|
|
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 = null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creator:Richard.liu
|
|
/// 独立线程,监听AGV反馈的数据,并进行解析
|
|
/// </summary>
|
|
public static class CListenAGVState
|
|
{
|
|
public static event CDataSourceChangeEventHandler DataChange;
|
|
public static event CUpdateDBEventHandler UpdateDB;
|
|
|
|
public static void OnDataChange(CDataChangeEventArgs e)
|
|
{
|
|
if (DataChange != null)
|
|
{
|
|
DataChange(null, e);
|
|
}
|
|
}
|
|
public static void OnUpdateDB(CUpdateDBChangeEventArgs e)
|
|
{
|
|
if (UpdateDB != null)
|
|
{
|
|
UpdateDB(null,e);
|
|
}
|
|
}
|
|
|
|
//记录AGV操作地址号
|
|
static ushort[] AgvActive = new ushort[4];
|
|
//static bool _exitThread = false;
|
|
static string _tcpServerError="";
|
|
|
|
/// <summary>
|
|
/// 监听接收AGV发送的数据时发生的故障
|
|
/// </summary>
|
|
public static string TcpServerError
|
|
{
|
|
get { return CListenAGVState._tcpServerError; }
|
|
set { CListenAGVState._tcpServerError = value; }
|
|
}
|
|
static string _receiveOK = null;
|
|
/// <summary>
|
|
/// 监听到该AGV车的所有队列完成
|
|
/// </summary>
|
|
public static string ReceiveOK
|
|
{
|
|
get { return CListenAGVState._receiveOK; }
|
|
set { CListenAGVState._receiveOK = value; }
|
|
}
|
|
static StringBuilder sql = new StringBuilder();
|
|
static Thread mythread;
|
|
static Socket Localsocket;
|
|
static bool exitThread = false;//20091107
|
|
static bool ConnectedServer = false;
|
|
static byte[] _GetData = new byte[8192];
|
|
public static DBOperator dbo = new DBOperator();
|
|
static DBOperator dboM = new DBOperator("ManConnString", "ManDBFactory");
|
|
|
|
|
|
/// <summary>
|
|
/// 开始监听接收到的数据
|
|
/// </summary>
|
|
private static void BeginListen()
|
|
{
|
|
//20091107
|
|
while (!exitThread )
|
|
{
|
|
|
|
try
|
|
{
|
|
int gcount = 0;
|
|
if (ConnectedServer == false)
|
|
{
|
|
if (ConnectTcpIPServer() == false)
|
|
{
|
|
Thread.Sleep(200);//20100710
|
|
continue;
|
|
}
|
|
}
|
|
|
|
Localsocket.Listen(1);
|
|
try
|
|
|
|
{
|
|
//20090920
|
|
if (SocketsTCPIP.CClientTCPIP.ClientSocket.Connected == true)
|
|
{
|
|
|
|
gcount = SocketsTCPIP.CClientTCPIP.ClientSocket.Receive(_GetData);
|
|
}
|
|
else
|
|
{
|
|
SocketsTCPIP.CClientTCPIP.IfInit = false;
|
|
ConnectedServer = false;
|
|
}
|
|
if (gcount == 0)
|
|
{//20091107
|
|
SocketsTCPIP.CClientTCPIP.IfInit = false;
|
|
ConnectedServer = false;
|
|
Thread.Sleep(200);//20100710
|
|
continue;
|
|
}
|
|
|
|
}
|
|
catch (SocketException ex)
|
|
{
|
|
_tcpServerError = "CListenAGVState.BeginListen:" + ex.Message;
|
|
SocketsTCPIP.CClientTCPIP.IfInit = false;
|
|
ConnectedServer = false;
|
|
Thread.Sleep(200);//20100710
|
|
continue;
|
|
}
|
|
|
|
//处理接收到数据:根据gcount在_GetData中查找各个帧头,按帧拆分
|
|
//帧的每两个字节(一个字)代表一个含义
|
|
byte[] chatnew;
|
|
chatnew = new byte[gcount];
|
|
Array.Copy(_GetData,0, chatnew,0, gcount);
|
|
//将byte数组转换成UInt16数组
|
|
UInt16[] newData = ConvertByteToUInt16(chatnew);
|
|
CCarryConvert.WriteDarkCasket("ReceiveAGV", "SocketsTCPIP.CConnectTCPIP", "Receive", "1000", chatnew);
|
|
|
|
|
|
//处理收到的消息
|
|
DisposeReceivedMessage(newData);
|
|
chatnew = null;//20100127
|
|
|
|
}
|
|
catch (SocketException ex)
|
|
{
|
|
ConnectedServer = false;
|
|
_tcpServerError = "CListenAGVState.BeginListen:" + ex.Message;
|
|
}
|
|
Thread.Sleep(200);//20100710
|
|
}
|
|
}
|
|
|
|
#region 将BYTE数组转换为UInt16数组
|
|
/// <summary>
|
|
/// 将BYTE数组转换为UInt16数组
|
|
/// </summary>
|
|
/// <param name="srcData">需要处理的byte数组</param>
|
|
/// <returns>返回UInt16数组</returns>
|
|
private static UInt16[] ConvertByteToUInt16(byte[] srcData)
|
|
{
|
|
byte[] chat = null;
|
|
//判断srcData数组的维数是否为奇数,如果为奇数则舍弃最后一位
|
|
if (srcData.Length % 2 == 1)
|
|
{
|
|
chat = new byte[srcData.Length - 1];
|
|
Array.Copy(srcData,0, chat,0, srcData.Length - 1);
|
|
//Buffer.BlockCopy(srcData, 0, chat, 0, srcData.Length - 1);
|
|
}
|
|
else
|
|
{
|
|
chat = new byte[srcData.Length];
|
|
Array.Copy(srcData,0, chat,0, srcData.Length);
|
|
//Buffer.BlockCopy(srcData, 0, chat, 0, srcData.Length);
|
|
}
|
|
|
|
UInt16[] newData = new UInt16[chat.Length / 2];
|
|
|
|
int temp = 0;
|
|
for (int i = 0; i < newData.Length; i++)
|
|
{
|
|
newData[i] = (UInt16)((chat[temp+ 1] << 8) + chat[temp ]);//C#版:0是低位,1是高位;VC++版:1是低位,0是高位;
|
|
temp += 2;
|
|
}
|
|
|
|
return newData;
|
|
}
|
|
#endregion
|
|
|
|
#region 处理收到的消息
|
|
/// <summary>
|
|
/// 处理收到的消息
|
|
/// </summary>
|
|
/// <param name="message">消息数组</param>
|
|
private static void DisposeReceivedMessage(UInt16[] message)
|
|
{
|
|
StringBuilder AheadDetect = new StringBuilder();
|
|
ushort[] chatnew;
|
|
byte[] _Sdata = new byte[6];
|
|
try
|
|
{
|
|
for (int i = 0; i < message.Length; )
|
|
{
|
|
|
|
switch (message[i])
|
|
{
|
|
case 60080://监控下达任务的应答60080[T1][T2](对60003[T1][T2][K][P][S][C]的应答)
|
|
#region 60080AGV对监控下达任务的应答
|
|
|
|
if (message.Length >= 3)//
|
|
{
|
|
if (message.Length <= (i + 2)) break;
|
|
try
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("UPDATE T_Monitor_Task SET F_ErrorCode='', F_Status=2 WHERE F_MonitorIndex = ").Append(message[i + 2]).Append("");//20110505
|
|
SQLString(dbo, sql);
|
|
//20110608dbo.ExecuteSql(sql.ToString());
|
|
#region 多叉关联任务可以同步的一同报开始
|
|
if (CGeneralFunction.DoubleForkIfSync(message[i + 2], 1001, 6) == true)
|
|
{
|
|
string[] df = CGeneralFunction.GetDoubleForkMonitorInfo(message[i + 2], 1001);
|
|
if (df != null)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("UPDATE T_Monitor_Task SET F_ErrorCode='',F_Status=2 WHERE F_MonitorIndex = ").Append(Convert.ToInt32(df[0]));//20110505
|
|
SQLString(dbo, sql);
|
|
//20110608dbo.ExecuteSql( sql.ToString());
|
|
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
DataSourceChange();//20110405
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_tcpServerError = "CListenAGVState.DisposeReceivedMessage:任务进入消息队列," + ex.Message;
|
|
}
|
|
chatnew = new ushort[3];
|
|
Array.Copy(message, i, chatnew, 0, 3);
|
|
CCarryConvert.WriteDarkCasket("ReceiveAGV", "SocketsTCPIP.CConnectTCPIP", "Receive", "AGV任务进入消息队列", chatnew);
|
|
i += 3;
|
|
}
|
|
break;
|
|
|
|
#endregion
|
|
case 60081://允许AGV移载的应答:60081[T1][T2](对60005[T1][T2][N] [E] [O]的应答)
|
|
#region 60081允许AGV移载的应答
|
|
|
|
if (message.Length >= 3)
|
|
{
|
|
if (message.Length <= (i + 2)) break;
|
|
try
|
|
{
|
|
|
|
|
|
///////////////////////message[i + 2]对应F_AGVNextTask,求得F_MonitorIndex
|
|
object ob = dbo.GetSingle("select F_MonitorIndex from T_Monitor_Task where F_AGVNextTask=" + message[i + 2]);
|
|
if (ob != null)
|
|
{
|
|
int fid = message[i + 1];
|
|
int mankind = GetManageTaskKindIndexFromMonitor(Convert.ToInt32(ob));
|
|
///////////////////////
|
|
string[] df = CGeneralFunction.GetDoubleForkMonitorInfo(Convert.ToInt32(ob), 1001);
|
|
bool snyc = CGeneralFunction.DoubleForkIfSync(Convert.ToInt32(ob), 1001, 6);
|
|
ActionFinish(1001, Convert.ToInt32(ob), 0);
|
|
//20110608ActionComplete(1001, Convert.ToInt32(ob), 0);
|
|
//刷新监控中心显示
|
|
#region 多叉关联任务,能同步的同时报告完成;异步的直接执行关联的命令
|
|
//20100323
|
|
if (df != null)//20100702
|
|
{
|
|
//20100817 zhangxy 修改
|
|
fid = GetManageTaskIndexfromMonitor(Convert.ToInt32(df[0]));
|
|
mankind = GetManageTaskKindIndexFromMonitor(Convert.ToInt32(df[0]));
|
|
|
|
///////////////////////
|
|
if (snyc == true)//20100702
|
|
{
|
|
ActionFinish(1001, Convert.ToInt32(df[0]), 1);
|
|
//20110608ActionComplete(1001, Convert.ToInt32(df[0]), 1);//20100702
|
|
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
DataSourceChange();//20110405
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_tcpServerError = "CListenAGVState.DisposeReceivedMessage:允许AGV移载的应答," + ex.Message;
|
|
}
|
|
chatnew = new ushort[3];
|
|
Array.Copy(message, i, chatnew, 0, 3);
|
|
CCarryConvert.WriteDarkCasket("ReceiveAGV", "SocketsTCPIP.CConnectTCPIP", "Receive", "允许AGV移载的应答", chatnew);
|
|
i += 3;
|
|
}
|
|
break;
|
|
|
|
#endregion
|
|
case 60050://60050[T1][T2][A] ;AGV控制台开始分配AGV车号
|
|
#region AGV控制台开始分配AGV车号
|
|
if (message.Length >= 4)
|
|
{
|
|
if (message.Length <= (i + 3)) break;
|
|
try
|
|
{
|
|
int fid = message[i + 1];
|
|
int mankind = GetManageTaskKindIndexFromMonitor(message[i + 2]);
|
|
|
|
if (mankind == 1)
|
|
{//20100714
|
|
SQLString(dboM,new StringBuilder ( "update IO_CONTROL set CONTROL_STATUS=11 where CONTROL_ID=" + fid ));
|
|
//20110608dboM.ExecuteSql("update IO_CONTROL set CONTROL_STATUS=11 where CONTROL_ID=" + fid + "");
|
|
}
|
|
|
|
//20100817 zhangxy 修改
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Base_device set F_LockedState=").Append(message[i + 2]).Append(
|
|
" where F_DeviceIndex=").Append(message[i + 3]);
|
|
SQLString(dbo, sql);
|
|
//20110608dbo.ExceSQL(sql.ToString());
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("UPDATE T_Monitor_Task SET F_AgvNo=").Append(message[i + 3]).Append(" WHERE F_ManageTaskIndex=").Append(fid).Append(" and F_ManageTaskKindIndex=").Append(mankind).Append(" and F_DeviceIndex=1001 and (F_AgvNo is null) ");
|
|
SQLString(dbo, sql);
|
|
//20110608dbo.ExecuteSql(sql.ToString());
|
|
#region 多叉关联任务一起分配车号
|
|
string[] df = CGeneralFunction.GetDoubleForkMonitorInfo(message[i + 2], 1001);
|
|
if (df != null)
|
|
{
|
|
fid = GetManageTaskIndexfromMonitor(Convert.ToInt32(df[0]));
|
|
mankind = GetManageTaskKindIndexFromMonitor(Convert.ToInt32(df[0]));
|
|
if (mankind == 1)
|
|
{//20100714
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update IO_CONTROL set CONTROL_STATUS=11 where CONTROL_ID=" ).Append( fid);
|
|
SQLString(dboM, sql);
|
|
//20110608dboM.ExecuteSql( sql.ToString());
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("UPDATE T_Monitor_Task SET F_AgvNo=").Append(message[i + 3]).Append(" WHERE F_ManageTaskIndex=").Append(fid).Append(" and F_ManageTaskKindIndex=").Append(mankind).Append(" and F_DeviceIndex=1001");
|
|
SQLString(dbo, sql);
|
|
//20110608dbo.ExecuteSql(sql.ToString());
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
#region 给单一AGV任务配双叉任务
|
|
|
|
//if ((ir > 0) &&(GetDeviceOrderFromMonitor(message[i + 1])==1)&&(GetFCONTROLTASKTYPEFromManageTask(GetManageTaskKindIndexFromMonitor(message[i + 1]),GetManageTaskIndexfromMonitor(message[i + 1])))==1)//第一次分配车号并且是入库任务的取货指令
|
|
//{//查找一个后续位置的未发送的关联任务,可能会涉及到关联设备改道和重分配货叉
|
|
// int xCoor=CGeneralFunction.GetXCoorFromMonitor(message[i + 1], 1001, 1);
|
|
// int agvSquence = GetAgvSquence(xCoor);
|
|
// int useAwayfork = GetUseAwayFork(message[i + 1]);
|
|
// if (useAwayfork == 1)
|
|
// {
|
|
// useAwayfork = 0;
|
|
// }
|
|
// else
|
|
// {
|
|
// useAwayfork = 1;
|
|
// }
|
|
// DataView dv = dbo.ExceSQL(" SELECT TOP 1 T_Monitor_Task.F_ManageTaskIndex,T_Monitor_Task.F_ManageTASKKINDINDEX,T_Monitor_Task.F_MonitorIndex FROM T_Monitor_Task,T_Base_AGV_Gate,T_Manage_Task where T_Monitor_Task.F_NumParam2 = T_Base_AGV_Gate.F_AGVGateDeviceIndex and T_Monitor_Task.F_ManageTaskIndex = T_Manage_Task.FID AND T_Monitor_Task.F_ManageTASKKINDINDEX = T_Manage_Task.F_ManageTaskKindIndex and (T_Monitor_Task.F_Status = 0) AND (T_Base_AGV_Gate.F_Sequence >" + agvSquence + ") AND(T_Monitor_Task.F_DeviceIndex = 1001) AND (T_Monitor_Task.F_DeviceCommandIndex = 1) AND (T_Manage_Task.F_RELATIVECONTORLID = - 1) and (FCONTROLTASKTYPE=1) and (F_UseAwayFork ='" + useAwayfork + "') and (F_AgvNo is null) ORDER BY F_Sequence asc").Tables[0].DefaultView;
|
|
// if (dv.Count > 0)
|
|
// {//找到一个合适的多叉关联任务
|
|
// fid = GetManageTaskIndexfromMonitor(message[i + 1]);
|
|
// mankind = GetManageTaskKindIndexFromMonitor(message[i + 1]);
|
|
// int fidr =Convert.ToInt32( dv[0]["F_ManageTaskIndex"]);
|
|
// int mankindr = Convert.ToInt32(dv[0]["F_ManageTASKKINDINDEX"]);
|
|
// dbo.TransBegin();
|
|
// try
|
|
// {
|
|
// //修改多叉关联任务;分配AGV车号
|
|
// dbo.ExecuteSql("update T_Manage_Task set F_RELATIVECONTORLID=" + fidr + " where FID=" + fid + " and F_ManageTaskKindIndex="+mankind+"");
|
|
// dbo.ExecuteSql("update T_Manage_Task set F_RELATIVECONTORLID=" + fid + " where FID=" + fidr + " and F_ManageTaskKindIndex=" + mankindr + "");
|
|
// dbo.ExecuteSql("UPDATE T_Monitor_Task SET F_AgvNo=" + message[i + 2] + " WHERE F_ManageTaskIndex=" + fidr + " and F_ManageTaskKindIndex=" + mankindr + " and F_DeviceIndex=1001");
|
|
// dbo.TransCommit();
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _tcpServerError = "CListenAGVState.DisposeReceivedMessage:分配AGV车号," + ex.Message;
|
|
// dbo.TransRollback();
|
|
// }
|
|
|
|
// }
|
|
// dv = null;
|
|
//}
|
|
|
|
#endregion
|
|
}
|
|
#endregion
|
|
DataSourceChange();//20110405
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_tcpServerError = "CListenAGVState.DisposeReceivedMessage:AGV控制台开始分配AGV车号," + ex.Message;
|
|
}
|
|
chatnew = new ushort[4];
|
|
Array.Copy(message, i, chatnew, 0, 4);
|
|
CCarryConvert.WriteDarkCasket("ReceiveAGV", "SocketsTCPIP.CConnectTCPIP", "Receive", "AGV控制台开始分配AGV车号", chatnew);
|
|
i += 4;
|
|
}
|
|
break;
|
|
|
|
#endregion
|
|
case 60051://60051[T1][T2][N节点] [E货叉设备号] [O动作类型] [A车号] O为动作类型( 1-左取, 2-左送,3右取,4-右送)
|
|
//AGV到位(即到交接点):在入出库口输送机AGV到位后,AGV控制台询问监控系统地面是否准备好
|
|
#region AGV到位(即到交接点)在入出库口输送机AGV到位后,AGV控制台询问监控系统地面是否准备好
|
|
|
|
{
|
|
|
|
if (message.Length >= 7)//20110110
|
|
{
|
|
if (message.Length <= (i + 6)) break;//20110110
|
|
//AGV到位(即到交接点)的应答:60030[T1][T2](对60051[T1][T2][N] [E] [O] [A]的应答)
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_DeviceIndex,F_DeviceKindIndex, F_LocalIP, F_LocalPort, F_RemoteIP, F_RemotePort FROM T_Base_Device where F_DeviceIndex=1001");
|
|
DataView dvc = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dvc.Count > 0)
|
|
{
|
|
_Sdata = new byte[6];
|
|
_Sdata[0] = Convert.ToByte(60030 & 255);
|
|
_Sdata[1] = Convert.ToByte(60030 >> 8);
|
|
|
|
_Sdata[2] = Convert.ToByte(message[i + 1] & 255);
|
|
_Sdata[3] = Convert.ToByte(message[i + 1] >> 8);
|
|
_Sdata[4] = Convert.ToByte(message[i + 2] & 255);
|
|
_Sdata[5] = Convert.ToByte(message[i + 2] >> 8);
|
|
SocketsTCPIP.CClientTCPIP.Send(dvc[0]["F_RemoteIP"].ToString(), Convert.ToInt32(dvc[0]["F_RemotePort"]), _Sdata);
|
|
}
|
|
dvc = null;
|
|
try
|
|
{
|
|
int device = GetDeviceIndexFromAgvAddress(message[i + 3], message[i + 4]);//20110110
|
|
|
|
if (GetDeviceOrderFromMonitor(message[i + 2]) == -1)//AGV反馈的任务号不存在
|
|
{//地面移载故障60008[T1][T2][N][C]
|
|
|
|
}
|
|
else
|
|
{
|
|
if (GetDeviceKindIdx(device) == 2)
|
|
{
|
|
_Sdata = new byte[12];
|
|
DataView dv;
|
|
//任务状态:0,生成【顶升上升】;1,只生成【允许AGV取货移载】;2,只生成【允许AGV送货移载】;3,先生成【顶升下降】然后生成【允许AGV移载】
|
|
|
|
#region 入口输送机送货,检测空闲,无货,逻辑无物
|
|
if ((message[i + 5] == 2) || (message[i + 5] == 4))
|
|
{
|
|
|
|
#region 20110412【允许AGV送货移载】:输送机空闲、入口无货、逻辑无货
|
|
int ManFID = message[i + 1];
|
|
int Mankind = GetManageTaskKindIndexFromMonitor(message[i + 2]);
|
|
|
|
AheadDetect.Remove(0, AheadDetect.Length);
|
|
AheadDetect.Append("I").Append(Convert.ToString(device)).Append(";N").Append(Convert.ToString(device))
|
|
.Append(";D").Append(Convert.ToString(device)).Append(".0");
|
|
|
|
if (DeviceAndOrderExitInMonitor(Mankind, ManFID, 1001, 5, device) == false)
|
|
{
|
|
|
|
#region 允许AGV送货移载
|
|
int mindex = message[i + 2] - 1;
|
|
dv = dbo.ExceSQL(string.Format("SELECT F_NumParam2,F_RouteID,F_TxtParam,F_MonitorTaskLevel,F_UseAwayFork FROM T_Monitor_Task WHERE (F_MonitorIndex = {0})", message[i + 2])).Tables[0].DefaultView;
|
|
|
|
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_NumParam2, F_NumParam5,").Append(
|
|
" F_AheadDetect,F_TxtParam,F_AGVNextTask,F_UseAwayFork)").Append(
|
|
"VALUES (").Append(ManFID).Append(",").Append(Mankind).Append(",").Append(mindex).Append(",").Append(dv[0]["F_MonitorTaskLevel"]
|
|
).Append(",").Append(1001).Append(",5,").Append(dv[0]["F_RouteID"]).Append(",0,").Append(device).Append(",0").Append(
|
|
",'").Append(AheadDetect).Append("','").Append(dv[0]["F_TxtParam"]).Append("',").Append(message[i + 2]).Append(",'").Append(dv[0]["F_UseAwayFork"]).Append("')");
|
|
SQLString(dbo,sql);
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 检查关联站台
|
|
string[] df=CGeneralFunction.GetDoubleForkMonitorInfo(message[i + 2], 1001) ;
|
|
if ((message[i + 4] == 3) && (df != null))//多叉关联
|
|
{//检查关联站台
|
|
|
|
device = GetCorrDeviceIndex(device);
|
|
ManFID = GetManageTaskIndexfromMonitor(Convert.ToInt32(df[0]));
|
|
Mankind = GetManageTaskKindIndexFromMonitor(Convert.ToInt32(df[0]));
|
|
|
|
AheadDetect.Remove(0, AheadDetect.Length);
|
|
AheadDetect.Append("I").Append(Convert.ToString(device)).Append(";N").Append(Convert.ToString(device))
|
|
.Append(";D").Append(Convert.ToString(device)).Append(".0");
|
|
|
|
if (DeviceAndOrderExitInMonitor(Mankind, ManFID, 1001, 5, device) == false)
|
|
{
|
|
#region 允许AGV送货移载
|
|
int mindex = Convert.ToInt32(df[0]) - 1;
|
|
dv = dbo.ExceSQL(string.Format("SELECT F_NumParam2,F_RouteID,F_TxtParam,F_MonitorTaskLevel,F_UseAwayFork FROM T_Monitor_Task WHERE (F_MonitorIndex = {0})", Convert.ToInt32(df[0]))).Tables[0].DefaultView;
|
|
|
|
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_NumParam2, F_NumParam5,").Append(
|
|
" F_AheadDetect,F_TxtParam,F_AGVNextTask,F_UseAwayFork)").Append(
|
|
"VALUES (").Append(ManFID).Append(",").Append(Mankind).Append(",").Append(mindex).Append(",").Append(dv[0]["F_MonitorTaskLevel"]
|
|
).Append(",").Append(1001).Append(",5,").Append(dv[0]["F_RouteID"]).Append(",0,").Append(device).Append(",0").Append(
|
|
",'").Append(AheadDetect).Append("','").Append(dv[0]["F_TxtParam"]).Append("',").Append(Convert.ToInt32(df[0])).Append(",'").Append(dv[0]["F_UseAwayFork"]).Append("')");
|
|
SQLString(dbo,sql);
|
|
#endregion
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 出口输送机取货,检测空闲,有货,顶升低位
|
|
if ((message[i + 5] == 1) || (message[i + 5] == 3))
|
|
{
|
|
int ManFID = message[i + 1];
|
|
int Mankind = GetManageTaskKindIndexFromMonitor(message[i + 2]);
|
|
AheadDetect.Remove(0, AheadDetect.Length);
|
|
#region 20110412【允许AGV取货移载】:输送机空闲、顶升机空闲、顶升低位、出口有货
|
|
AheadDetect.Append("I").Append(Convert.ToString(device)).Append(
|
|
";I").Append(Convert.ToString(device - 2)).Append(
|
|
";D-").Append(device.ToString()).Append(".2").Append(
|
|
";D-").Append((device-2).ToString()).Append(".0");
|
|
|
|
if (DeviceAndOrderExitInMonitor(Mankind, ManFID, 1001, 5, device) == false)
|
|
{
|
|
#region 允许AGV取货移载
|
|
int mindex = message[i + 2] - 1;
|
|
dv = dbo.ExceSQL(string.Format("SELECT F_NumParam2,F_RouteID,F_TxtParam,F_MonitorTaskLevel,F_UseAwayFork FROM T_Monitor_Task WHERE (F_MonitorIndex = {0})", message[i + 2])).Tables[0].DefaultView;
|
|
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_NumParam2, F_NumParam5,").Append(
|
|
" F_AheadDetect,F_TxtParam,F_AGVNextTask,F_UseAwayFork)").Append(
|
|
"VALUES (").Append(ManFID).Append(",").Append(Mankind).Append(",").Append(mindex).Append(",").Append(dv[0]["F_MonitorTaskLevel"]
|
|
).Append(",").Append(1001).Append(",5,").Append(dv[0]["F_RouteID"]).Append(",0,").Append(device).Append(",0").Append(
|
|
",'").Append(AheadDetect).Append("','").Append(dv[0]["F_TxtParam"]).Append("',").Append(message[i + 2]).Append(",'").Append(dv[0]["F_UseAwayFork"]).Append("')");
|
|
SQLString(dbo, sql);
|
|
#endregion
|
|
}
|
|
#endregion
|
|
#region 检查关联站台
|
|
string[] df=CGeneralFunction.GetDoubleForkMonitorInfo(message[i + 2], 1001);
|
|
if ((message[i + 4] == 3) && ( df!= null))//多叉关联
|
|
{//检查关联站台
|
|
device = GetCorrDeviceIndex(device);
|
|
ManFID = GetManageTaskIndexfromMonitor(Convert.ToInt32(df[0]));
|
|
Mankind = GetManageTaskKindIndexFromMonitor(Convert.ToInt32(df[0]));
|
|
AheadDetect.Remove(0, AheadDetect.Length);
|
|
#region 20110412【允许AGV取货移载】:输送机空闲、顶升机空闲、顶升低位、出口有货
|
|
AheadDetect.Append("I").Append(Convert.ToString(device)).Append(
|
|
";I").Append(Convert.ToString(device - 2)).Append(
|
|
";D-").Append(device.ToString()).Append(".2").Append(
|
|
";D-").Append((device - 2).ToString()).Append(".0");
|
|
|
|
if (DeviceAndOrderExitInMonitor(Mankind, ManFID, 1001, 5, device) == false)
|
|
{
|
|
#region 允许AGV取货移载
|
|
int mindex = Convert.ToInt32(df[0]) - 1;
|
|
dv = dbo.ExceSQL(string.Format("SELECT F_NumParam2,F_RouteID,F_TxtParam,F_MonitorTaskLevel,F_UseAwayFork FROM T_Monitor_Task WHERE (F_MonitorIndex = {0})", message[i + 2])).Tables[0].DefaultView;
|
|
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_NumParam2, F_NumParam5,").Append(
|
|
" F_AheadDetect,F_TxtParam,F_AGVNextTask,F_UseAwayFork)").Append(
|
|
"VALUES (").Append(ManFID).Append(",").Append(Mankind).Append(",").Append(mindex).Append(",").Append(dv[0]["F_MonitorTaskLevel"]
|
|
).Append(",").Append(1001).Append(",5,").Append(dv[0]["F_RouteID"]).Append(",0,").Append(device).Append(",0").Append(
|
|
",'").Append(AheadDetect).Append("','").Append(dv[0]["F_TxtParam"]).Append("',").Append(Convert.ToInt32(df[0])).Append(",'").Append(dv[0]["F_UseAwayFork"]).Append("')");
|
|
SQLString(dbo,sql);
|
|
#endregion
|
|
}
|
|
#endregion
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
#endregion
|
|
dv = null;
|
|
}
|
|
else
|
|
{//地面移载故障60008[T1][T2][N][C]
|
|
|
|
}
|
|
}
|
|
chatnew = new ushort[7];//20110110
|
|
Array.Copy(message, i, chatnew, 0, 7);//20110110
|
|
CCarryConvert.WriteDarkCasket("ReceiveAGV", "SocketsTCPIP.CConnectTCPIP", "Receive", "在输送机:"+device.ToString()+",AGV询问是否可移载", chatnew);
|
|
DataSourceChange();//20110405
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_tcpServerError = "CListenAGVState.DisposeReceivedMessage:入库口输送机,AGV询问是否可移载," + ex.Message;
|
|
}
|
|
i += 7;//20110110
|
|
}
|
|
|
|
}
|
|
break;
|
|
|
|
#endregion
|
|
|
|
case 60052://60052[T1][T2][N节点] [E货叉设备号] [O动作类型] [A车号]
|
|
#region AGV移载开始
|
|
if (message.Length >= 7)//
|
|
{
|
|
if (message.Length <= (i + 6)) break;
|
|
//20110412AGV暂时不反馈
|
|
//try
|
|
//{
|
|
// int devicegate = GetDeviceIndexFromAgvAddress(message[i + 3], message[i + 4]);//20110110
|
|
// sql.Remove(0, sql.Length);
|
|
// sql.Append("update T_Base_device set F_LockedState=").Append(message[i + 2]).Append(
|
|
// " where F_DeviceIndex=").Append(devicegate);
|
|
// dbo.ExceSQL(sql.ToString());
|
|
// if ((message[i + 4] == 3) && (CGeneralFunction.GetDoubleForkMonitorInfo(message[i + 2], 1001) != null))//多叉关联
|
|
// {//检查关联站台
|
|
|
|
// int deviceCorr = GetCorrDeviceIndex(devicegate);
|
|
// sql.Remove(0, sql.Length);
|
|
// sql.Append("update T_Base_device set F_LockedState=").Append(message[i + 2]).Append(
|
|
// " where F_DeviceIndex=").Append(deviceCorr);
|
|
// dbo.ExceSQL(sql.ToString());
|
|
// }
|
|
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// _tcpServerError = "CListenAGVState.DisposeReceivedMessage:AGV移载开始," + ex.Message;
|
|
//}
|
|
chatnew = new ushort[7];
|
|
Array.Copy(message, i, chatnew, 0, 7);
|
|
CCarryConvert.WriteDarkCasket("ReceiveAGV", "SocketsTCPIP.CConnectTCPIP", "Receive", "AGV移载开始", chatnew);
|
|
i += 7;
|
|
|
|
}
|
|
break;
|
|
#endregion
|
|
|
|
case 60053://60053[T1][T2][N节点] [E货叉设备号] [O动作类型] [A车号] (动作类型: 1-左取, 2-左送,3右取,4-右送)
|
|
|
|
#region AGV移载结束
|
|
if (message.Length >= 7)//
|
|
{
|
|
if (message.Length <= (i + 6)) break;
|
|
//20110412AGV暂时不反馈
|
|
//try
|
|
//{
|
|
// sql.Remove(0, sql.Length);//20110110
|
|
// sql.Append("update T_Base_device set F_LockedState=0").Append(
|
|
// " where F_LockedState=").Append(message[i + 2]);
|
|
// dbo.ExceSQL(sql.ToString());
|
|
// #region 取货移栽完成,插入顶升机 顶升指令
|
|
// if ((message[i + 5] == 1) || (message[i + 5] == 3))//左取 右取
|
|
// {
|
|
// //任务状态:0,生成【顶升上升】;1,只生成【允许AGV取货移载】;2,只生成【允许AGV送货移载】;3,先生成【顶升下降】然后生成【允许AGV移载】
|
|
// int device = GetDeviceIndexFromAgvAddress(message[i + 3], message[i + 4]);
|
|
// int deviceCorr = 0;DataView dv;
|
|
// int LifterIndex1 = -1; int MonitorIndex1 = -1; int taskStatus1 = -1;
|
|
// #region 检查关联站台
|
|
|
|
// if ((message[i + 4] == 3) && (CGeneralFunction.GetDoubleForkMonitorInfo(message[i + 2], 1001) != null))//多叉关联
|
|
// {//检查关联站台
|
|
|
|
// deviceCorr = GetCorrDeviceIndex(device);
|
|
// LifterIndex1 = deviceCorr;
|
|
// MonitorIndex1 = Convert.ToInt32(CGeneralFunction.GetDoubleForkMonitorInfo(message[i + 2], 1001)[0]);
|
|
// taskStatus1 = 0;
|
|
// }
|
|
// #endregion
|
|
|
|
// //插入顶升机 顶升
|
|
// sql.Remove(0, sql.Length);
|
|
// sql.Append("select F_Pending_ID from T_Base_Pending_Lifter where F_MonitorIndex=").Append(message[i + 2]).Append(" or F_MonitorIndex1=").Append(message[i + 2]);
|
|
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
// if (dv.Count <= 0)
|
|
// {
|
|
// sql.Remove(0, sql.Length);
|
|
// sql.Append("INSERT INTO T_Base_Pending_Lifter( ")
|
|
// .Append(" F_LifterIndex, F_MonitorIndex, F_Status,")
|
|
// .Append(" F_LifterIndex1, F_MonitorIndex1, F_Status1)VALUES (")
|
|
// .Append(device).Append(",").Append(message[i + 2]).Append(",0,")
|
|
// .Append(LifterIndex1).Append(",").Append(MonitorIndex1).Append(",").Append(taskStatus1).Append(")");
|
|
// dbo.ExecuteSql(sql.ToString());
|
|
// }
|
|
// dv = null;
|
|
|
|
// }
|
|
// DataSourceChange();//20110405
|
|
// #endregion
|
|
|
|
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// _tcpServerError = "CListenAGVState.DisposeReceivedMessage:AGV移载结束," + ex.Message;
|
|
//}
|
|
chatnew = new ushort[7];
|
|
Array.Copy(message, i, chatnew, 0, 7);
|
|
CCarryConvert.WriteDarkCasket("ReceiveAGV", "SocketsTCPIP.CConnectTCPIP", "Receive", "AGV移载结束", chatnew);
|
|
i += 7;
|
|
|
|
}
|
|
break;
|
|
#endregion
|
|
case 60054://60054[T1][T2][N] [C故障码] [A]
|
|
#region AGV移载故障
|
|
if (message.Length >= 6)//
|
|
{
|
|
if (message.Length <= (i + 5)) break;
|
|
try
|
|
{
|
|
//有过记录的故障设备的任务号,不再重复处理
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_DeviceIndex FROM T_Base_Device where F_DeviceIndex=").Append(message[i + 5]).Append(" and F_ErrorTaskNo=").Append(message[i + 2]);
|
|
|
|
//20100108
|
|
DataTable dt = dbo.ExceSQL(sql.ToString()).Tables[0];
|
|
if (dt.Rows.Count >= 1)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Monitor_Task set F_Status= ").Append((message[i + 4]+30)).Append(" where (F_MonitorIndex= ").Append(message[i + 2]).Append(") and ((F_Status<> ").Append((message[i + 4]+30)).Append(") and (F_Status<> 3))");
|
|
SQLString(dbo, sql);
|
|
//20110608dbo.ExceSQL(sql.ToString());
|
|
DataSourceChange();//20110405
|
|
}
|
|
dt = null;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_tcpServerError = "CListenAGVState.DisposeReceivedMessage:AGV移载故障," + ex.Message;
|
|
}
|
|
chatnew = new ushort[6];
|
|
Array.Copy(message, i, chatnew, 0, 6);
|
|
CCarryConvert.WriteDarkCasket("ReceiveAGV", "SocketsTCPIP.CConnectTCPIP", "Receive", "AGV移载故障", chatnew);
|
|
i += 6;
|
|
|
|
}
|
|
break;
|
|
#endregion
|
|
case 60055://60055[T1][T2] AGV完成任务;调度需要发送应答帧,待定
|
|
#region AGV完成任务
|
|
|
|
if (message.Length >= 3)
|
|
{
|
|
if (message.Length <= (i + 2)) break;
|
|
try
|
|
{
|
|
int fid = message[i + 1];
|
|
int mankind = GetManageTaskKindIndexFromMonitor(message[i + 2]);
|
|
int fid1 = 0;
|
|
int mankind1 =0;
|
|
///////////////////////
|
|
string[] df = CGeneralFunction.GetDoubleForkMonitorInfo(message[i + 2], 1001);
|
|
bool snyc = CGeneralFunction.DoubleForkIfSync(message[i + 2], 1001, 6);
|
|
//根据DeviceIndex,得到Sockets通讯的初始设置
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_DeviceIndex,F_DeviceKindIndex, F_LocalIP, F_LocalPort, F_RemoteIP, F_RemotePort FROM T_Base_Device where F_DeviceIndex=1001");
|
|
DataView dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{//AGV任务完成的应答:60031[T1][T2](对60055[T1][T2]的应答)
|
|
_Sdata = new byte[6];
|
|
_Sdata[0] = Convert.ToByte(60031 & 255);
|
|
_Sdata[1] = Convert.ToByte(60031 >> 8);
|
|
|
|
_Sdata[2] = Convert.ToByte(message[i + 1] & 255);
|
|
_Sdata[3] = Convert.ToByte(message[i + 1] >> 8);
|
|
_Sdata[4] = Convert.ToByte(message[i + 2] & 255);
|
|
_Sdata[5] = Convert.ToByte(message[i + 2] >> 8);
|
|
if (SocketsTCPIP.CClientTCPIP.Send(dv[0]["F_RemoteIP"].ToString(), Convert.ToInt32(dv[0]["F_RemotePort"]), _Sdata) == true)
|
|
{
|
|
//20110412任务状态:0,生成【顶升上升】;1,只生成【允许AGV取货移载】;2,只生成【允许AGV送货移载】;3,先生成【顶升下降】然后生成【允许AGV移载】
|
|
int device = 0;
|
|
int devorder=GetDeviceOrderFromMonitor(message[i + 2]);
|
|
int MonitorIndex1 = -1;
|
|
dv = dbo.ExceSQL(string.Format("SELECT F_NumParam2,F_RouteID,F_TxtParam,F_MonitorTaskLevel FROM T_Monitor_Task WHERE (F_MonitorIndex = {0})", message[i + 2])).Tables[0].DefaultView ;
|
|
if (dv.Count >0)
|
|
{
|
|
device = Convert.ToInt32(dv[0]["F_NumParam2"]);
|
|
}
|
|
///////////////////////
|
|
ActionFinish(1001, message[i + 2], 0);
|
|
#region 顶升机顶升
|
|
AheadDetect.Clear();
|
|
AheadDetect.Append("I").Append(Convert.ToString(device - 2)).Append(";D").Append(Convert.ToString(device-2))
|
|
.Append(".0;I").Append(Convert.ToString(device));
|
|
|
|
if (DeviceAndOrderExitInMonitor(mankind, fid, (device), 9, 0) == false)
|
|
{
|
|
int mindex = message[i + 2] - 1;
|
|
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)").Append(
|
|
"VALUES (").Append(fid).Append(",").Append(mankind).Append(",").Append(mindex).Append(",").Append(dv[0]["F_MonitorTaskLevel"]
|
|
).Append(",").Append((device)).Append(",9,").Append(dv[0]["F_RouteID"]).Append(",0,").Append((device)).Append(",0").Append(
|
|
",'").Append(AheadDetect).Append("','").Append(dv[0]["F_TxtParam"]).Append("')");
|
|
SQLString(dbo, sql);
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 多叉关联任务,能同步的同时报告完成;异步的直接执行关联的命令
|
|
//20100323
|
|
if (df != null)//20100702
|
|
{
|
|
//20100817 zhangxy 修改
|
|
fid1 = GetManageTaskIndexfromMonitor(Convert.ToInt32(df[0]));
|
|
mankind1 = GetManageTaskKindIndexFromMonitor(Convert.ToInt32(df[0]));
|
|
|
|
///////////////////////
|
|
if (snyc == true)//20100702
|
|
{
|
|
|
|
#region 20110412检查关联站台
|
|
dv = dbo.ExceSQL(string.Format("SELECT F_NumParam2,F_RouteID,F_TxtParam,F_MonitorTaskLevel FROM T_Monitor_Task WHERE (F_MonitorIndex = {0})", Convert.ToInt32(df[0]))).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
device = Convert.ToInt32(dv[0]["F_NumParam2"]);
|
|
}
|
|
MonitorIndex1 = Convert.ToInt32(df[0])-1;
|
|
|
|
#endregion
|
|
ActionFinish(1001, Convert.ToInt32(df[0]), 1);
|
|
#region 顶升机顶升
|
|
AheadDetect.Clear();
|
|
AheadDetect.Append("I").Append(Convert.ToString(device - 2)).Append(";D").Append(Convert.ToString(device - 2))
|
|
.Append(".0;I").Append(Convert.ToString(device));
|
|
|
|
if (DeviceAndOrderExitInMonitor(mankind1, fid1, device, 9, 0) == false)
|
|
{
|
|
|
|
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)").Append(
|
|
"VALUES (").Append(fid).Append(",").Append(mankind).Append(",").Append(MonitorIndex1).Append(",").Append(dv[0]["F_MonitorTaskLevel"]
|
|
).Append(",").Append((device)).Append(",9,").Append(dv[0]["F_RouteID"]).Append(",0,").Append((device)).Append(",0").Append(
|
|
",'").Append(AheadDetect).Append("','").Append(dv[0]["F_TxtParam"]).Append("')");
|
|
SQLString(dbo, sql);
|
|
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
_tcpServerError = "向AGV反馈任务:" + message[i + 1] + "的应答时,发送失败!";
|
|
}
|
|
DataSourceChange();//20110405
|
|
|
|
}
|
|
|
|
|
|
chatnew = new ushort[3];
|
|
Array.Copy(message, i, chatnew, 0, 3);
|
|
CCarryConvert.WriteDarkCasket("ReceiveAGV", "SocketsTCPIP.CConnectTCPIP", "Receive", "AGV完成任务", chatnew);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_tcpServerError = "CListenAGVState.DisposeReceivedMessage:AGV完成任务," + ex.Message;
|
|
}
|
|
|
|
i += 3;
|
|
}
|
|
break;
|
|
|
|
#endregion
|
|
case 60056://60056[T1][T2]
|
|
#region AGV控制台任务删除申请
|
|
if (message.Length >= 3)//
|
|
{
|
|
if (message.Length <= (i + 2)) break;
|
|
|
|
try
|
|
{
|
|
int fid = 0;
|
|
int mankind = 0;
|
|
int tasktype = 0;
|
|
|
|
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT * FROM T_Monitor_Task where F_MonitorIndex = ").Append(message[i + 2]);
|
|
DataView dvMonintor = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dvMonintor.Count > 0)
|
|
{
|
|
fid = message[i + 1];
|
|
mankind = GetManageTaskKindIndexFromMonitor(message[i + 2]);
|
|
tasktype = GetFCONTROLTASKTYPEFromManageTask(mankind, fid);
|
|
if ((tasktype != 1) && ((tasktype != 4)))
|
|
{
|
|
|
|
i += 3;
|
|
break;
|
|
}
|
|
|
|
}
|
|
//根据DeviceIndex,得到Sockets通讯的初始设置
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_DeviceIndex,F_DeviceKindIndex, F_LocalIP, F_LocalPort, F_RemoteIP, F_RemotePort FROM T_Base_Device where F_DeviceIndex=1001");
|
|
DataView dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
_Sdata = new byte[6];
|
|
_Sdata[0] = Convert.ToByte(60009 & 255);
|
|
_Sdata[1] = Convert.ToByte(60009 >> 8);
|
|
|
|
_Sdata[2] = Convert.ToByte(message[i + 1] & 255);
|
|
_Sdata[3] = Convert.ToByte(message[i + 1] >> 8);
|
|
_Sdata[4] = Convert.ToByte(message[i + 2] & 255);
|
|
_Sdata[5] = Convert.ToByte(message[i + 2] >> 8);
|
|
SocketsTCPIP.CClientTCPIP.Send(dv[0]["F_RemoteIP"].ToString(), Convert.ToInt32(dv[0]["F_RemotePort"]), _Sdata);
|
|
|
|
|
|
}
|
|
dv = null;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_tcpServerError = "CListenAGVState.DisposeReceivedMessage:AGV控制台任务删除申请," + ex.Message;
|
|
}
|
|
chatnew = new ushort[3];
|
|
Array.Copy(message, i, chatnew, 0, 3);
|
|
CCarryConvert.WriteDarkCasket("ReceiveAGV", "SocketsTCPIP.CConnectTCPIP", "Receive", "AGV控制台任务删除申请", chatnew);
|
|
i += 3;
|
|
|
|
}
|
|
break;
|
|
#endregion
|
|
case 60057://60057[T1][T2][A] A为允许状态(0-不允许,1-允许)
|
|
#region 对监控调度申请删除任务的回复
|
|
if (message.Length >= 4)//
|
|
{
|
|
if (message.Length <= (i + 3)) break;
|
|
try
|
|
{
|
|
if (message[i + 3] == 0)//0-不允许
|
|
{
|
|
i += 4;
|
|
break;
|
|
}
|
|
int fid = 0;
|
|
int mankind = 0;
|
|
int tasktype = 0;
|
|
|
|
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT * FROM T_Monitor_Task where F_MonitorIndex = ").Append(message[i + 2]);
|
|
DataView dvMonintor = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dvMonintor.Count > 0)
|
|
{
|
|
fid = message[i + 1];
|
|
mankind = GetManageTaskKindIndexFromMonitor(message[i + 2]);
|
|
tasktype = GetFCONTROLTASKTYPEFromManageTask(mankind, fid);
|
|
if ((tasktype != 1) && ((tasktype != 4)))
|
|
{
|
|
i += 4;
|
|
break;
|
|
}
|
|
DataView dv;
|
|
|
|
AAA:
|
|
string[] df = CGeneralFunction.GetDoubleForkMonitorInfo(message[i + 2], 1001);
|
|
SQLString(dbo, new StringBuilder("update T_Manage_Task set FExceptionNO=" + Model.CGeneralFunction.TASKDELETE + " where (F_ManageTaskKindIndex = " + mankind + ") AND (FID = " + fid + ")"));
|
|
//20110608dbo.ExceSQL("update T_Manage_Task set FExceptionNO=" + Model.CGeneralFunction.TASKDELETE + " where (F_ManageTaskKindIndex = " + mankind + ") AND (FID = " + fid + ")");
|
|
SQLString(dbo, new StringBuilder("update T_Monitor_Task set F_STATUS=-1 where F_ManageTaskKindIndex=" + mankind + " and F_ManageTaskIndex=" + fid + " and F_STATUS=0"));
|
|
//20110608dbo.ExceSQL("update T_Monitor_Task set F_STATUS=-1 where F_ManageTaskKindIndex=" + mankind + " and F_ManageTaskIndex=" + fid + " and F_STATUS=0");
|
|
dv = dbo.ExceSQL("SELECT F_ManageTaskKindIndex, F_ManageTaskIndex,F_DeviceIndex,F_MonitorIndex,F_Status,F_DeviceCommandIndex " +
|
|
",F_NumParam2,F_NumParam5,F_TxtParam FROM T_Monitor_Task Where F_ManageTaskIndex=" + fid + " and F_ManageTaskKindIndex= " +
|
|
mankind).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
//20100108
|
|
CCarryConvert.WriteDarkCasket("ReceiveAGV", "SocketsTCPIP.CConnectTCPIP", "Receive AGV撤销任务", "托盘条码:" + dvMonintor[0]["F_TxtParam"], "调度任务索引:" + fid.ToString());
|
|
for (int j = 0; j < dv.Count; j++)
|
|
{
|
|
ActionFinish(Convert.ToInt32(dv[j]["F_DeviceIndex"]), Convert.ToInt32(dv[j]["F_MonitorIndex"]), Model.CGeneralFunction.TASKDELETE);
|
|
//20110608ActionComplete(Convert.ToInt32(dv[j]["F_DeviceIndex"]), Convert.ToInt32(dv[j]["F_MonitorIndex"]), Model.CGeneralFunction.TASKDELETE);
|
|
}
|
|
}
|
|
dv = null;
|
|
|
|
if (df != null)
|
|
{
|
|
fid = GetManageTaskIndexfromMonitor(Convert.ToInt32(df[0]));
|
|
mankind = GetManageTaskKindIndexFromMonitor(Convert.ToInt32(df[0]));
|
|
goto AAA;
|
|
|
|
}
|
|
DataSourceChange();//20110405
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_tcpServerError = "CListenAGVState.DisposeReceivedMessage:AGV对监控调度申请删除任务的回复," + ex.Message;
|
|
}
|
|
chatnew = new ushort[4];
|
|
Array.Copy(message, i, chatnew, 0, 4);
|
|
CCarryConvert.WriteDarkCasket("ReceiveAGV", "SocketsTCPIP.CConnectTCPIP", "Receive", "AGV对监控调度申请删除任务的回复", chatnew);
|
|
i += 4;
|
|
|
|
}
|
|
break;
|
|
#endregion
|
|
case 60058://60058[N][A]
|
|
#region AGV申请进入特殊节点
|
|
if (message.Length >= 3)//
|
|
{
|
|
if (message.Length <= (i + 2)) break;
|
|
try
|
|
{
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_tcpServerError = "CListenAGVState.DisposeReceivedMessage:AGV申请进入特殊节点," + ex.Message;
|
|
}
|
|
chatnew = new ushort[3];
|
|
Array.Copy(message, i, chatnew, 0, 3);
|
|
CCarryConvert.WriteDarkCasket("ReceiveAGV", "SocketsTCPIP.CConnectTCPIP", "Receive", "AGV申请进入特殊节点", chatnew);
|
|
i += 3;
|
|
|
|
}
|
|
break;
|
|
#endregion
|
|
case 60059://60059[A][S][X][Y][G] A为车号;S为状态(0-正常,1-故障);X为X坐标;Y为Y坐标;G为角度
|
|
|
|
#region AGV报告位置状态
|
|
if (message.Length >= 6)//
|
|
{
|
|
if (message.Length <= (i + 5)) break;
|
|
|
|
try
|
|
{
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_tcpServerError = "CListenAGVState.DisposeReceivedMessage:AGV报告位置状态," + ex.Message;
|
|
}
|
|
chatnew = new ushort[6];
|
|
Array.Copy(message, i, chatnew, 0, 6);
|
|
CCarryConvert.WriteDarkCasket("ReceiveAGV", "SocketsTCPIP.CConnectTCPIP", "Receive", "AGV报告位置状态", chatnew);
|
|
i += 6;
|
|
|
|
|
|
}
|
|
break;
|
|
#endregion
|
|
case 60060://60060[T1][T2][A][C]
|
|
#region AGV故障报告
|
|
if (message.Length >= 5)//
|
|
{
|
|
if (message.Length <= (i + 4)) break;
|
|
try
|
|
{
|
|
//有过记录的故障设备的任务号,不再重复处理
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_DeviceIndex FROM T_Base_Device where F_DeviceIndex=").Append(message[i + 3]).Append(" and F_ErrorTaskNo=").Append(message[i + 2]);
|
|
|
|
//20100108
|
|
DataTable dt = dbo.ExceSQL(sql.ToString()).Tables[0];
|
|
if (dt.Rows.Count >= 1)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Monitor_Task set F_Status= ").Append((message[i + 4]+30)).Append(" where (F_MonitorIndex= ").Append(message[i + 2]).Append(") and ((F_Status<> ").Append((message[i + 4]+30)).Append(") and (F_Status<> 3))");
|
|
SQLString(dbo, sql);
|
|
//20110608dbo.ExceSQL(sql.ToString());
|
|
DataSourceChange();//20110405
|
|
}
|
|
dt = null;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_tcpServerError = "CListenAGVState.DisposeReceivedMessage:AGV故障报告," + ex.Message;
|
|
}
|
|
chatnew = new ushort[5];
|
|
Array.Copy(message, i, chatnew, 0, 5);
|
|
CCarryConvert.WriteDarkCasket("ReceiveAGV", "SocketsTCPIP.CConnectTCPIP", "Receive", "AGV故障报告", chatnew);
|
|
i += 5;
|
|
|
|
}
|
|
break;
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_tcpServerError = "CConnectTCPIP.DisposeReceiveMessage:" + ex.Message;
|
|
|
|
}
|
|
finally
|
|
{//20100127
|
|
chatnew = null;
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
public static int GetAgvSquence(int agvGate)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_Sequence FROM T_Base_AGV_Gate WHERE (F_AGVGateDeviceIndex = ").Append(agvGate).Append(")");
|
|
object ob = dbo.GetSingle(sql.ToString());
|
|
if (ob != null)
|
|
{
|
|
return Convert.ToInt32(ob);
|
|
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
public static int GetUseAwayFork(int taskno)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_UseAwayFork FROM T_Monitor_Task WHERE (F_MonitorIndex = ").Append(taskno).Append(")");
|
|
string obj = dbo.GetSingle(sql.ToString()).ToString();
|
|
if (obj == "-")
|
|
{
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return Convert.ToInt32(obj);
|
|
}
|
|
}
|
|
public static int GetFCONTROLTASKTYPEFromManageTask(int taskKindIndex, int Managefid)
|
|
{
|
|
DataView dv;
|
|
try
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FCONTROLTASKTYPE FROM T_Manage_Task WHERE (FID = " ).Append( Managefid ).Append( ") AND (F_ManageTaskKindIndex = " ).Append( taskKindIndex ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
if (dv[0]["FCONTROLTASKTYPE"] == DBNull.Value) return -1;
|
|
return Convert.ToInt32(dv[0]["FCONTROLTASKTYPE"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 连接远程主机和绑定本地主机端口
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static bool ConnectTcpIPServer()
|
|
{
|
|
string remoteIP; int remotePort; string localIP; int localPort;
|
|
//20100127
|
|
DataView dv;
|
|
IPAddress ipAddress ;
|
|
IPEndPoint EPlocal;
|
|
try
|
|
{
|
|
//根据DeviceIndex,得到Sockets通讯的初始设置
|
|
//20100127
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_DeviceIndex,F_DeviceKindIndex, F_LocalIP, F_LocalPort, F_RemoteIP, F_RemotePort FROM T_Base_Device where F_DeviceIndex=1001 and F_DeviceKindIndex=6");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
|
|
if (dv.Count == 0)
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
remoteIP = (dv[0]["F_RemoteIP"]).ToString();
|
|
localIP = (dv[0]["F_LocalIP"]).ToString();
|
|
remotePort = Convert.ToInt32(dv[0]["F_RemotePort"]);
|
|
localPort = Convert.ToInt32(dv[0]["F_LocalPort"]);
|
|
}
|
|
//20100127
|
|
ipAddress = IPAddress.Parse(localIP);
|
|
//20100127
|
|
EPlocal = new IPEndPoint(ipAddress, localPort);
|
|
|
|
|
|
// Create a TCP/IP socket.
|
|
if (Localsocket == null)
|
|
{
|
|
Localsocket = new Socket(AddressFamily.InterNetwork,
|
|
SocketType.Stream, ProtocolType.Tcp);
|
|
Localsocket.Bind((EndPoint)EPlocal);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SocketsTCPIP.CClientTCPIP.IfInit == false)
|
|
{
|
|
if (SocketsTCPIP.CClientTCPIP.InitClientTCPIP(remoteIP, remotePort) == false)
|
|
{
|
|
_tcpServerError = SocketsTCPIP.CClientTCPIP.TcpError;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
ConnectedServer = true;
|
|
|
|
return ConnectedServer;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_tcpServerError = "CConnectTCPIP.ConnectTcpIPServer:" + ex.Message;
|
|
return false;
|
|
}
|
|
finally
|
|
{//20100127
|
|
dv = null;
|
|
ipAddress =null ;
|
|
EPlocal = null;
|
|
remoteIP = null;
|
|
localIP = null;
|
|
}
|
|
}
|
|
public static void EndListen()
|
|
{//20091107
|
|
exitThread=true ;
|
|
if (SocketsTCPIP.CClientTCPIP.ClientSocket != null)
|
|
{
|
|
SocketsTCPIP.CClientTCPIP.ClientSocket.Close();
|
|
}
|
|
if (mythread != null)
|
|
{
|
|
mythread.Abort();
|
|
|
|
mythread = null;
|
|
}
|
|
}
|
|
|
|
public static void StartListen()
|
|
{
|
|
exitThread = false ;
|
|
if (mythread == null)
|
|
{
|
|
mythread = new Thread(new ThreadStart(BeginListen));
|
|
mythread.IsBackground = true;
|
|
}
|
|
if (mythread.ThreadState != ThreadState.Running)
|
|
{
|
|
mythread.Start();
|
|
}
|
|
}
|
|
public static void ActionComplete(int DeviceIdx, int TaskIdx, int ClearZero)
|
|
{
|
|
int devKind = GetDeviceKindIdx(DeviceIdx);
|
|
int order = GetDeviceOrderFromMonitor(TaskIdx);
|
|
int fid = GetManageTaskIndexfromMonitor(TaskIdx);
|
|
int mti = GetManageTaskKindIndexFromMonitor(TaskIdx);
|
|
//20100710
|
|
#region 取得AGV放货点输送机的编号(AGV通道内的停车点设备)
|
|
|
|
int AgvNextConveyor = 0;
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_NumParam5 FROM T_Monitor_Task WHERE (F_MonitorIndex = ").Append(TaskIdx).Append(") ");
|
|
object ob = dbo.GetSingle(sql.ToString());
|
|
if (ob != null)
|
|
{
|
|
if (GetDeviceKindIdx(Convert.ToInt32(ob)) == 2)
|
|
{
|
|
AgvNextConveyor = Convert.ToInt32(ob);
|
|
}
|
|
}//20100710
|
|
|
|
#endregion
|
|
|
|
|
|
string cap;
|
|
int errrcode = GetExceptionNOFromManageTask(fid, mti);
|
|
DataView dv;//20100127
|
|
//dbo.TransBegin();
|
|
try
|
|
{
|
|
//20100127
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select count(F_MonitorIndex) as counts from T_Monitor_Task " ).Append(
|
|
" where F_ManageTaskIndex =" ).Append( fid ).Append( " and F_ManageTaskKindIndex= " ).Append( mti);
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
if (Convert.ToInt32(dv[0]["counts"]) == 1)
|
|
{
|
|
//固定路径模式
|
|
//调度任务的fid的最后一个监控分解任务完成
|
|
|
|
if (mti == 1)
|
|
{
|
|
cap = "调度任务";
|
|
//完成FSTATUS=999;970堆垛机送货重故障异常完成;980堆垛机取空故障异常完成;990条码扫描异常完成;调度撤销删除调度任务900
|
|
if (errrcode > 900)//异常完成
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update IO_Control set Control_STATUS=" ).Append( errrcode ).Append( " where Control_ID=" ).Append( fid);
|
|
dboM.ExceSQL(sql.ToString());
|
|
}
|
|
else
|
|
{
|
|
if (ClearZero == Model.CGeneralFunction.TASKDELETE)//调度撤销删除调度任务900
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update IO_Control set Control_STATUS=" ).Append( Model.CGeneralFunction.TASKDELETE ).Append( " where Control_ID=" ).Append( fid);
|
|
dboM.ExceSQL(sql.ToString());
|
|
}
|
|
else//完成FSTATUS=999
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update IO_Control set Control_STATUS=" ).Append( Model.CGeneralFunction.TASKFINISH ).Append( " where Control_ID=" ).Append( fid);
|
|
dboM.ExceSQL(sql.ToString());
|
|
}
|
|
}
|
|
}
|
|
else if (mti == 4)
|
|
{
|
|
cap = "手工任务";
|
|
}
|
|
else
|
|
{
|
|
cap = "临时任务";
|
|
}
|
|
//回写管理表
|
|
if (ClearZero == Model.CGeneralFunction.TASKDELETE)//调度撤销删除调度任务900
|
|
{
|
|
ReturnManageInfo(fid, mti, cap, false);
|
|
}
|
|
else
|
|
{
|
|
ReturnManageInfo(fid, mti, cap, true);
|
|
}
|
|
}
|
|
|
|
}
|
|
#region AGV向输送机放货增加逻辑有物20110110
|
|
if ((AgvNextConveyor > 0) && (order == 3) && (ClearZero != Model.CGeneralFunction.TASKDELETE))
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Base_Device set F_HaveGoods=1 where F_DeviceIndex=" ).Append( AgvNextConveyor ).Append( " ");
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
#endregion
|
|
|
|
//被这个任务号锁定的设备全部解锁
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Base_Device set F_LockedState=0 where F_LockedState=" ).Append( TaskIdx);
|
|
dbo.ExceSQL(sql.ToString());
|
|
|
|
|
|
if (ClearZero == 1)
|
|
{
|
|
|
|
if (mti == 1)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("UPDATE IO_CONTROL SET ERROR_TEXT ='' WHERE Control_ID=" ).Append( fid ).Append( " and Control_STATUS<900");
|
|
dboM.ExceSQL(sql.ToString());
|
|
}
|
|
}
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("delete from T_Monitor_Task where F_MonitorIndex=" ).Append( TaskIdx);
|
|
dbo.ExceSQL(sql.ToString());
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_tcpServerError = "CListenAGVState.ActionComplete:" + ex.Message;
|
|
}
|
|
finally
|
|
{//20100127
|
|
dv = null;
|
|
}
|
|
}
|
|
static void ReturnManageInfo(int fid, int mti, string cap, bool IFOK)
|
|
{
|
|
//20100127
|
|
DataView dv;
|
|
try
|
|
{
|
|
//200906240111增加货位记录:入库1-结束位置有货;出库2-起始位置无货;倒库3-起始位置无货,结束位置有货
|
|
//20100127
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FID, F_ManageTaskKindIndex,FCONTROLTASKTYPE, FSTARTDEVICE,FSTARTCELL, FENDDEVICE,FENDCELL 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)
|
|
{
|
|
switch (dv[0]["FCONTROLTASKTYPE"].ToString())
|
|
{
|
|
case "1":
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("UPDATE ST_CELL SET FCELLSTATUS = 1 WHERE (FLaneWay=" ).Append( dv[0]["FENDDEVICE"] ).Append( " and FCELLCODE = '" ).Append( dv[0]["FENDCELL"] ).Append( "')");
|
|
dbo.ExceSQL(sql.ToString());
|
|
break;
|
|
case "2":
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("UPDATE ST_CELL SET FCELLSTATUS =0 WHERE (FLaneWay=" ).Append( dv[0]["FSTARTDEVICE"] ).Append( " and FCELLCODE = '" ).Append( dv[0]["FSTARTCELL"] ).Append( "')");
|
|
dbo.ExceSQL(sql.ToString());
|
|
break;
|
|
case "3":
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("UPDATE ST_CELL SET FCELLSTATUS = 1 WHERE (FLaneWay=" ).Append( dv[0]["FENDDEVICE"] ).Append( " and FCELLCODE = '" ).Append( dv[0]["FENDCELL"] ).Append( "')");
|
|
dbo.ExceSQL(sql.ToString());
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("UPDATE ST_CELL SET FCELLSTATUS =0 WHERE (FLaneWay=" ).Append( dv[0]["FSTARTDEVICE"] ).Append( " and FCELLCODE = '" ).Append( dv[0]["FSTARTCELL"] ).Append( "')");
|
|
dbo.ExceSQL(sql.ToString());
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
}
|
|
//20101028
|
|
string dtime = DateTime.Now.ToString("u");//20101028
|
|
dtime = dtime.Substring(0, dtime.Length - 1);//20101028
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Manage_Task set FSTATUS=999,FENDTIME='" ).Append( dtime ).Append( "' where FID=" ).Append( fid ).Append( " and F_ManageTaskKindIndex= " ).Append( mti);
|
|
dbo.ExceSQL(sql.ToString());
|
|
//20101028
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("INSERT INTO T_Manage_Task_BAK SELECT * FROM T_Manage_Task where FID=" ).Append( fid ).Append( " and F_ManageTaskKindIndex<>1");
|
|
dbo.ExecuteSql(sql.ToString());
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("delete from T_Manage_Task where FID=" ).Append( fid ).Append( " and F_ManageTaskKindIndex= " ).Append( mti);
|
|
dbo.ExceSQL(sql.ToString());
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{//20100127
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100127
|
|
dv = null;
|
|
}
|
|
|
|
}
|
|
public static int GetDeviceKindIdx(int devIdx)
|
|
{
|
|
try
|
|
{
|
|
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_DeviceIndex, F_DeviceKindIndex FROM T_Base_Device WHERE F_DeviceIndex=" + devIdx);
|
|
|
|
DataSet ds = dbo.ExceSQL(sql.ToString());
|
|
DataView dv = ds.Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_DeviceKindIndex"]);
|
|
}
|
|
else
|
|
return 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
public static int GetManageTaskIndexfromMonitor(int monitorIdx)
|
|
{
|
|
//20100127
|
|
DataView dv;
|
|
try
|
|
{//20100127
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_ManageTaskIndex FROM T_Monitor_Task WHERE (F_MonitorIndex = " ).Append( monitorIdx ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_ManageTaskIndex"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100127
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100127
|
|
dv = null;
|
|
}
|
|
}
|
|
public static int GetManageTaskKindIndexFromMonitor(int monitorIdx)
|
|
{
|
|
//20100127
|
|
DataView dv;
|
|
try
|
|
{//20100127
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_ManageTaskKindIndex FROM T_Monitor_Task WHERE (F_MonitorIndex = " ).Append( monitorIdx ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_ManageTaskKindIndex"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100127
|
|
dv = null;
|
|
}
|
|
}
|
|
public static int GetDeviceOrderFromMonitor(int MonitorIndex)
|
|
{
|
|
//20100127
|
|
DataView dv;
|
|
try
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select F_DeviceCommandIndex from T_Monitor_Task where (F_DeviceCommandIndex IS NOT NULL) and F_MonitorIndex=" ).Append( MonitorIndex);
|
|
|
|
//20100127
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_DeviceCommandIndex"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100127
|
|
dv = null;
|
|
}
|
|
}
|
|
public static int GetExceptionNOFromManageTask(int FID, int ManTaskKind)
|
|
{
|
|
//20100127
|
|
DataTable dt;
|
|
try
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FID, F_ManageTaskKindIndex, FExceptionNO FROM T_Manage_Task WHERE (FID = " ).Append( FID ).Append( ") AND (F_ManageTaskKindIndex = " ).Append( ManTaskKind ).Append( ") ");
|
|
;
|
|
//20100127
|
|
dt = dbo.ExceSQL(sql.ToString()).Tables[0];
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
if (dt.Rows[0]["FExceptionNO"] == DBNull.Value)
|
|
{
|
|
return -1;
|
|
}
|
|
else
|
|
{
|
|
|
|
return Convert.ToInt32(dt.Rows[0]["FExceptionNO"]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100127
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100127
|
|
dt = null;
|
|
}
|
|
|
|
}
|
|
static int GetDeviceIndexFromAgvActive(int AgvActive)
|
|
{
|
|
//20100127AGV
|
|
DataView dva;
|
|
try
|
|
{
|
|
//20100127
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_AGVGateDeviceIndex, F_Address FROM T_Base_AGV_Gate WHERE (F_Active = " ).Append( AgvActive ).Append( ") ");
|
|
dva = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dva.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dva[0]["F_AGVGateDeviceIndex"]);
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
catch (Exception ex)
|
|
{//20100127
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100127
|
|
dva = null;
|
|
}
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="AgvAddress"></param>
|
|
/// <param name="ForkIndex">1,前叉;2后叉;3双叉</param>
|
|
/// <returns></returns>
|
|
static int GetDeviceIndexFromAgvAddress(int AgvAddress,int ForkIndex)
|
|
{
|
|
//20110110AGV
|
|
DataView dva;
|
|
try
|
|
{
|
|
string F_UseAwayFork = string.Empty;
|
|
if (ForkIndex == 1)//前叉,远叉
|
|
{
|
|
F_UseAwayFork=" and F_UseAwayFork = '1' ";
|
|
}
|
|
else if (ForkIndex == 2)
|
|
{
|
|
F_UseAwayFork = " and F_UseAwayFork = '0' ";
|
|
}
|
|
else//3
|
|
{
|
|
F_UseAwayFork = " and F_UseAwayFork <> '-' ";
|
|
}
|
|
//20100127
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_AGVGateDeviceIndex, F_Address FROM T_Base_AGV_Gate WHERE (F_Address = " ).Append( AgvAddress ).Append( ") ").Append(F_UseAwayFork);
|
|
dva = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dva.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dva[0]["F_AGVGateDeviceIndex"]);
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100127
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100127
|
|
dva = null;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 是否逻辑有物
|
|
/// </summary>
|
|
/// <param name="deviceindex"></param>
|
|
/// <returns></returns>
|
|
static bool IfHaveLogicGoods(int deviceindex)
|
|
{
|
|
DataView dv = dbo.ExceSQL("SELECT F_HaveGoods FROM T_Base_Device where F_HaveGoods=1 and F_DeviceIndex=" + deviceindex).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
static int GetCorrDeviceIndex(int device)
|
|
{//20110412
|
|
int deviceCorr=0;
|
|
if ((device % 2) == 1)
|
|
{
|
|
deviceCorr = device - 1;
|
|
}
|
|
else
|
|
{
|
|
deviceCorr = device + 1;
|
|
}
|
|
return deviceCorr;
|
|
}
|
|
static string GetDeviceS7Connection(int deviceindex)
|
|
{
|
|
DataView dv = dbo.ExceSQL("SELECT F_S7Connection FROM T_Base_Device WHERE (F_DeviceIndex = "+deviceindex+")").Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return dv[0]["F_S7Connection"].ToString();
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 20110405数据视图更新
|
|
/// </summary>
|
|
static void DataSourceChange()
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select * from V_Monitor_Task where ").Append(CStaticClass.Monstatus).Append(" order by 设备指令索引 asc ");
|
|
DataView dvmon = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select * from V_Manage_Task where ").Append(CStaticClass.Manstatus);
|
|
DataView dvman = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
CDataChangeEventArgs e = new CDataChangeEventArgs(dvman, dvmon);
|
|
OnDataChange(e);
|
|
}
|
|
/// <summary>
|
|
/// 20110608执行SQL语句数组
|
|
/// </summary>
|
|
/// <param name="sqlList"></param>
|
|
static void SQLString(DBOperator dbo,StringBuilder sql)
|
|
{
|
|
|
|
CUpdateDBChangeEventArgs e = new CUpdateDBChangeEventArgs(dbo,sql);
|
|
OnUpdateDB(e);
|
|
}
|
|
/// <summary>
|
|
/// 20110608报告完成
|
|
/// </summary>
|
|
/// <param name="device"></param>
|
|
/// <param name="task"></param>
|
|
/// <param name="taskstate"></param>
|
|
static void ActionFinish(int device, int task, int taskstate)
|
|
{
|
|
CUpdateDBChangeEventArgs e = new CUpdateDBChangeEventArgs(device,task,taskstate);
|
|
OnUpdateDB(e);
|
|
}
|
|
/// <summary>
|
|
/// 判断调度表T_Monitor_Task是否存在调度任务的设备和命令
|
|
/// </summary>
|
|
/// <param name="Mankind">调度任务类型</param>
|
|
/// <param name="ManFID">调度任务索引</param>
|
|
/// <param name="DeviceIndex">设备所引</param>
|
|
/// <param name="Order">设备命令</param>
|
|
/// <returns></returns>
|
|
public static bool DeviceAndOrderExitInMonitor(int Mankind, int ManFID, int DeviceIndex, int Order, int ArrowAddress)
|
|
{
|
|
DataView dv;
|
|
try
|
|
{
|
|
if (Order == -1) return true;
|
|
sql.Remove(0, sql.Length);
|
|
switch (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)
|
|
{
|
|
_tcpServerError = "CListenAGVState.DeviceAndOrderExitInMonitor:" + ex.Message;
|
|
return false;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|