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.
3142 lines
151 KiB
3142 lines
151 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using DBFactory;
|
|
using CommonLib;
|
|
using System.Data;
|
|
namespace SocketsTCPIP
|
|
{
|
|
using System;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
using System.Threading;
|
|
using System.Text;
|
|
using CommonClassLib;
|
|
|
|
|
|
|
|
public static class CClientTCPIP
|
|
{//20130111
|
|
private static Object thisLock = new Object();
|
|
|
|
public static event CDataSourceChangeEventHandler DataChange;
|
|
public static event CUpdateDBEventHandler UpdateDB;
|
|
public static event CWriteDarkCasketEventHandler WriteDarkCasket;
|
|
public static event CSendDeviceOrderEventHandler SendDeviceOrder;
|
|
public static void OnSendDeviceOrder(CSendDeviceOrderEventArgs e)
|
|
{
|
|
if (SendDeviceOrder != null)
|
|
{
|
|
SendDeviceOrder(null, e);
|
|
}
|
|
}
|
|
public static void OnWriteDarkCasket(CWriteDarkCasketEventArgs e)
|
|
{
|
|
if (WriteDarkCasket != null)
|
|
{
|
|
WriteDarkCasket(null, e);
|
|
}
|
|
}
|
|
public static void OnDataChange(CDataChangeEventArgs e)
|
|
{
|
|
if (DataChange != null)
|
|
{
|
|
DataChange(null, e);
|
|
}
|
|
}
|
|
public static void OnUpdateDB(CUpdateDBChangeEventArgs e)
|
|
{
|
|
if (UpdateDB != null)
|
|
{
|
|
UpdateDB(null, e);
|
|
}
|
|
}
|
|
public static event RefreshMonitorEventHandler RefreshMonitor;
|
|
public static void OnRefreshMonitor(RefreshMonitorEventArgs e)
|
|
{
|
|
if (RefreshMonitor != null)
|
|
{
|
|
RefreshMonitor(e);
|
|
}
|
|
}
|
|
public static DBOperator dbo =new DBOperator();//20130926
|
|
static DBOperator dboM =CommonClassLib.AppSettings.dboM;//20130926
|
|
static StringBuilder sql = new StringBuilder();
|
|
private static Dictionary<string, int> _initCount = new Dictionary<string, int>();
|
|
public static Dictionary<string, int> TcpIPInitCount
|
|
{
|
|
get { return CClientTCPIP._initCount; }
|
|
set
|
|
{
|
|
DataView dv = dbo.ExceSQL("SELECT F_RemoteIP,F_RemotePort FROM T_Base_Device WHERE (F_DeviceKindIndex = 6 and F_RemoteIP is not null)").Tables[0].DefaultView;
|
|
for (int i = 0; i < dv.Count; i++)
|
|
{
|
|
|
|
if (value.ContainsKey(dv[i][0].ToString()) == false)
|
|
{
|
|
value.Add(dv[i][0].ToString(), 0);
|
|
}
|
|
|
|
}
|
|
CClientTCPIP._initCount = value;
|
|
|
|
}
|
|
}
|
|
static Dictionary<string, bool> _ifInit = new Dictionary<string, bool>();
|
|
public static Dictionary<string, bool> IfInit
|
|
{
|
|
get { return CClientTCPIP._ifInit; }
|
|
set
|
|
{
|
|
DataView dv = dbo.ExceSQL("SELECT F_RemoteIP,F_RemotePort FROM T_Base_Device WHERE (F_DeviceKindIndex = 6 and F_RemoteIP is not null)").Tables[0].DefaultView;
|
|
for (int i = 0; i < dv.Count; i++)
|
|
{
|
|
if (_ifConnect.ContainsKey(dv[i][0].ToString()) == false)
|
|
{
|
|
_ifConnect.Add(dv[i][0].ToString(), false);
|
|
}
|
|
if (value.ContainsKey(dv[i][0].ToString()) == false)
|
|
{
|
|
value.Add(dv[i][0].ToString(), false);
|
|
}
|
|
if (value[dv[i][0].ToString()] == false)
|
|
{
|
|
_ifConnect[dv[i][0].ToString()] = false;
|
|
|
|
}
|
|
}
|
|
CClientTCPIP._ifInit = value;
|
|
}
|
|
}
|
|
|
|
static Dictionary<string, bool> _ifConnect = new Dictionary<string, bool>();
|
|
static string _remoteIP;
|
|
static int _remotePort;
|
|
static Socket clientSocket = null;
|
|
static EndPoint epServer;
|
|
static byte[] _byteData = new byte[6];
|
|
static string _tcpError;
|
|
static Dictionary<string, Socket> clientSockets = new Dictionary<string, Socket>();
|
|
public static string TcpError
|
|
{
|
|
get { return _tcpError; }
|
|
set
|
|
{
|
|
_tcpError = value;
|
|
RefreshMonitorEventArgs rea = new RefreshMonitorEventArgs("tsStatus", string.Format("SocketsTCPIP:{0}", _tcpError));
|
|
OnRefreshMonitor(rea);
|
|
}
|
|
}
|
|
public static byte[] ByteData
|
|
{
|
|
get { return _byteData; }
|
|
set { _byteData = value; }
|
|
}
|
|
|
|
public static Socket ClientSocket
|
|
{
|
|
get { return CClientTCPIP.clientSocket; }
|
|
set { CClientTCPIP.clientSocket = value; }
|
|
}
|
|
|
|
public static bool InitClientTCPIP(string remoteIP, int remotePort)
|
|
{
|
|
|
|
if (_ifConnect.ContainsKey(remoteIP) == false)
|
|
{
|
|
_ifConnect.Add(remoteIP, false);
|
|
}
|
|
if (_initCount.ContainsKey(remoteIP) == false)
|
|
{
|
|
_initCount.Add(remoteIP, 0);
|
|
}
|
|
if (_ifInit.ContainsKey(remoteIP) == false)
|
|
{
|
|
_ifInit.Add(remoteIP, false);
|
|
}
|
|
|
|
if (_initCount[remoteIP] > 3)
|
|
{
|
|
TcpError = "SocketsTCPIP,连接远程主机:" + remoteIP + "时,发生三次连接失败错误!请检查远程主机是否正常运行!重新打开命令开关。";
|
|
_ifInit[remoteIP] = false;
|
|
return false;
|
|
}
|
|
if (_ifConnect[remoteIP] == true) return false;
|
|
clientSocket = null;
|
|
|
|
IPAddress ipAddress;
|
|
IPEndPoint remoteEP;
|
|
|
|
try
|
|
{
|
|
_remoteIP = remoteIP;
|
|
_remotePort = remotePort;
|
|
ipAddress = IPAddress.Parse(_remoteIP);
|
|
remoteEP = new IPEndPoint(ipAddress, _remotePort);
|
|
epServer = (EndPoint)remoteEP;
|
|
// Create a TCP/IP socket.
|
|
if (clientSocket == null)
|
|
{
|
|
clientSocket = new Socket(AddressFamily.InterNetwork,
|
|
SocketType.Stream, ProtocolType.Tcp);
|
|
|
|
}
|
|
|
|
// Connect to the remote endpoint.
|
|
StateObject so = new StateObject();
|
|
so.workSocket = clientSocket;
|
|
so.remoteIP = remoteIP;
|
|
clientSocket.BeginConnect(epServer,
|
|
new AsyncCallback(ConnectCallback), so);
|
|
_ifInit[remoteIP] = false;
|
|
_ifConnect[remoteIP] = true;
|
|
if (clientSockets.ContainsKey(remoteIP) == false)
|
|
{
|
|
clientSockets.Add(remoteIP, clientSocket);
|
|
}
|
|
return _ifInit[remoteIP];
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
if (_initCount[remoteIP] > 3)
|
|
{
|
|
TcpError = "SocketsTCPIP:连接远程主机:" + remoteIP + "时,发生三次连接失败错误!请检查远程主机是否正常运行!重新打开命令开关。";
|
|
clientSocket = null;
|
|
//_initCount = 0;
|
|
|
|
return false;
|
|
}
|
|
_initCount[remoteIP]++;
|
|
_ifInit[remoteIP] = false;
|
|
|
|
TcpError = "SocketsTCPIP.CClientTCPIP.InitClientTCPIP:" + e.StackTrace + e.Message;
|
|
return false;
|
|
}
|
|
finally
|
|
{//20100127
|
|
ipAddress = null;
|
|
remoteEP = null;
|
|
//sb = null;
|
|
}
|
|
}
|
|
|
|
private static void ConnectCallback(IAsyncResult ar)
|
|
{
|
|
|
|
try
|
|
{
|
|
lock (thisLock)
|
|
{
|
|
StateObject so = (StateObject)ar.AsyncState;
|
|
Socket s = so.workSocket;
|
|
|
|
try
|
|
{
|
|
s.EndConnect(ar);
|
|
clientSockets[so.remoteIP] = s;
|
|
_ifInit[so.remoteIP] = true;
|
|
_initCount[so.remoteIP] = 0;
|
|
//开始下一次异步接收
|
|
s.BeginReceive(so.buffer, 0, StateObject.BUFFER_SIZE, 0, new AsyncCallback(ReceiveCallback), so);
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
TcpError = "SocketsTCPIP.CClientTCPIP.ConnectCallback:" + e.Message;
|
|
_initCount[so.remoteIP]++;
|
|
_ifInit[so.remoteIP] = false;
|
|
|
|
}
|
|
finally
|
|
{
|
|
_ifConnect[so.remoteIP] = false;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TcpError = "SocketsTCPIP.CClientTCPIP.ConnectCallback:" + ex.Message;
|
|
}
|
|
}
|
|
|
|
private static void ReceiveCallback(IAsyncResult ar)
|
|
{
|
|
try
|
|
{
|
|
lock (thisLock)
|
|
{
|
|
StateObject so = (StateObject)ar.AsyncState;
|
|
Socket s = so.workSocket;
|
|
|
|
int agvdev = 0;
|
|
try
|
|
{
|
|
|
|
int read = s.EndReceive(ar);
|
|
if (read > 0)
|
|
{
|
|
agvdev = GetAGVServer(so.remoteIP);
|
|
byte[] chatnew = new byte[read];
|
|
Array.Copy(so.buffer, 0, chatnew, 0, read);
|
|
CWriteDarkCasketEventArgs e = new CWriteDarkCasketEventArgs("SocketsTCPIP.CClientTCPIP", "ReceiveCallback", agvdev.ToString(), "接收AGV数据", chatnew);
|
|
OnWriteDarkCasket(e);
|
|
//将byte数组转换成UInt16数组
|
|
int[] newData = ConvertByteToInt32(chatnew);
|
|
DisposeReceivedMessage(agvdev, newData);//触发事件通知主线程
|
|
//开始下一次异步接收
|
|
s.BeginReceive(so.buffer, 0, StateObject.BUFFER_SIZE, 0, new AsyncCallback(ReceiveCallback), so);
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_ifInit[so.remoteIP] = false;
|
|
TcpError = "SocketsTCPIP.CClientTCPIP.ReceiveCallback:" + e.StackTrace + e.Message;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TcpError = "SocketsTCPIP.CClientTCPIP.ReceiveCallback:" + ex.StackTrace + ex.Message;
|
|
}
|
|
|
|
}
|
|
|
|
public static bool Send(string remoteIP, int remotePort, byte[] data)
|
|
{
|
|
lock (thisLock)//20130607
|
|
{
|
|
try
|
|
{
|
|
if (_ifInit.ContainsKey(remoteIP) == false)
|
|
{
|
|
_ifInit.Add(remoteIP, false);
|
|
}
|
|
if (_ifInit[remoteIP] == false)
|
|
{
|
|
if (InitClientTCPIP(remoteIP, remotePort) == false)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
//20100127
|
|
int agvdev = GetAGVServer(remoteIP);
|
|
int sendcount = clientSockets[remoteIP].Send(data);
|
|
//clientSocket.BeginSend(byteData, 0, byteData.Length, 0,
|
|
// new AsyncCallback(SendCallback), clientSocket);
|
|
CWriteDarkCasketEventArgs e = new CWriteDarkCasketEventArgs("SocketsTCPIP.CClientTCPIP", "Send", agvdev.ToString(), "发送AGV", data);//20100127
|
|
OnWriteDarkCasket(e);
|
|
return true;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_ifInit[remoteIP] = false;
|
|
TcpError = "SocketsTCPIP.CClientTCPIP.Send:" + e.StackTrace + e.Message;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void SendCallback(IAsyncResult ar)
|
|
{
|
|
try
|
|
{
|
|
Socket client;//20100127
|
|
client = (Socket)ar.AsyncState;
|
|
if (client.Connected == false) return;
|
|
IPEndPoint ipep = (IPEndPoint)client.RemoteEndPoint;
|
|
try
|
|
{
|
|
|
|
client.EndSend(ar);
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_ifInit[ipep.Address.ToString()] = false;
|
|
TcpError = "SocketsTCPIP.CClientTCPIP.SendCallback:" + e.StackTrace + e.Message;
|
|
|
|
|
|
}
|
|
finally
|
|
{//20100127
|
|
client = null;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TcpError = "SocketsTCPIP.CClientTCPIP.SendCallback:" + ex.StackTrace + ex.Message;
|
|
}
|
|
}
|
|
public static void EndConnect()
|
|
{
|
|
//DataView dv = dbo.ExceSQL("SELECT F_RemoteIP FROM T_Base_Device WHERE (F_DeviceKindIndex = 6)").Tables[0].DefaultView;
|
|
//if (dv.Count > 0)
|
|
//{
|
|
// if (_ifInit == false)
|
|
// {
|
|
// return;
|
|
|
|
// }
|
|
// byte[] sb = new byte[2] { 62, 0 };
|
|
// if (clientSocket.Connected == true)
|
|
// {
|
|
// clientSocket.Send(sb);
|
|
// }
|
|
// sb = null;//20100127
|
|
//}
|
|
}
|
|
|
|
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)
|
|
{
|
|
TcpError = "SocketsTCPIP:GetDeviceKindIdx," + ex.StackTrace + ex.Message;
|
|
return 0;
|
|
//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;
|
|
TcpError = "SocketsTCPIP:GetDeviceKindIdx," + ex.StackTrace + ex.Message;
|
|
return -1;
|
|
}
|
|
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)
|
|
{
|
|
TcpError = "SocketsTCPIP:GetDeviceKindIdx," + ex.StackTrace + ex.Message;
|
|
return -1;
|
|
//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)
|
|
{
|
|
TcpError = "SocketsTCPIP:GetDeviceKindIdx," + ex.StackTrace + ex.Message;
|
|
return -1;
|
|
//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;
|
|
TcpError = "SocketsTCPIP:GetDeviceKindIdx," + ex.StackTrace + ex.Message;
|
|
return -1;
|
|
}
|
|
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;
|
|
TcpError = "SocketsTCPIP:GetDeviceKindIdx," + ex.StackTrace + ex.Message;
|
|
return -1;
|
|
}
|
|
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;
|
|
TcpError = "SocketsTCPIP:GetDeviceKindIdx," + ex.StackTrace + ex.Message;
|
|
return -1;
|
|
}
|
|
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(null, null);
|
|
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)
|
|
{
|
|
TcpError = "DeviceAndOrderExitInMonitor:" + ex.StackTrace + ex.Message;
|
|
return false;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
|
|
}
|
|
}
|
|
|
|
#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);
|
|
|
|
}
|
|
else
|
|
{
|
|
chat = new byte[srcData.Length];
|
|
Array.Copy(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
|
|
|
|
private static int[] ConvertByteToInt32(byte[] srcData)
|
|
{
|
|
byte[] chat = null;
|
|
if (srcData.Length % 4 != 0)
|
|
{
|
|
int arrlen = srcData.Length - (srcData.Length % 4);
|
|
chat = new byte[arrlen];
|
|
Array.Copy(srcData, 0, chat, 0, arrlen);
|
|
|
|
}
|
|
else
|
|
{
|
|
chat = new byte[srcData.Length];
|
|
Array.Copy(srcData, 0, chat, 0, srcData.Length);
|
|
|
|
}
|
|
|
|
int[] newData = new int[chat.Length / 4];
|
|
|
|
int temp = 0;
|
|
for (int i = 0; i < newData.Length; i++)
|
|
{
|
|
newData[i] = (int)((chat[temp + 3] << 24) + (chat[temp + 2] << 16) + (chat[temp + 1] << 8) + chat[temp]);//C#版:0是低位,1是高位;VC++版:1是低位,0是高位;
|
|
temp += 4;
|
|
}
|
|
|
|
return newData;
|
|
}
|
|
|
|
#region 处理收到的消息
|
|
/// <summary>
|
|
/// 处理收到的消息
|
|
/// </summary>
|
|
/// <param name="message">消息数组</param>
|
|
private static void DisposeReceivedMessage(int agvdev, int[] message)
|
|
{
|
|
StringBuilder AheadDetect = new StringBuilder();
|
|
int[] chatnew; DataView dva = new DataView();
|
|
DataView dv = new DataView();
|
|
byte[] _Sdata = new byte[16]; string rIP = string.Empty; int rport = 0;
|
|
int ck = 0;
|
|
try
|
|
{
|
|
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=").Append(agvdev);
|
|
dva = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dva.Count > 0)
|
|
{
|
|
rIP = dva[0]["F_RemoteIP"].ToString();
|
|
rport = Convert.ToInt32(dva[0]["F_RemotePort"]);
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
for (int i = 0; i < message.Length; )
|
|
{
|
|
|
|
switch (message[i])
|
|
{
|
|
|
|
case 60003://监控下达任务的应答60003[T1][T2][CK](对60003[T1][T2][T][P][K][A] [F][C]的应答)
|
|
#region 60003AGV对监控下达任务的应答
|
|
|
|
if (message.Length >= 4)
|
|
{
|
|
if (message.Length <= (i + 3)) { i += 4; break; }
|
|
ck = message[i] + message[i + 1] + message[i + 2];
|
|
if (ck != message[i + 3]) { i += 4; 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);
|
|
#region 多叉关联任务可以同步的一同报开始
|
|
if (CGeneralFunction.DoubleForkIfSync(message[i + 2], agvdev, 6) == true)
|
|
{
|
|
string[] df = CGeneralFunction.GetDoubleForkMonitorInfo(message[i + 2], agvdev);
|
|
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);
|
|
}
|
|
}
|
|
#endregion
|
|
DataSourceChange();//20110405
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TcpError = "DisposeReceivedMessage:AGV对监控下达任务的应答," + ex.StackTrace + ex.Message;
|
|
}
|
|
chatnew = new int[4];
|
|
Array.Copy(message, i, chatnew, 0, 4);
|
|
CWriteDarkCasketEventArgs e = new CWriteDarkCasketEventArgs("SocketsTCPIP.CConnectTCPIP", "Receive", agvdev.ToString(), "AGV对监控下达任务的应答", chatnew);
|
|
OnWriteDarkCasket(e);
|
|
i += 4;
|
|
}
|
|
break;
|
|
|
|
#endregion
|
|
|
|
case 60004://60004[T1][T2][A][CK] ;AGV控制台开始分配AGV车号
|
|
#region AGV控制台开始分配AGV车号
|
|
if (message.Length >= 5)
|
|
{
|
|
if (message.Length <= (i + 4)) { i += 5; break; }
|
|
ck = message[i] + message[i + 1] + message[i + 2] + message[i + 3];
|
|
if (ck != message[i + 4]) { i += 5; break; }
|
|
try
|
|
{
|
|
_Sdata = new byte[16];
|
|
_Sdata[0] = Convert.ToByte(message[i] & 255);
|
|
_Sdata[1] = Convert.ToByte((message[i] >> 8) & 255);
|
|
_Sdata[2] = Convert.ToByte((message[i] >> 16) & 255);
|
|
_Sdata[3] = Convert.ToByte((message[i] >> 24) & 255);
|
|
_Sdata[4] = Convert.ToByte(message[i + 1] & 255);
|
|
_Sdata[5] = Convert.ToByte((message[i + 1] >> 8) & 255);
|
|
_Sdata[6] = Convert.ToByte((message[i + 1] >> 16) & 255);
|
|
_Sdata[7] = Convert.ToByte((message[i + 1] >> 24) & 255);
|
|
_Sdata[8] = Convert.ToByte(message[i + 2] & 255);
|
|
_Sdata[9] = Convert.ToByte((message[i + 2] >> 8) & 255);
|
|
_Sdata[10] = Convert.ToByte((message[i + 2] >> 16) & 255);
|
|
_Sdata[11] = Convert.ToByte((message[i + 2] >> 24) & 255);
|
|
ck = message[i] + message[i + 1] + message[i + 2];
|
|
_Sdata[12] = Convert.ToByte(ck & 255);
|
|
_Sdata[13] = Convert.ToByte((ck >> 8) & 255);
|
|
_Sdata[14] = Convert.ToByte((ck >> 16) & 255);
|
|
_Sdata[15] = Convert.ToByte((ck >> 24) & 255);
|
|
CSendDeviceOrderEventArgs sd = new CSendDeviceOrderEventArgs(agvdev, rIP, rport, _Sdata);
|
|
OnSendDeviceOrder(sd);
|
|
int fid = message[i + 1];
|
|
int mankind = GetManageTaskKindIndexFromMonitor(message[i + 2]);
|
|
|
|
if (mankind == 1)
|
|
{
|
|
SQLString(dboM, new StringBuilder("update IO_CONTROL set CONTROL_STATUS=11 where CONTROL_ID=" + fid));
|
|
}
|
|
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);
|
|
|
|
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=").Append(agvdev).Append(" and (F_AgvNo is null) ");
|
|
SQLString(dbo, sql);
|
|
#region 多叉关联任务一起分配车号
|
|
string[] df = CGeneralFunction.GetDoubleForkMonitorInfo(message[i + 2], agvdev);
|
|
if (df != null)
|
|
{
|
|
fid = GetManageTaskIndexfromMonitor(Convert.ToInt32(df[0]));
|
|
mankind = GetManageTaskKindIndexFromMonitor(Convert.ToInt32(df[0]));
|
|
if (mankind == 1)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update IO_CONTROL set CONTROL_STATUS=11 where CONTROL_ID=").Append(fid);
|
|
SQLString(dboM, sql);
|
|
|
|
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=").Append(agvdev);
|
|
SQLString(dbo, sql);
|
|
|
|
}
|
|
|
|
}
|
|
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], agvdev, 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 = agvdev) 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=agvdev");
|
|
// dbo.TransCommit();
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _tcpServerError = "DisposeReceivedMessage:分配AGV车号," + ex.Message;
|
|
// dbo.TransRollback();
|
|
// }
|
|
|
|
// }
|
|
// dv = null;
|
|
//}
|
|
|
|
#endregion
|
|
}
|
|
#endregion
|
|
DataSourceChange();
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TcpError = "DisposeReceivedMessage:AGV控制台开始分配AGV车号," + ex.StackTrace + ex.Message;
|
|
}
|
|
chatnew = new int[5];
|
|
Array.Copy(message, i, chatnew, 0, 5);
|
|
CWriteDarkCasketEventArgs e = new CWriteDarkCasketEventArgs("SocketsTCPIP.CConnectTCPIP", "Receive", agvdev.ToString(), "AGV控制台开始分配AGV车号", chatnew);
|
|
OnWriteDarkCasket(e);
|
|
|
|
i += 5;
|
|
}
|
|
break;
|
|
|
|
#endregion
|
|
|
|
case 60005://60005[T1][T2][A][CK] AGV完成任务;
|
|
#region AGV完成任务
|
|
|
|
if (message.Length >= 5)
|
|
{
|
|
if (message.Length <= (i + 4)) { i += 5; break; }
|
|
ck = message[i] + message[i + 1] + message[i + 2] + message[i + 3];
|
|
if (ck != message[i + 4]) { i += 5; 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], agvdev);
|
|
bool snyc = CGeneralFunction.DoubleForkIfSync(message[i + 2], agvdev, 6);
|
|
//AGV任务完成的应答:60005[T1][T2][CK]
|
|
_Sdata = new byte[16];
|
|
_Sdata[0] = Convert.ToByte(message[i] & 255);
|
|
_Sdata[1] = Convert.ToByte((message[i] >> 8) & 255);
|
|
_Sdata[2] = Convert.ToByte((message[i] >> 16) & 255);
|
|
_Sdata[3] = Convert.ToByte((message[i] >> 24) & 255);
|
|
_Sdata[4] = Convert.ToByte(message[i + 1] & 255);
|
|
_Sdata[5] = Convert.ToByte((message[i + 1] >> 8) & 255);
|
|
_Sdata[6] = Convert.ToByte((message[i + 1] >> 16) & 255);
|
|
_Sdata[7] = Convert.ToByte((message[i + 1] >> 24) & 255);
|
|
_Sdata[8] = Convert.ToByte(message[i + 2] & 255);
|
|
_Sdata[9] = Convert.ToByte((message[i + 2] >> 8) & 255);
|
|
_Sdata[10] = Convert.ToByte((message[i + 2] >> 16) & 255);
|
|
_Sdata[11] = Convert.ToByte((message[i + 2] >> 24) & 255);
|
|
ck = message[i] + message[i + 1] + message[i + 2];
|
|
_Sdata[12] = Convert.ToByte(ck & 255);
|
|
_Sdata[13] = Convert.ToByte((ck >> 8) & 255);
|
|
_Sdata[14] = Convert.ToByte((ck >> 16) & 255);
|
|
_Sdata[15] = Convert.ToByte((ck >> 24) & 255);
|
|
CSendDeviceOrderEventArgs sd = new CSendDeviceOrderEventArgs(agvdev, rIP, rport, _Sdata);
|
|
OnSendDeviceOrder(sd);
|
|
|
|
//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(agvdev, 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(agvdev, 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
|
|
|
|
DataSourceChange();//20110405
|
|
|
|
chatnew = new int[5];
|
|
Array.Copy(message, i, chatnew, 0, 5);
|
|
CWriteDarkCasketEventArgs e = new CWriteDarkCasketEventArgs("SocketsTCPIP.CConnectTCPIP", "Receive", agvdev.ToString(), "AGV完成任务", chatnew);
|
|
OnWriteDarkCasket(e);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TcpError = "DisposeReceivedMessage:AGV完成任务," + ex.StackTrace + ex.Message;
|
|
}
|
|
|
|
i += 5;
|
|
}
|
|
break;
|
|
|
|
#endregion
|
|
|
|
case 60006://60006[T1][T2][A][CK] A为允许状态(0-不允许,1-允许)
|
|
#region Agv控制台对监控调度申请删除任务的回复
|
|
if (message.Length >= 5)//
|
|
{
|
|
if (message.Length <= (i + 4)) { i += 5; break; }
|
|
ck = message[i] + message[i + 1] + message[i + 2] + message[i + 3];
|
|
if (ck != message[i + 4]) { i += 5;break; }
|
|
chatnew = new int[5];
|
|
Array.Copy(message, i, chatnew, 0, 5);
|
|
CWriteDarkCasketEventArgs e1 = new CWriteDarkCasketEventArgs("SocketsTCPIP.CConnectTCPIP", "Receive", agvdev.ToString(), "AGV对监控调度申请删除任务的回复:" + message[i + 3].ToString(), chatnew);
|
|
OnWriteDarkCasket(e1);
|
|
try
|
|
{
|
|
if (message[i + 3] == 0)//0-不允许
|
|
{
|
|
i += 5;
|
|
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 += 5;
|
|
break;
|
|
}
|
|
|
|
|
|
AAA:
|
|
string[] df = CGeneralFunction.GetDoubleForkMonitorInfo(message[i + 2], agvdev);
|
|
SQLString(dbo, new StringBuilder("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"));
|
|
|
|
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)
|
|
{
|
|
|
|
chatnew = new int[5];
|
|
Array.Copy(message, i, chatnew, 0, 5);
|
|
CWriteDarkCasketEventArgs e = new CWriteDarkCasketEventArgs("SocketsTCPIP.CConnectTCPIP", "Receive AGV撤销任务", agvdev.ToString(), "托盘条码:" + dvMonintor[0]["F_TxtParam"] + ",调度任务索引:" + fid.ToString(), chatnew);
|
|
OnWriteDarkCasket(e);
|
|
for (int j = 0; j < dv.Count; j++)
|
|
{
|
|
ActionFinish(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)
|
|
{
|
|
TcpError = "DisposeReceivedMessage:AGV对监控调度申请删除任务的回复," + ex.StackTrace + ex.Message;
|
|
}
|
|
|
|
i += 5;
|
|
|
|
}
|
|
break;
|
|
#endregion
|
|
|
|
case 60007://60007[T1][T2][CK]
|
|
#region AGV控制台任务删除申请
|
|
if (message.Length >= 4)//
|
|
{
|
|
if (message.Length <= (i + 3)) { i += 4; break; }
|
|
ck = message[i] + message[i + 1] + message[i + 2] ;
|
|
if (ck != message[i + 3]) { i += 4;break; }
|
|
_Sdata = new byte[16];
|
|
_Sdata[0] = Convert.ToByte(message[i] & 255);
|
|
_Sdata[1] = Convert.ToByte((message[i] >> 8) & 255);
|
|
_Sdata[2] = Convert.ToByte((message[i] >> 16) & 255);
|
|
_Sdata[3] = Convert.ToByte((message[i] >> 24) & 255);
|
|
_Sdata[4] = Convert.ToByte(message[i + 1] & 255);
|
|
_Sdata[5] = Convert.ToByte((message[i + 1] >> 8) & 255);
|
|
_Sdata[6] = Convert.ToByte((message[i + 1] >> 16) & 255);
|
|
_Sdata[7] = Convert.ToByte((message[i + 1] >> 24) & 255);
|
|
_Sdata[8] = Convert.ToByte(message[i + 2] & 255);
|
|
_Sdata[9] = Convert.ToByte((message[i + 2] >> 8) & 255);
|
|
_Sdata[10] = Convert.ToByte((message[i + 2] >> 16) & 255);
|
|
_Sdata[11] = Convert.ToByte((message[i + 2] >> 24) & 255);
|
|
ck = message[i] + message[i + 1] + message[i + 2];
|
|
_Sdata[12] = Convert.ToByte(ck & 255);
|
|
_Sdata[13] = Convert.ToByte((ck >> 8) & 255);
|
|
_Sdata[14] = Convert.ToByte((ck >> 16) & 255);
|
|
_Sdata[15] = Convert.ToByte((ck >> 24) & 255);
|
|
CSendDeviceOrderEventArgs sd = new CSendDeviceOrderEventArgs(agvdev, rIP, rport, _Sdata);
|
|
OnSendDeviceOrder(sd);
|
|
chatnew = new int[4];
|
|
Array.Copy(message, i, chatnew, 0, 4);
|
|
CWriteDarkCasketEventArgs e = new CWriteDarkCasketEventArgs("SocketsTCPIP.CConnectTCPIP", "Receive", agvdev.ToString(), "AGV控制台任务删除申请", chatnew);
|
|
OnWriteDarkCasket(e);
|
|
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 += 4;
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
byte[] sdd = new byte[16];//20130821
|
|
sdd[0] = Convert.ToByte(60006 & 255);//调度向AGV控制台申请删除任务
|
|
sdd[1] = Convert.ToByte((60006 >> 8) & 255);
|
|
sdd[2] = Convert.ToByte((60006 >> 16) & 255);
|
|
sdd[3] = Convert.ToByte((60006 >> 24) & 255);
|
|
sdd[4] = Convert.ToByte(message[i + 1] & 255);
|
|
sdd[5] = Convert.ToByte((message[i + 1] >> 8) & 255);
|
|
sdd[6] = Convert.ToByte((message[i + 1] >> 16) & 255);
|
|
sdd[7] = Convert.ToByte((message[i + 1] >> 24) & 255);
|
|
sdd[8] = Convert.ToByte(message[i + 2] & 255);
|
|
sdd[9] = Convert.ToByte((message[i + 2] >> 8) & 255);
|
|
sdd[10] = Convert.ToByte((message[i + 2] >> 16) & 255);
|
|
sdd[11] = Convert.ToByte((message[i + 2] >> 24) & 255);
|
|
ck = 60006 + message[i + 1] + message[i + 2];
|
|
sdd[12] = Convert.ToByte(ck & 255);
|
|
sdd[13] = Convert.ToByte((ck >> 8) & 255);
|
|
sdd[14] = Convert.ToByte((ck >> 16) & 255);
|
|
sdd[15] = Convert.ToByte((ck >> 24) & 255);
|
|
|
|
sd = new CSendDeviceOrderEventArgs(agvdev, rIP, rport, sdd);//20130821
|
|
OnSendDeviceOrder(sd);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TcpError = "DisposeReceivedMessage:AGV控制台任务删除申请," + ex.StackTrace + ex.Message;
|
|
}
|
|
|
|
i += 4;
|
|
|
|
}
|
|
break;
|
|
#endregion
|
|
|
|
case 60011://60011[R][C][N][CK]R为1, 需控制台确认;C为1;N为车间编号 (1化成A,2化成B,3腐蚀)//20130624
|
|
if (message.Length >= 5)
|
|
{
|
|
if (message.Length <= (i + 4)) { i += 5; break; }
|
|
ck = message[i] + message[i + 1] + message[i + 2] + message[i + 3];
|
|
if (ck != message[i + 4]) { i += 5; break; }
|
|
_Sdata = new byte[20];
|
|
_Sdata[0] = Convert.ToByte(message[i] & 255);
|
|
_Sdata[1] = Convert.ToByte((message[i] >> 8) & 255);
|
|
_Sdata[2] = Convert.ToByte((message[i] >> 16) & 255);
|
|
_Sdata[3] = Convert.ToByte((message[i] >> 24) & 255);
|
|
_Sdata[4] = Convert.ToByte(message[i + 1] & 255);
|
|
_Sdata[5] = Convert.ToByte((message[i + 1] >> 8) & 255);
|
|
_Sdata[6] = Convert.ToByte((message[i + 1] >> 16) & 255);
|
|
_Sdata[7] = Convert.ToByte((message[i + 1] >> 24) & 255);
|
|
_Sdata[8] = Convert.ToByte(message[i + 2] & 255);
|
|
_Sdata[9] = Convert.ToByte((message[i + 2] >> 8) & 255);
|
|
_Sdata[10] = Convert.ToByte((message[i + 2] >> 16) & 255);
|
|
_Sdata[11] = Convert.ToByte((message[i + 2] >> 24) & 255);
|
|
_Sdata[12] = Convert.ToByte(message[i + 3] & 255);
|
|
_Sdata[13] = Convert.ToByte((message[i + 3] >> 8) & 255);
|
|
_Sdata[14] = Convert.ToByte((message[i + 3] >> 16) & 255);
|
|
_Sdata[15] = Convert.ToByte((message[i + 3] >> 24) & 255);
|
|
_Sdata[16] = Convert.ToByte(ck & 255);
|
|
_Sdata[17] = Convert.ToByte((ck >> 8) & 255);
|
|
_Sdata[18] = Convert.ToByte((ck >> 16) & 255);
|
|
_Sdata[19] = Convert.ToByte((ck >> 24) & 255);
|
|
CSendDeviceOrderEventArgs sd1 = new CSendDeviceOrderEventArgs(agvdev, rIP, rport, _Sdata);
|
|
OnSendDeviceOrder(sd1);
|
|
AheadDetect.Clear();
|
|
if (message[i + 3] == 1)
|
|
{
|
|
AheadDetect.Append("化成A车间");
|
|
}
|
|
else if (message[i + 3] == 2)
|
|
{
|
|
AheadDetect.Append("化成B车间");
|
|
}
|
|
else if (message[i + 3] == 3)
|
|
{
|
|
AheadDetect.Append("腐蚀车间");
|
|
}
|
|
RefreshMonitorEventArgs rea = new RefreshMonitorEventArgs("notifyIcon1", string.Format("警告:{0},AGV发生故障!", AheadDetect.ToString()));
|
|
OnRefreshMonitor(rea);
|
|
i += 5;
|
|
}
|
|
break;
|
|
|
|
#region 暂时不用的旧协议部分
|
|
|
|
|
|
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=").Append(agvdev);
|
|
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);
|
|
CSendDeviceOrderEventArgs sd = new CSendDeviceOrderEventArgs(agvdev, dvc[0]["F_RemoteIP"].ToString(), Convert.ToInt32(dvc[0]["F_RemotePort"]), _Sdata);
|
|
OnSendDeviceOrder(sd);
|
|
|
|
}
|
|
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)
|
|
{
|
|
//任务状态: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, agvdev, 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(agvdev).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], agvdev);
|
|
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, agvdev, 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(agvdev).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, agvdev, 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(agvdev).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], agvdev);
|
|
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, agvdev, 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(agvdev).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 int[7];//20110110
|
|
Array.Copy(message, i, chatnew, 0, 7);//20110110
|
|
CWriteDarkCasketEventArgs e = new CWriteDarkCasketEventArgs("SocketsTCPIP.CConnectTCPIP", "Receive", agvdev.ToString(), "在输送机:" + device.ToString() + ",AGV询问是否可移载", chatnew);
|
|
OnWriteDarkCasket(e);
|
|
|
|
DataSourceChange();//20110405
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TcpError = "DisposeReceivedMessage:入库口输送机,AGV询问是否可移载," + ex.StackTrace + 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], agvdev) != 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 = "DisposeReceivedMessage:AGV移载开始," + ex.Message;
|
|
//}
|
|
chatnew = new int[7];
|
|
Array.Copy(message, i, chatnew, 0, 7);
|
|
CWriteDarkCasketEventArgs e = new CWriteDarkCasketEventArgs("SocketsTCPIP.CConnectTCPIP", "Receive", agvdev.ToString(), "AGV移载开始", chatnew);
|
|
OnWriteDarkCasket(e);
|
|
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], agvdev) != null))//多叉关联
|
|
// {//检查关联站台
|
|
|
|
// deviceCorr = GetCorrDeviceIndex(device);
|
|
// LifterIndex1 = deviceCorr;
|
|
// MonitorIndex1 = Convert.ToInt32(CGeneralFunction.GetDoubleForkMonitorInfo(message[i + 2], agvdev)[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 = "DisposeReceivedMessage:AGV移载结束," + ex.Message;
|
|
//}
|
|
chatnew = new int[7];
|
|
Array.Copy(message, i, chatnew, 0, 7);
|
|
CWriteDarkCasketEventArgs e = new CWriteDarkCasketEventArgs("SocketsTCPIP.CConnectTCPIP", "Receive", agvdev.ToString(), "AGV移载结束", chatnew);
|
|
OnWriteDarkCasket(e);
|
|
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)
|
|
{
|
|
TcpError = "DisposeReceivedMessage:AGV移载故障," + ex.StackTrace + ex.Message;
|
|
}
|
|
chatnew = new int[6];
|
|
Array.Copy(message, i, chatnew, 0, 6);
|
|
CWriteDarkCasketEventArgs e = new CWriteDarkCasketEventArgs("SocketsTCPIP.CConnectTCPIP", "Receive", agvdev.ToString(), "AGV移载故障", chatnew);
|
|
OnWriteDarkCasket(e);
|
|
i += 6;
|
|
|
|
}
|
|
break;
|
|
#endregion
|
|
case 60058://60058[N][A]
|
|
#region AGV申请进入特殊节点
|
|
if (message.Length >= 3)//
|
|
{
|
|
if (message.Length <= (i + 2)) break;
|
|
try
|
|
{
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TcpError = "DisposeReceivedMessage:AGV申请进入特殊节点," + ex.StackTrace + ex.Message;
|
|
}
|
|
chatnew = new int[3];
|
|
Array.Copy(message, i, chatnew, 0, 3);
|
|
CWriteDarkCasketEventArgs e1 = new CWriteDarkCasketEventArgs("SocketsTCPIP.CConnectTCPIP", "Receive", agvdev.ToString(), "AGV申请进入特殊节点", chatnew);
|
|
OnWriteDarkCasket(e1);
|
|
|
|
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)
|
|
{
|
|
TcpError = "DisposeReceivedMessage:AGV报告位置状态," + ex.StackTrace + ex.Message;
|
|
}
|
|
chatnew = new int[6];
|
|
Array.Copy(message, i, chatnew, 0, 6);
|
|
CWriteDarkCasketEventArgs e1 = new CWriteDarkCasketEventArgs("SocketsTCPIP.CConnectTCPIP", "Receive", agvdev.ToString(), "AGV报告位置状态", chatnew);
|
|
OnWriteDarkCasket(e1);
|
|
|
|
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)
|
|
{
|
|
TcpError = "DisposeReceivedMessage:AGV故障报告," + ex.StackTrace + ex.Message;
|
|
}
|
|
chatnew = new int[5];
|
|
Array.Copy(message, i, chatnew, 0, 5);
|
|
CWriteDarkCasketEventArgs e1 = new CWriteDarkCasketEventArgs("SocketsTCPIP.CConnectTCPIP", "Receive", agvdev.ToString(), "AGV故障报告", chatnew);
|
|
OnWriteDarkCasket(e1);
|
|
|
|
i += 5;
|
|
|
|
}
|
|
break;
|
|
#endregion
|
|
case 60081://允许AGV移载的应答:60081[T1][T2][CK](对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), agvdev);
|
|
bool snyc = CGeneralFunction.DoubleForkIfSync(Convert.ToInt32(ob), agvdev, 6);
|
|
ActionFinish(agvdev, Convert.ToInt32(ob), 0);
|
|
//20110608ActionComplete(agvdev, 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(agvdev, Convert.ToInt32(df[0]), 1);
|
|
//20110608ActionComplete(agvdev, Convert.ToInt32(df[0]), 1);//20100702
|
|
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
DataSourceChange();//20110405
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TcpError = "DisposeReceivedMessage:允许AGV移载的应答," + ex.StackTrace + ex.Message;
|
|
}
|
|
chatnew = new int[3];
|
|
Array.Copy(message, i, chatnew, 0, 3);
|
|
CWriteDarkCasketEventArgs e = new CWriteDarkCasketEventArgs("SocketsTCPIP.CConnectTCPIP", "Receive", agvdev.ToString(), "允许AGV移载的应答", chatnew);
|
|
OnWriteDarkCasket(e);
|
|
|
|
i += 3;
|
|
}
|
|
break;
|
|
|
|
#endregion
|
|
#endregion
|
|
default:
|
|
i=message.Length;
|
|
TcpError = "CConnectTCPIP.DisposeReceiveMessage:通讯协议帧长度错误!";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TcpError = "CConnectTCPIP.DisposeReceiveMessage:" + ex.StackTrace + ex.Message;
|
|
|
|
}
|
|
finally
|
|
{//20100127
|
|
chatnew = null;
|
|
dv.Dispose();
|
|
dva.Dispose();
|
|
}
|
|
}
|
|
#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;
|
|
TcpError = "SocketsTCPIP:GetDeviceKindIdx," + ex.StackTrace + ex.Message;
|
|
return -1;
|
|
}
|
|
finally
|
|
{
|
|
dv = null;
|
|
|
|
}
|
|
}
|
|
public static int GetAGVServer(string ipaddress)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_DeviceIndex FROM T_Base_Device WHERE (F_RemoteIP = '").Append(ipaddress).Append(" ')");
|
|
string obj = dbo.GetSingle(sql.ToString()).ToString();
|
|
if (obj == null)
|
|
{
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return Convert.ToInt32(obj);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class StateObject
|
|
{
|
|
public Socket workSocket = null;
|
|
public const int BUFFER_SIZE = 1024;
|
|
public byte[] buffer = new byte[BUFFER_SIZE];
|
|
public string remoteIP = string.Empty;
|
|
}
|
|
|
|
static class CGeneralFunction
|
|
{
|
|
static StringBuilder sql = new StringBuilder();
|
|
static DBOperator dbo = CClientTCPIP.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;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|