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.

2236 lines
124 KiB

using System;
using System.Collections.Generic;
using System.Text;
using ICommLayer;
using DBFactory;
using System.Data;
using Microsoft.VisualBasic;
using System.Linq;
namespace OPCClient
{
public class CSendDeviceOrder : ISendDeviceOrder
{
Model.MDevice devinfo;
string _commLayerError;
StringBuilder sql = new StringBuilder();
StringBuilder sss = new StringBuilder();
public string CommLayerError
{
get { return _commLayerError; }
set { _commLayerError = value; }
}
DBOperator dbo = CCommonOPCClient.dbo;
//Model.MDevice devinfo;
public CSendDeviceOrder()
{
dbo.Open();
}
/// <summary>
/// 发送堆垛机命令
/// </summary>
/// <param name="MessageIndex">消息编号</param>
/// <param name="TaskIndex">任务编号</param>
/// <param name="Order">堆垛机命令字</param>
///1-复位
///2-将取
///3-将送
///4-取货
///5-放货
///6-取放货
/// <param name="DeviceIndex">设备编号</param>
/// <param name="StartX">起始x坐标,排-沿轨道方向</param>
/// <param name="StartY">起始y坐标,层-高度方向</param>
/// <param name="StartZ">起始z坐标,列-面向堆垛机操作面板,1-左侧,2-右侧</param>
/// <param name="EndX">目标x坐标,列-沿轨道方向</param>
/// <param name="EndY">目标y坐标,层-高度方向</param>
/// <param name="EndZ">目标z坐标,排-面向堆垛机操作面板,1-左侧,2-右侧</param>
/// <returns>发送堆垛机命令是否成功</returns>
public bool SendDeviceOrder(int MessageIndex, int TaskIndex, int Order, int DeviceIndex, int StartX, int StartY, int StartZ, int EndX, int EndY, int EndZ, out StringBuilder[] _itemnames, out StringBuilder[] _itemvalues)
{//20120820
StringBuilder[] itemnames = { new StringBuilder("") };
StringBuilder[] itemvalues = { new StringBuilder("") };
string barcode = GetBarcodeFromMonitorIndex(TaskIndex);
int sn = 0; int UseAwayFork = 0;
try
{
devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIndex);
if (CCommonOPCClient.ConnectCount[devinfo.S7Connection] > 0)
{//20231017
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:设备所在PLC已离线!";
return false;
}
if (devinfo.XCoor == 0 && devinfo.DeviceKind != 13) return false;
int[] sendmes = new int[10] { MessageIndex, TaskIndex, Order, DeviceIndex, StartX, StartY, StartZ, EndX, EndY, EndZ };
devinfo.SendMessage = sendmes;
Model.CGetInfo.SetDeviceMessage(devinfo);
if (devinfo == null)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:在设备表中没找到设备所引!";
return false;
}
else
{
if (devinfo.DeviceKind == 1)
{
#region 堆垛机
int[] startz = new int[devinfo.ForkAmount];
int[] endz = new int[devinfo.ForkAmount];
if (devinfo.IfCorrelDoubleFork == "1")
{
#region 多叉堆垛机
//堆垛机的原点属性
char[] sp = new char[1] { ',' };
string[] yd = devinfo.StackZeroColLayer.Split(sp);
int zeroXcoor = 0;
if (yd.GetLength(0) > 0)
{
zeroXcoor = Convert.ToInt32(yd[0]);
}
else
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:堆垛机的原点坐标没有填写!";
return false;
}
for (int i = 0; i < devinfo.ForkAmount; i++)
{
startz[i] = 0;
endz[i] = 0;
}
#region 堆垛机的双叉取货指令,在此决定分配货叉、同步还是异步发送
if ((Order == 4) || (Order == 2))
{
///EndX = 0; EndY = 0; EndZ = 0;
int mti = Model.CGeneralFunction.GetManageTaskKindIndexFromMonitor(TaskIndex);
int fid = Model.CGeneralFunction.GetManageTaskIndexfromMonitor(TaskIndex);
#region 分配货叉,修改路径的双叉自关联站台信息
//如果不是多叉关联任务:ST_CELL的FDoubleFork=0,则奇数列使用近货叉,偶数列使用远货叉;否则货叉按照ST_CELL的FDoubleFork的值
Dictionary<int, string[]> rr = Model.CGeneralFunction.GetDoubleForkMonitorInfo(TaskIndex, DeviceIndex);
if (rr == null)
{
#region 无关联任务
//如果F_UseAwayFork='0',分配货叉,否则已经分配好货叉无需再分配
if (Model.CGeneralFunction.GetUseAwayFork(TaskIndex) == "0")
{
UseAwayFork = Model.CGeneralFunction.GetDoubleForkFromST_CELL(StartZ, StartX, StartY, Model.CGeneralFunction.GetWAREHOUSEFromSTCELL(DeviceIndex));
if (UseAwayFork == 0)
{
devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIndex);
if (devinfo != null)
{
int stackno = 0;
if (devinfo.VirtualStack > 0)
{
stackno = devinfo.VirtualStack;
}
else
{
stackno = DeviceIndex;
}
#region 巷道货位判断是否为极限列,以极限列为准分配货叉
sql.Clear();
sql.Append("SELECT F_ForwardLimitX,F_BackLimitX FROM T_Base_LaneInfo WHERE F_StackIndex = ").Append(stackno).Append(" and F_ForwardLimitX>0 and F_BackLimitX>0");
DataView dvl = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if ((devinfo.IfCorrelDoubleFork == "1") && (dvl.Count > 0))
{
if (zeroXcoor < Convert.ToInt32(dvl[0]["F_ForwardLimitX"]))
{//如果原点列坐标小于ForwardLimitX,检查ForwardLimitX至ForwardLimitX+(n-2);
if ((StartX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) >= 0) && ((StartX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) <= (devinfo.ForkAmount - 2))))
{
UseAwayFork = (StartX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) + 1);
}
else if ((EndX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) >= 0) && ((EndX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) <= (devinfo.ForkAmount - 2))))
{
UseAwayFork = (EndX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) + 1);
}
}
else if (zeroXcoor > Convert.ToInt32(dvl[0]["F_ForwardLimitX"]))
{//如果原点列坐标大于ForwardLimitX,检查ForwardLimitX至ForwardLimitX-(n-2).
if ((Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - StartX >= 0) && ((Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - StartX <= (devinfo.ForkAmount - 2))))
{
UseAwayFork = (Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - StartX + 1);
}
else if ((Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - EndX >= 0) && ((Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - EndX <= (devinfo.ForkAmount - 2))))
{
UseAwayFork = (Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - EndX + 1);
}
}
if (zeroXcoor < Convert.ToInt32(dvl[0]["F_BackLimitX"]))
{//如果原点列坐标小于F_BackLimitX,检查F_BackLimitX至F_BackLimitX-(n-2);
if ((Convert.ToInt32(dvl[0]["F_BackLimitX"]) - StartX >= 0) && ((Convert.ToInt32(dvl[0]["F_BackLimitX"]) - StartX <= (devinfo.ForkAmount - 2))))
{
UseAwayFork = (devinfo.ForkAmount - (Convert.ToInt32(dvl[0]["F_BackLimitX"]) - StartX));
}
else if ((Convert.ToInt32(dvl[0]["F_BackLimitX"]) - EndX >= 0) && ((Convert.ToInt32(dvl[0]["F_BackLimitX"]) - EndX <= (devinfo.ForkAmount - 2))))
{
UseAwayFork = (devinfo.ForkAmount - (Convert.ToInt32(dvl[0]["F_BackLimitX"]) - EndX));
}
}
else if (zeroXcoor > Convert.ToInt32(dvl[0]["F_BackLimitX"]))
{//如果原点列坐标大于F_BackLimitX,检查F_BackLimitX至F_BackLimitX+(n-2).
if ((StartX - Convert.ToInt32(dvl[0]["F_BackLimitX"]) >= 0) && ((StartX - Convert.ToInt32(dvl[0]["F_BackLimitX"]) <= (devinfo.ForkAmount - 2))))
{
UseAwayFork = (devinfo.ForkAmount - (StartX - Convert.ToInt32(dvl[0]["F_BackLimitX"])));
}
else if ((EndX - Convert.ToInt32(dvl[0]["F_BackLimitX"]) >= 0) && ((EndX - Convert.ToInt32(dvl[0]["F_BackLimitX"]) <= (devinfo.ForkAmount - 2))))
{
UseAwayFork = (devinfo.ForkAmount - (EndX - Convert.ToInt32(dvl[0]["F_BackLimitX"])));
}
}
}
#endregion
}
if (UseAwayFork == 0)
{
if ((StartX % devinfo.ForkAmount) == 0)
{
UseAwayFork = devinfo.ForkAmount;
}
else
{
UseAwayFork = StartX % devinfo.ForkAmount;
}
}
}
if (UseAwayFork > devinfo.ForkAmount)
{
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "发送多叉堆垛机命令", DeviceIndex.ToString(), barcode.ToCharArray() + ",分配货叉失败,排:" + StartZ.ToString() + "列:" + StartX.ToString() + "层:" + StartY.ToString() + ",货叉总数" + devinfo.ForkAmount.ToString() + ",分配的实际货叉" + UseAwayFork.ToString());
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + barcode + ",分配货叉失败,排:" + StartZ.ToString() + "列:" + StartX.ToString() + "层:" + StartY.ToString() + ",货叉总数" + devinfo.ForkAmount.ToString() + ",分配的实际货叉" + UseAwayFork.ToString();
return false;
}
//20111226同时考虑调整路径所选站台和提前检测
bool rp = SetLaneGateReplace(mti, fid, DeviceIndex, TaskIndex, UseAwayFork);//20120217
sql.Clear();
sql.Append("UPDATE T_Monitor_Task SET F_UseAwayFork = '").Append(UseAwayFork).Append("' WHERE (F_ManageTaskIndex = ")
.Append(fid).Append(") AND (F_ManageTASKKINDINDEX = ")
.Append(mti).Append(") AND F_DeviceIndex = ").Append(DeviceIndex);
dbo.ExecuteSql(sql.ToString());
if (rp == true) return false;//20120217
}
else
{
UseAwayFork = Convert.ToInt32(Model.CGeneralFunction.GetUseAwayFork(TaskIndex));
if (UseAwayFork > devinfo.ForkAmount)
{
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "发送多叉堆垛机命令", DeviceIndex.ToString(), barcode.ToCharArray() + ",获取任务时分配的货叉错误,排:" + StartZ.ToString() + "列:" + StartX.ToString() + "层:" + StartY.ToString() + ",货叉总数" + devinfo.ForkAmount.ToString() + ",分配的实际货叉" + UseAwayFork.ToString());
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + barcode + ",获取任务时分配的货叉错误,排:" + StartZ.ToString() + "列:" + StartX.ToString() + "层:" + StartY.ToString() + ",货叉总数" + devinfo.ForkAmount.ToString() + ",分配的实际货叉" + UseAwayFork.ToString();
return false;
}
//20111226同时考虑调整路径所选站台和提前检测
bool rp = SetLaneGateReplace(mti, fid, DeviceIndex, TaskIndex, UseAwayFork);//20120217
sql.Clear();
sql.Append("UPDATE T_Monitor_Task SET F_UseAwayFork = '").Append(UseAwayFork).Append("' WHERE (F_ManageTaskIndex = ")
.Append(fid).Append(") AND (F_ManageTASKKINDINDEX = ")
.Append(mti).Append(")");//AND F_DeviceIndex = ").Append(DeviceIndex)
dbo.ExecuteSql(sql.ToString());
if (rp == true) return false;//20120217
}
#endregion
}
else
{
#region 有关联任务
Dictionary<int, double> minzerodis = new Dictionary<int, double>();
Dictionary<int, string[]> rrnew = rr;
int mintask = 0; double minDist = 0; int[] tasks;
while (rrnew.Keys.Count > 0)
{
tasks = new int[rrnew.Keys.Count];
rrnew.Keys.CopyTo(tasks, 0);
//计算任务离原点的距离由小到大排序
Model.CGeneralFunction.GetMinZeroDistanceTask(tasks, devinfo, Order, out mintask, out minDist);
minzerodis.Add(mintask, minDist);
rrnew.Remove(mintask);
}
int forkno = 1; int tempStartX = 0, tempEndX = 0;
bool Ifreturn = false;
foreach (int task in minzerodis.Keys)
{
UseAwayFork = 0;
mti = Model.CGeneralFunction.GetManageTaskKindIndexFromMonitor(task);
fid = Model.CGeneralFunction.GetManageTaskIndexfromMonitor(task);
if (Model.CGeneralFunction.GetUseAwayFork(task) == "0")
{
//未分配货叉,判断是否为极限货位,n叉考虑极限货位的n-1列;
#region 巷道货位判断是否为极限列,以极限列为准分配货叉
int stackno = 0;
if (devinfo.VirtualStack > 0)
{
stackno = devinfo.VirtualStack;
}
else
{
stackno = DeviceIndex;
}
sql.Clear();
sql.Append("SELECT F_ForwardLimitX,F_BackLimitX FROM T_Base_LaneInfo WHERE F_StackIndex = ").Append(stackno).Append(" and F_ForwardLimitX>0 and F_BackLimitX>0");
DataView dvl = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
tempStartX = Model.CGeneralFunction.GetXCoorFromMonitor(task, DeviceIndex, 4);
tempEndX = Model.CGeneralFunction.GetXCoorFromMonitor(task, DeviceIndex, 5);
if ((devinfo.IfCorrelDoubleFork == "1") && (dvl.Count > 0))
{
if (zeroXcoor < Convert.ToInt32(dvl[0]["F_ForwardLimitX"]))
{//如果原点列坐标小于ForwardLimitX,检查ForwardLimitX至ForwardLimitX+(n-2);
if ((tempStartX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) >= 0) && ((tempStartX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) <= (devinfo.ForkAmount - 2))))
{
UseAwayFork = (tempStartX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) + 1);
}
else if ((tempEndX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) >= 0) && ((tempEndX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) <= (devinfo.ForkAmount - 2))))
{
UseAwayFork = (tempEndX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) + 1);
}
}
else if (zeroXcoor > Convert.ToInt32(dvl[0]["F_ForwardLimitX"]))
{//如果原点列坐标大于ForwardLimitX,检查ForwardLimitX至ForwardLimitX-(n-2).
if ((Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - tempStartX >= 0) && ((Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - tempStartX <= (devinfo.ForkAmount - 2))))
{
UseAwayFork = (Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - tempStartX + 1);
}
else if ((Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - tempEndX >= 0) && ((Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - tempEndX <= (devinfo.ForkAmount - 2))))
{
UseAwayFork = (Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - tempEndX + 1);
}
}
if (zeroXcoor < Convert.ToInt32(dvl[0]["F_BackLimitX"]))
{//如果原点列坐标小于F_BackLimitX,检查F_BackLimitX至F_BackLimitX-(n-2);
if ((Convert.ToInt32(dvl[0]["F_BackLimitX"]) - tempStartX >= 0) && ((Convert.ToInt32(dvl[0]["F_BackLimitX"]) - tempStartX <= (devinfo.ForkAmount - 2))))
{
UseAwayFork = (devinfo.ForkAmount - (Convert.ToInt32(dvl[0]["F_BackLimitX"]) - tempStartX));
}
else if ((Convert.ToInt32(dvl[0]["F_BackLimitX"]) - tempEndX >= 0) && ((Convert.ToInt32(dvl[0]["F_BackLimitX"]) - tempEndX <= (devinfo.ForkAmount - 2))))
{
UseAwayFork = (devinfo.ForkAmount - (Convert.ToInt32(dvl[0]["F_BackLimitX"]) - tempEndX));
}
}
else if (zeroXcoor > Convert.ToInt32(dvl[0]["F_BackLimitX"]))
{//如果原点列坐标大于F_BackLimitX,检查F_BackLimitX至F_BackLimitX+(n-2).
if ((tempStartX - Convert.ToInt32(dvl[0]["F_BackLimitX"]) >= 0) && ((tempStartX - Convert.ToInt32(dvl[0]["F_BackLimitX"]) <= (devinfo.ForkAmount - 2))))
{
UseAwayFork = (devinfo.ForkAmount - (tempStartX - Convert.ToInt32(dvl[0]["F_BackLimitX"])));
}
else if ((tempEndX - Convert.ToInt32(dvl[0]["F_BackLimitX"]) >= 0) && ((tempEndX - Convert.ToInt32(dvl[0]["F_BackLimitX"]) <= (devinfo.ForkAmount - 2))))
{
UseAwayFork = (devinfo.ForkAmount - (tempEndX - Convert.ToInt32(dvl[0]["F_BackLimitX"])));
}
}
}
#endregion
//和堆垛机原点坐标做差取绝对值,值最小的是1叉,货叉已经分配过的不要重复
if (UseAwayFork == 0)
{
UseAwayFork = forkno;
}
}
else
{
UseAwayFork = Convert.ToInt32(Model.CGeneralFunction.GetUseAwayFork(task));
}
#region 如果货叉已经被关联任务占用,极限列会出现,需要剔除关联关系
if (IfDeleteRelative(mti, fid, task, UseAwayFork) == true)//扬州晶澳注释
{
return false;
}
#endregion
if (UseAwayFork > devinfo.ForkAmount)
{
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "发送多叉堆垛机命令", DeviceIndex.ToString(), barcode.ToCharArray() + ",关联任务分配货叉错误,排:" + StartZ.ToString() + "列:" + StartX.ToString() + "层:" + StartY.ToString() + ",货叉总数" + devinfo.ForkAmount.ToString() + ",分配的实际货叉" + UseAwayFork.ToString());
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + barcode + ",关联任务分配货叉错误,排:" + StartZ.ToString() + "列:" + StartX.ToString() + "层:" + StartY.ToString() + ",货叉总数" + devinfo.ForkAmount.ToString() + ",分配的实际货叉" + UseAwayFork.ToString();
dbo.ExecuteSql(string.Format("UPDATE T_Manage_Task SET F_RELATIVECONTORLID = - 1 WHERE (F_ManageTaskKindIndex = {0}) AND (FID = {1})", mti, fid));
return false;
}
forkno = UseAwayFork;
//20111226同时考虑调整路径所选站台和提前检测
bool rp = SetLaneGateReplace(mti, fid, DeviceIndex, task, UseAwayFork);//20120217
if (rp == true) Ifreturn = true;
sql.Clear();
sql.Append("UPDATE T_Monitor_Task SET F_UseAwayFork = '").Append(UseAwayFork).Append("' WHERE (F_ManageTaskIndex = ")
.Append(fid).Append(") AND (F_ManageTASKKINDINDEX = ")
.Append(mti).Append(")");//AND F_DeviceIndex = ").Append(DeviceIndex)
dbo.ExecuteSql(sql.ToString());
forkno++;
}
if (Ifreturn == true) return false;
#endregion
}
#endregion
#region 同步还是异步发送
int[] mutitasks = Model.CGeneralFunction.MutiForkIfSync(TaskIndex, DeviceIndex, devinfo.DeviceKind);
if (mutitasks != null)
{
foreach (int temptask in mutitasks)
{
UseAwayFork = Convert.ToInt32(Model.CGeneralFunction.GetUseAwayFork(temptask));
if (temptask == TaskIndex)
{
if (StartX > zeroXcoor)
{
StartX = StartX - (UseAwayFork - 1);
}
else
{
StartX = StartX + (UseAwayFork - 1);
}
}
}
}
else
{
UseAwayFork = Convert.ToInt32(Model.CGeneralFunction.GetUseAwayFork(TaskIndex));
if (StartX > zeroXcoor)
{
StartX = StartX - (UseAwayFork - 1);
}
else
{
StartX = StartX + (UseAwayFork - 1);
}
}
}
#endregion
#region 堆垛机的双叉送货指令,在此决定同步还是异步发送
if ((Order == 5) || (Order == 3))
{
UseAwayFork = Convert.ToInt32(Model.CGeneralFunction.GetUseAwayFork(TaskIndex));
#region 同步还是异步发送
int[] mutitasks = Model.CGeneralFunction.MutiForkIfSync(TaskIndex, DeviceIndex, devinfo.DeviceKind);
if (mutitasks != null)
{
foreach (int temptask in mutitasks)
{
UseAwayFork = Convert.ToInt32(Model.CGeneralFunction.GetUseAwayFork(temptask));
if (temptask == TaskIndex)
{
if (EndX > zeroXcoor)
{
EndX = EndX - (UseAwayFork - 1);
}
else
{
EndX = EndX + (UseAwayFork - 1);
}
}
}
}
else
{
if (EndX > zeroXcoor)
{
EndX = EndX - (UseAwayFork - 1);
}
else
{
EndX = EndX + (UseAwayFork - 1);
}
}
#endregion
}
#endregion
//9,11,13
int arrAmout = 9 + (devinfo.ForkAmount - 1) * 2;
int arrsn = 0; StringBuilder strap = new StringBuilder();
itemnames = new StringBuilder[arrAmout];
itemvalues = new StringBuilder[arrAmout];
for (int i = 0; i < arrAmout; i++)
{
itemnames[i] = new StringBuilder();
itemvalues[i] = new StringBuilder();
}
#endregion
sn = devinfo.Dbw1Address;
//将消息头和命令的赋值放在StringBuilder的最后位置
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 2)).Append(",i");
itemvalues[0].Append(TaskIndex.ToString());
itemnames[1].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 4)).Append(",b");
itemvalues[1].Append(StartX.ToString());
itemnames[2].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 5)).Append(",b");
itemvalues[2].Append(StartY.ToString());
for (int i = 1; i <= devinfo.ForkAmount; i++)
{
itemnames[2 + i].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 5 + i)).Append(",b");
itemvalues[2 + i].Append(startz[i - 1].ToString());
strap.Append(i.ToString()).Append("叉取排Z:").Append(startz[i - 1].ToString()).Append(";");
}
arrsn = 2 + devinfo.ForkAmount;
itemnames[arrsn + 1].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + arrsn + 4)).Append(",b");
itemvalues[arrsn + 1].Append(EndX.ToString());
itemnames[arrsn + 2].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + arrsn + 5)).Append(",b");
itemvalues[arrsn + 2].Append(EndY.ToString());
for (int i = 1; i <= devinfo.ForkAmount; i++)
{
itemnames[arrsn + 2 + i].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + arrsn + 5 + i)).Append(",b");
itemvalues[arrsn + 2 + i].Append(endz[i - 1].ToString());
strap.Append(i.ToString()).Append("叉送排Z:").Append(endz[i - 1].ToString()).Append(";");
}
itemnames[arrsn + 3 + devinfo.ForkAmount].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 1)).Append(",b");
itemvalues[arrsn + 3 + devinfo.ForkAmount].Append(Order.ToString());
itemnames[arrsn + 3 + devinfo.ForkAmount + 1].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[arrsn + 3 + devinfo.ForkAmount + 1].Append(MessageIndex.ToString());
sss.Remove(0, sss.Length);
sss.Append("条码:").Append(barcode).Append("**写标志").Append(MessageIndex.ToString()).Append("**命令字" + Order.ToString()).Append("**任务号" + TaskIndex.ToString())
.Append("**起始排" + StartZ.ToString()).Append("**起始列" + StartX.ToString()).Append("**起始层" + StartY.ToString())
.Append("**终止排" + EndZ.ToString()).Append("**终止列" + EndX.ToString()).Append("**终止层" + EndY.ToString())
.Append(";").Append(strap);
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "发送多叉堆垛机命令", DeviceIndex.ToString(), sss.ToString());
#endregion
}
else
{
#region 单叉堆垛机【为了适应电器采用双叉协议,增加取货Z2与送货Z2】
itemnames = new StringBuilder[12] { new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder("") };
itemvalues = new StringBuilder[12] { new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder("") };
#region 转换(Z)排坐标
//双伸堆垛机z转换改到数据库表t_base_sendrow
//if (StartZ != 0)
//{
// if (StartZ % 2 == 0)
// {
// StartZ = 2;
// }
// else
// {
// StartZ = 1;
// }
//}
//if (EndZ != 0)
//{
// if (EndZ % 2 == 0)
// {
// EndZ = 2;
// }
// else
// {
// EndZ = 1;
// }
//}
#endregion
//byte0,byte1,byte2,byte3,byte4
// int1 int3
//int0(byte0,byte1);int1(byte1,byte2);int2(byte2,byte3);int3(byte3,byte4)
sn = Convert.ToInt32(devinfo.Dbw1Address);
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 2)).Append(",i");
itemvalues[0].Append(TaskIndex.ToString());
itemnames[1].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 4)).Append(",b");
itemvalues[1].Append((StartX).ToString());
itemnames[2].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 5)).Append(",b");
itemvalues[2].Append(StartY.ToString());
itemnames[3].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 6)).Append(",b");
itemvalues[3].Append(StartZ.ToString());
//增加取货Z2
itemnames[4].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 7)).Append(",b");
itemvalues[4].Append("0");
itemnames[5].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 8)).Append(",b");
itemvalues[5].Append((EndX).ToString());
itemnames[6].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 9)).Append(",b");
itemvalues[6].Append(EndY.ToString());
itemnames[7].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 10)).Append(",b");
itemvalues[7].Append(EndZ.ToString());
//增加送货Z2
itemnames[8].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 11)).Append(",b");
itemvalues[8].Append("0");
itemnames[9].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 12)).Append(",b");
object ob = dbo.GetSingle(string.Format("select cell_model from T_MANAGE_TASK ,t_monitor_task where T_MANAGE_TASK.f_managetaskkindindex=t_monitor_task.f_managetaskkindindex and T_MANAGE_TASK.fid=t_monitor_task.f_managetaskindex and f_monitorindex={0}", TaskIndex));
if (ob != null)
{//20230815richard.liu【1小货;2大货】
itemvalues[9].Append(ob.ToString());
}
else
{
itemvalues[9].Append(0);
}
itemnames[10].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 1)).Append(",b");
itemvalues[10].Append(Order.ToString());//命令字
itemnames[11].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[11].Append(MessageIndex.ToString());//读写标志
sss.Remove(0, sss.Length);
sss.Append("条码:").Append(barcode).Append("**写标志").Append(MessageIndex.ToString()).Append("**命令字" + Order.ToString()).Append("**任务号" + TaskIndex.ToString())
.Append("**起始排" + StartZ.ToString()).Append("**起始列" + StartX.ToString()).Append("**起始层" + StartY.ToString())
.Append("**终止排" + EndZ.ToString()).Append("**终止列" + EndX.ToString()).Append("**终止层" + EndY.ToString());
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "发送堆垛机命令", DeviceIndex.ToString(), sss.ToString());
#endregion
}
if (WriteBarcode(DeviceIndex, TaskIndex) == false)
{
return false;
}
#endregion
}
#region 鸿安环穿主站richard.liu20230718
else if (devinfo.DeviceKind == 13)
{
CCommonOPCClient.Hostname = CommonClassLib.AppSettings.GetValue("HostName");
CCommonOPCClient.ProgID = CommonClassLib.AppSettings.GetValue("OPCProgID");
CCommonOPCClient.PlcConnectionID = devinfo.S7Connection;
if (MessageIndex >= 90)
{
if (MessageIndex == 99)
{//心跳,头99,Order心跳值
sn = Convert.ToInt32(devinfo.Dbw1Address);
itemnames = new StringBuilder[1] { new StringBuilder("") };
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn)).Append(",i");
itemvalues = new StringBuilder[1] { new StringBuilder("") };
itemvalues[0].Append(Order);
sss.Clear();
sss.Append("条码:").Append("-").Append("**写标志").Append(MessageIndex.ToString()).Append("**心跳" + Order.ToString()).Append("**任务号0");
}
else
{//特殊命令,头 90:系统启动,91:系统立即停止,92:系统循环停止,93:系统报警解除,94:异常异常解除,
sn = Convert.ToInt32(devinfo.Dbw1Address);
itemnames = new StringBuilder[1] { new StringBuilder("") };
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn)).Append(",b");
itemvalues = new StringBuilder[1] { new StringBuilder(MessageIndex) };
sss.Clear();
sss.Append("条码:").Append("-").Append("**写标志").Append(MessageIndex.ToString()).Append("**特殊命令字" + MessageIndex.ToString()).Append("**任务号0");
}
}
else if (MessageIndex >= 1 && MessageIndex <= 2)
{//1:新任务写入OK 2:任务变更写入OK
itemnames = new StringBuilder[6] { new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder("") };
itemvalues = new StringBuilder[6] { new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder("") };
sn = Convert.ToInt32(devinfo.Dbw1Address) + 1;//0-1心跳单独订阅;2特殊命令,3是写入标识
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 1)).Append(",i");
itemvalues[0].Append(TaskIndex.ToString());//任务号
itemnames[1].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 3)).Append(",b");
itemvalues[1].Append((Order).ToString());//任务类型 1:取卸货 2:取货 3:卸货 4:空车移动
itemnames[2].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 4)).Append(",b");
itemvalues[2].Append((barcode.Substring(0, 3) == "JAX" ? 1 : 2).ToString());//托盘类型 1:小托盘 2:大托盘;JAD,JAX,JAC
//20230815richard.liu
itemnames[3].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 5)).Append(",i");
itemvalues[3].Append(StartZ.ToString());//取货时的输送机编号//F_NUMPARAM1
itemnames[4].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 7)).Append(",i");
itemvalues[4].Append((EndZ).ToString());//卸货时的输送机编号F_NUMPARAM4
itemnames[5].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[5].Append(MessageIndex.ToString());//读写标志
sss.Clear();
sss.Append("条码:").Append(barcode).Append("**写标志").Append(MessageIndex.ToString()).Append("**命令字" + Order.ToString()).Append("**任务号" + TaskIndex.ToString()).Append("取货站台:").Append(StartZ).Append(",送货站台:").Append(EndZ);
}
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "发送环穿主站命令", DeviceIndex.ToString(), sss.ToString());
}
#endregion
#region 鸿安环穿小车任务应答richard.liu20230718
else if (devinfo.DeviceKind == 14)//20230815richard.liu
{//命令字99
CCommonOPCClient.Hostname = CommonClassLib.AppSettings.GetValue("HostName");
CCommonOPCClient.ProgID = CommonClassLib.AppSettings.GetValue("OPCProgID");
CCommonOPCClient.PlcConnectionID = devinfo.S7Connection;
itemnames = new StringBuilder[1] { new StringBuilder("") };
itemvalues = new StringBuilder[1] { new StringBuilder("") };
sn = Convert.ToInt32(devinfo.Dbw1Address);
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn)).Append(",i");
itemvalues[0].Append(TaskIndex.ToString());//任务号
sss.Remove(0, sss.Length);
sss.Append("条码:").Append("-").Append("**写标志").Append(MessageIndex.ToString()).Append("**反馈任务号" + TaskIndex.ToString());
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "发送环穿小车任务应答", DeviceIndex.ToString(), sss.ToString());
}
#endregion
//20230811richard.liu
//CCommonOPCClient.Hostname = CommonClassLib.AppSettings.GetValue("HostName");
//CCommonOPCClient.ProgID = CommonClassLib.AppSettings.GetValue("OPCProgID");
//CCommonOPCClient.PlcConnectionID = devinfo.S7Connection;//20110216
//if (CCommonOPCClient.SyncWriteAllItemValue(itemnames, itemvalues) == false)
//{
// _commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + CCommonOPCClient.OpcError;
// return false;
//}
}
return true;
}
catch (Exception ex)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + ex.Message + ex.StackTrace;
return false;
}
finally
{
_itemnames = itemnames;
_itemvalues = itemvalues;
devinfo = null;
}
}
bool IfDeleteRelative(int mti, int fid, int moniTask,int useawayfork)
{
DataView dv = new DataView();
try
{
int relfid= Model.CGeneralFunction.GetRelativeControlID(mti, fid);
sql.Clear();
sql.Append("SELECT DISTINCT T_Manage_Task.FID FROM T_Manage_Task,T_Monitor_Task where ")
.Append(" T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX ")
.Append(" AND T_Manage_Task.FID = T_Monitor_Task.F_ManageTaskIndex and ")
.Append(" (T_Manage_Task.F_RELATIVECONTORLID = ").Append(relfid).Append(") AND (T_Monitor_Task.F_UseAwayFork = '").Append(useawayfork).Append("') ")
.Append(" AND (T_Monitor_Task.F_ManageTASKKINDINDEX = ").Append(mti).Append(") AND (T_Monitor_Task.F_ManageTaskIndex <> ").Append(fid).Append(")");
dv=dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
dbo.ExecuteSql(string .Format("UPDATE T_Manage_Task SET F_RELATIVECONTORLID = - 1 WHERE (F_ManageTaskKindIndex = {0}) AND (FID = {1})",mti,fid));
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
private void GetLaneGateDeviceZXY(int StackIndex, int laneGate, out string DeviceZXY)
{
DeviceZXY = string.Empty;
sql.Clear();
sql.Append(string.Format("SELECT T_Base_Lane_Gate.F_ZXY FROM T_Base_Lane_Gate,T_Base_LaneInfo where T_Base_Lane_Gate.F_LaneIndex = T_Base_LaneInfo.F_LaneDeviceIndex and T_Base_LaneInfo.F_StackIndex={0} and T_Base_Lane_Gate.F_LaneGateDeviceIndex={1}", StackIndex, laneGate));
DataView dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
DeviceZXY = dv[0][0].ToString();
}
}
/// <summary>
/// 发送穿梭车、输送机设备命令
/// </summary>
/// <param name="MessageIndex">消息编号</param>
/// <param name="TaskIndex">任务编号</param>
/// <param name="Order">命令字</param>
/// 穿梭车命令字:
///1-复位
///2-左接货
///3-左送货
///4-右接货
///5-右送货
///6-停止
///7-运动(运动到第4、5字节指定的目标设备所引)
///输送机命令字:
///1-入库(朝向库)
///2-出库(背向库)
///3-送货
///4-接货
///5-停止
/// <param name="DeviceIndex">设备编号</param>
///<param name="ArrowDeviceIndex">对于输送机、穿梭车代表目标设备所引,
/// 0-代表单一设备控制,无目标设备所引;1…65535代表目标设备所引(终点输送机的设备所引)</param>
/// <returns>发送穿梭车、输送机设备命令是否成功</returns>
public bool SendDeviceOrder(int MessageIndex, int TaskIndex, int Order, int DeviceIndex, int ArrowDeviceIndex, out StringBuilder[] _itemnames, out StringBuilder[] _itemvalues)
{
StringBuilder[] itemnames = new StringBuilder[1] { new StringBuilder("") };
StringBuilder[] itemvalues = new StringBuilder[1] { new StringBuilder("") };
string barcode = GetBarcodeFromMonitorIndex(TaskIndex);
try
{
devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIndex);
if (CCommonOPCClient.ConnectCount[devinfo.S7Connection] > 0)
{//20231017
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:设备所在PLC已离线!";
return false;
}
if (devinfo.Dbw1Address < 0)
{
_commLayerError = DeviceIndex.ToString() + ":没有DB1发送命令数据区,不能发送设备指令!";
return false;
}
if (devinfo.XCoor == 0 && devinfo.YCoor == 0 && devinfo.DeviceKind == 4) return false;//20130510
int[] sendmes = new int[5] { MessageIndex, TaskIndex, Order, DeviceIndex, ArrowDeviceIndex };
devinfo.SendMessage = sendmes;
Model.CGetInfo.SetDeviceMessage(devinfo);
int sn = 0;
if (devinfo == null)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:设备索引不存在!";
return false;
}
else
{
if (devinfo.DeviceKind == 7)
{
return true;
}
if (devinfo.DeviceKind == 1)
{//堆垛机不允许使用此方法
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:堆垛机不允许使用此方法!";
return false;
}
//byte0,byte1,byte2,byte3,byte4
// int1 int3
//int0(byte0,byte1);int1(byte1,byte2);int2(byte2,byte3);int3(byte3,byte4)
sn = Convert.ToInt32(devinfo.Dbw1Address);
if (devinfo.DeviceKind == 31)
{
#region 高端输送
int reSendFlag = 0, HMISendDb1Address = 0;
GetHMISendInfo(out reSendFlag, out HMISendDb1Address, TaskIndex);//触摸屏申请重新发送20120220
int inworkbench = IfInworkBench(TaskIndex);
if (MessageIndex == 2)
{
barcode = "000000";
inworkbench = 0;
}
byte[] barbyte = new byte[6];
if (barcode.Length == 6)
{
barbyte = ASCIIEncoding.ASCII.GetBytes(barcode);
}
else
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:高端工位输送机条码不合法!";
return false;
}
if (reSendFlag == 2)//触摸屏申请重新发送20120220devinfo.UseCommonDB == "1"
{
sn = HMISendDb1Address;
itemnames = new StringBuilder[10]
{ new StringBuilder(""), new StringBuilder(""), new StringBuilder(""),
new StringBuilder(""), new StringBuilder(""), new StringBuilder(""),
new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder("") }; ;
itemvalues = new StringBuilder[10]
{ new StringBuilder(""), new StringBuilder(""), new StringBuilder(""),
new StringBuilder(""), new StringBuilder(""), new StringBuilder(""),
new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder("") }; ;
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[0].Append("0");
for (int i = 1; i <= 6; i++)
{
itemnames[i].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + i)).Append(",b");
itemvalues[i].Append(barbyte[i - 1]);
}
itemnames[7].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 7)).Append(",b");
itemvalues[7].Append(inworkbench);
itemnames[8].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 8)).Append(",i");
//20120207
StringBuilder a1 = new StringBuilder(devinfo.DeviceIndex.ToString().Substring(0, 1));
if (devinfo.DeviceIndex > 0)
{//托盘所在的当前设备索引
StringBuilder a2 = new StringBuilder(devinfo.DeviceIndex.ToString().Substring(2));
a1.Append(a2);
}
itemvalues[8].Append(a1.ToString());//托盘所在的当前设备索引
itemnames[9].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 10)).Append(",i");
itemvalues[9].Append(ArrowDeviceIndex.ToString());
}
else
{
itemnames = new StringBuilder[9]
{ new StringBuilder(""), new StringBuilder(""), new StringBuilder(""),
new StringBuilder(""), new StringBuilder(""), new StringBuilder(""),
new StringBuilder(""), new StringBuilder(""), new StringBuilder("")}; ;
itemvalues = new StringBuilder[9]
{ new StringBuilder(""), new StringBuilder(""), new StringBuilder(""),
new StringBuilder(""), new StringBuilder(""), new StringBuilder(""),
new StringBuilder(""), new StringBuilder(""), new StringBuilder("") }; ;
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[0].Append("0");
for (int i = 1; i <= 6; i++)
{
itemnames[i].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + i)).Append(",b");
itemvalues[i].Append(barbyte[i - 1]);
}
itemnames[7].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 7)).Append(",b");
itemvalues[7].Append(inworkbench);
itemnames[8].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 8)).Append(",i");
itemvalues[8].Append(ArrowDeviceIndex.ToString());
}
#endregion
}
else if (devinfo.DeviceKind == 40)
{
itemnames = new StringBuilder[1] { new StringBuilder("") };
itemvalues = new StringBuilder[1] { new StringBuilder("") };
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[0].Append(Order.ToString());
sss.Remove(0, sss.Length);
sss.Append("上位机发送紧急停车:").Append(DeviceIndex).Append("**指令").Append(MessageIndex.ToString());
}
else if (devinfo.DeviceKind == 4)//devinfo.IfCorrelDoubleFork == "1" &&成品库都按单工位车发送
{
#region 双工位RGV可并且取两个货
itemnames = new StringBuilder[5] { new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder("") };//, new StringBuilder("")
itemvalues = new StringBuilder[5] { new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder("") };//, new StringBuilder("")
//将消息头的赋值放在StringBuilder的最后位置
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 1)).Append(",b");
itemvalues[0].Append(Order.ToString());
itemnames[1].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 2)).Append(",i");
itemvalues[1].Append(TaskIndex.ToString());
itemnames[2].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 4)).Append(",di");
itemvalues[2].Append(ArrowDeviceIndex.ToString());//是否需要判断哪个输送机
//20230718richard.liu双工位RGV同时可取两个货
itemnames[3].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 8)).Append(",b");
int[] mutitasks = Model.CGeneralFunction.MutiForkIfSync(TaskIndex, DeviceIndex, devinfo.DeviceKind);
int UseAwayFork = 0;
if (mutitasks != null)
{
foreach (int temptask in mutitasks)
{
UseAwayFork += Convert.ToInt32(Model.CGeneralFunction.GetUseAwayFork(temptask));
}
}
else
{//单叉运行无关联任务
UseAwayFork = Convert.ToInt32(Model.CGeneralFunction.GetUseAwayFork(TaskIndex));
}
//itemvalues[3].Append(UseAwayFork); //1叉,2叉,3双叉
itemvalues[3].Append(0); //1叉,2叉,3双叉gjn
//itemnames[4].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 9)).Append(",b");
//itemvalues[4].Append(0);//预留
itemnames[4].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[4].Append(MessageIndex);
//itemnames[5].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
//itemvalues[5].Append(MessageIndex);
#endregion
}
else
{
#region 物流输送机
if (devinfo.UseCommonDB == "1")
{
itemnames = new StringBuilder[5] { new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder("") };
itemvalues = new StringBuilder[5] { new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder("") };
//将消息头的赋值放在StringBuilder的最后位置
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 1)).Append(",b");
itemvalues[0].Append(Order.ToString());
itemnames[1].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 2)).Append(",i");
itemvalues[1].Append(TaskIndex.ToString());
itemnames[2].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 4)).Append(",i");
itemvalues[2].Append(DeviceIndex.ToString());//起始设备编号(当前设备编号)
itemnames[3].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 6)).Append(",di");
itemvalues[3].Append(ArrowDeviceIndex.ToString());
itemnames[4].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[4].Append(MessageIndex);
}
else
{
if (devinfo.IfCorrelDoubleFork == "1")
{//多叉关联站台任务
#region 物流输送机双叉
devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIndex);
sn = Convert.ToInt32(devinfo.Dbw1Address);
itemnames = new StringBuilder[5] { new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder("") }; ;
itemvalues = new StringBuilder[5] { new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder("") }; ;
//itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
//itemvalues[0].Append("0");
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 1)).Append(",b");
itemvalues[0].Append(Order.ToString());
int taskindex1 = 0;
int taskindex2 = 0;
int[] mutitasks = Model.CGeneralFunction.MutiForkIfSync(TaskIndex, DeviceIndex, devinfo.DeviceKind);
if (mutitasks != null)
{
foreach (int temptask in mutitasks)
{
int UseAwayFork = Convert.ToInt32(Model.CGeneralFunction.GetUseAwayFork(temptask));
if (UseAwayFork == 0)
{
taskindex1 = temptask;
}
else if (UseAwayFork == 1)
{
taskindex1 = temptask;
}
else if (UseAwayFork == 2)
{
taskindex2 = temptask;
}
}
}
else
{
taskindex1 = TaskIndex;
}
itemnames[1].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 2)).Append(",i");
itemvalues[1].Append(taskindex1);
itemnames[2].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 4)).Append(",i");
itemvalues[2].Append(taskindex2);
itemnames[3].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 6)).Append(",di");
itemvalues[3].Append(ArrowDeviceIndex.ToString());
itemnames[4].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[4].Append(MessageIndex);
#endregion
}
else
{//普通输送机
itemnames = new StringBuilder[6] { new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder("") };
itemvalues = new StringBuilder[6] { new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder("") };
//将消息头的赋值放在StringBuilder的最后位置
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 1)).Append(",b");
itemvalues[0].Append(Order.ToString());
itemnames[1].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 2)).Append(",i");
itemvalues[1].Append(TaskIndex.ToString());
itemnames[2].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 4)).Append(",di");
itemvalues[2].Append(ArrowDeviceIndex.ToString());
//20230815richard.liu版型和打带由管理系统获得数据,默认值0
itemnames[3].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 8)).Append(",b");
object ob = dbo.GetSingle(string.Format("select BOXBOS from T_MANAGE_TASK ,t_monitor_task where T_MANAGE_TASK.f_managetaskkindindex=t_monitor_task.f_managetaskkindindex and T_MANAGE_TASK.fid=t_monitor_task.f_managetaskindex and f_monitorindex={0}", TaskIndex));
if ((DeviceIndex == 32072 || DeviceIndex == 32086 || DeviceIndex == 32103 || DeviceIndex == 32120))//&&Order==1
{
ob = dbo.GetSingle(string.Format("select IFLIFT from T_MANAGE_TASK ,t_monitor_task where T_MANAGE_TASK.f_managetaskkindindex=t_monitor_task.f_managetaskkindindex and T_MANAGE_TASK.fid=t_monitor_task.f_managetaskindex and f_monitorindex={0}", TaskIndex));
if (ob != null)
{//合托机告诉电气举起还是落下
itemvalues[3].Append(ob.ToString());
}
else
{
itemvalues[3].Append(0);
}
}
else
{
if (ob != null)
{//版型PALLET_LENGTH_TYPE, BOXBOS
itemvalues[3].Append(ob.ToString());
}
else
{
itemvalues[3].Append(0);
}
}
itemnames[4].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 9)).Append(",b");
ob = dbo.GetSingle(string.Format("select CONTROL_FLAG from T_MANAGE_TASK ,t_monitor_task where T_MANAGE_TASK.f_managetaskkindindex=t_monitor_task.f_managetaskkindindex and T_MANAGE_TASK.fid=t_monitor_task.f_managetaskindex and f_monitorindex={0}", TaskIndex));
if (ob != null)
{//打带PALLET_STRAPPING_NUM, CONTROL_FLAG
itemvalues[4].Append(ob.ToString());
}
else
{
itemvalues[4].Append(0);
}
itemnames[5].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[5].Append(MessageIndex);
}
}
#endregion
}
}
//20230811richard.liu
//CCommonOPCClient.Hostname = CommonClassLib.AppSettings.GetValue("HostName");
//CCommonOPCClient.ProgID = CommonClassLib.AppSettings.GetValue("OPCProgID");
//CCommonOPCClient.PlcConnectionID = devinfo.S7Connection;//20110216
//if (CCommonOPCClient.SyncWriteAllItemValue(itemnames, itemvalues) == false)
////if (CCommonOPCClient.AWriteAllItemValue(itemnames, itemvalues) == false)//采用异步通信的方式写入OPC数据
//{
// _commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + CCommonOPCClient.OpcError;
// return false;
//}
sss.Remove(0, sss.Length);
sss.Append("条码:").Append(barcode).Append("**写标志").Append(MessageIndex.ToString()).Append("**命令字" + Order.ToString()).Append("**任务号" + TaskIndex.ToString())
.Append("**目标位置" + ArrowDeviceIndex.ToString());
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "发送指令", devinfo.DeviceIndex.ToString(), sss.ToString());
return true;
}
catch (Exception ex)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + ex.Message + ex.StackTrace;
return false;
}
finally
{
devinfo = null;
_itemnames = itemnames;
_itemvalues = itemvalues;
}
}
public bool SendDeviceOrder(int MessageIndex, int TaskIndex, int Order, int DeviceIndex, string BatteryType, string ng)
{
StringBuilder[] itemnames = new StringBuilder[404];
StringBuilder[] itemvalues = new StringBuilder[404];
devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIndex);
string barcode = GetBarcodeFromMonitorIndex(TaskIndex);
try
{
int[] sendmes = new int[4] { MessageIndex, TaskIndex, Order, DeviceIndex };
devinfo.SendMessage = sendmes;
Model.CGetInfo.SetDeviceMessage(devinfo);
int sn = 0;
if (devinfo == null)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:设备索引不存在!";
return false;
}
else
{
if (devinfo.DeviceKind == 1)
{//堆垛机不允许使用此方法
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:堆垛机不允许使用此方法!";
return false;
}
char[] cc1 = new char[1] { '|' };
char[] cc2 = new char[1] { '-' };
for (int i = 0; i < 404; i++)
{
itemnames[i] = new StringBuilder("");
itemvalues[i] = new StringBuilder("");
}
sn = Convert.ToInt32(devinfo.Dbw1Address);
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[0].Append("0");
itemnames[1].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 1)).Append(",b");
itemvalues[1].Append(Order.ToString());
itemnames[2].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 2)).Append(",i");
itemvalues[2].Append(TaskIndex.ToString());
itemnames[3].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 4)).Append(",b");
itemvalues[3].Append(BatteryType.ToString());
for (int i = 4; i < 404; i++)
{
itemnames[i].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + i + 2)).Append(",b");
itemvalues[i].Append("0");
}
if (ng != "-")
{
string[] ng1 = ng.ToString().Split(cc1);//查找需抓取电池及位置
for (int i = 0; i < ng1.GetLength(0); i++)
{
string location = ng1[i].Split(cc2)[0];//需抓取电池
string locationnew = ng1[i].Split(cc2)[1];//对应位置
itemvalues[Convert.ToInt32(location) + 3].Remove(0, itemvalues[Convert.ToInt32(location) + 3].Length);
itemvalues[Convert.ToInt32(location) + 3].Append(Convert.ToInt32(locationnew) + 2);
}
}
}
CCommonOPCClient.Hostname = CommonClassLib.AppSettings.GetValue("HostName");//20090922 devinfo.RemoteIP;
CCommonOPCClient.ProgID = CommonClassLib.AppSettings.GetValue("OPCProgID");
CCommonOPCClient.PlcConnectionID = devinfo.S7Connection;//20110216
if (CCommonOPCClient.SyncWriteAllItemValue(itemnames, itemvalues) == false)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + CCommonOPCClient.OpcError;
return false;
}
itemnames[0].Remove(0, itemnames[0].Length);
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[0].Remove(0, itemvalues[0].Length);
itemvalues[0].Append(MessageIndex);
if (CCommonOPCClient.SyncWriteAllItemValue(itemnames, itemvalues) == false)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + CCommonOPCClient.OpcError;
return false;
}
sss.Remove(0, sss.Length);
sss.Append("条码:").Append(barcode).Append("**写标志").Append(MessageIndex.ToString()).Append("**命令字" + Order.ToString()).Append("**任务号" + TaskIndex.ToString()).Append("**异常信息").Append(ng.ToString());
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "发送指令", devinfo.DeviceIndex.ToString(), sss.ToString());
//if (MessageIndex == 1)
//{
// if (WriteBarcode(DeviceIndex, TaskIndex) == false)
// {
// return false;
// }
//}
return true;
}
catch (Exception ex)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + ex.Message + DeviceIndex.ToString();
return false;
}
finally
{
devinfo = null;
itemnames = null;
itemvalues = null;
};
}
public bool SendDeviceOrder(int MessageIndex, int TaskIndex, int Order, int DeviceIndex, int ArrowDeviceIndex,int type)
{
StringBuilder[] itemnames;
StringBuilder[] itemvalues;
devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIndex);
if (devinfo.XCoor == 0 && devinfo.YCoor == 0 && devinfo.DeviceKind == 4) return false;//20130510
string barcode = GetBarcodeFromMonitorIndex(TaskIndex);
try
{
//int nowdev = GetNowDevice(TaskIndex);
//if ((devinfo.DeviceKind == 13) && (nowdev != 0))
//{
// devinfo = Model.CGetInfo.GetDeviceInfo(nowdev);
//}
int[] sendmes = new int[5] { MessageIndex, TaskIndex, Order, DeviceIndex, ArrowDeviceIndex };
devinfo.SendMessage = sendmes;
Model.CGetInfo.SetDeviceMessage(devinfo);
int sn = 0;
if (devinfo == null)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:设备索引不存在!";
return false;
}
else
{
sn = Convert.ToInt32(devinfo.Dbw1Address);
itemnames = new StringBuilder[5] { new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder("") }; ;
itemvalues = new StringBuilder[5] { new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder(""), new StringBuilder("") }; ;
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[0].Append("0");
itemnames[1].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 1)).Append(",b");
itemvalues[1].Append(Order.ToString());
itemnames[2].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 2)).Append(",i");
itemvalues[2].Append(TaskIndex.ToString());
itemnames[3].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 4)).Append(",di");
itemvalues[3].Append(ArrowDeviceIndex.ToString());
itemnames[4].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 8)).Append(",b");
itemvalues[4].Append(type.ToString());
}
CCommonOPCClient.Hostname = CommonClassLib.AppSettings.GetValue("HostName");//20090922 devinfo.RemoteIP;
CCommonOPCClient.ProgID = CommonClassLib.AppSettings.GetValue("OPCProgID");
CCommonOPCClient.PlcConnectionID = devinfo.S7Connection;//20110216
if (CCommonOPCClient.SyncWriteAllItemValue(itemnames, itemvalues) == false)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + CCommonOPCClient.OpcError;
return false;
}
itemnames[0].Remove(0, itemnames[0].Length);
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[0].Remove(0, itemvalues[0].Length);
itemvalues[0].Append(MessageIndex);
if (CCommonOPCClient.SyncWriteAllItemValue(itemnames, itemvalues) == false)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + CCommonOPCClient.OpcError;
return false;
}
sss.Remove(0, sss.Length);
sss.Append("条码:").Append(barcode).Append("**写标志").Append(MessageIndex.ToString()).Append("**命令字" + Order.ToString()).Append("**任务号" + TaskIndex.ToString())
.Append("**目标位置" + ArrowDeviceIndex.ToString());
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "发送指令", devinfo.DeviceIndex.ToString(), sss.ToString());
//if (MessageIndex == 1)
//{
// if (WriteBarcode(DeviceIndex, TaskIndex) == false)
// {
// return false;
// }
//}
return true;
}
catch (Exception ex)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + ex.Message + DeviceIndex.ToString();
return false;
}
finally
{
devinfo = null;
itemnames = null;
itemvalues = null;
}
}
public bool SendDeviceOrder(int MessageIndex, int TaskIndex, int Order, int DeviceIndex, int ArrowDeviceIndex, int type,string barcode)
{
StringBuilder[] itemnames;
StringBuilder[] itemvalues;
devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIndex);
if (devinfo.XCoor == 0 && devinfo.YCoor == 0 && devinfo.DeviceKind == 4) return false;//20130510
try
{
//int nowdev = GetNowDevice(TaskIndex);
//if ((devinfo.DeviceKind == 13) && (nowdev != 0))
//{
// devinfo = Model.CGetInfo.GetDeviceInfo(nowdev);
//}
int[] sendmes = new int[5] { MessageIndex, TaskIndex, Order, DeviceIndex, ArrowDeviceIndex };
devinfo.SendMessage = sendmes;
Model.CGetInfo.SetDeviceMessage(devinfo);
int sn = 0;
if (devinfo == null)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:设备索引不存在!";
return false;
}
else
{
sn = Convert.ToInt32(devinfo.Dbw1Address);
itemnames = new StringBuilder[5+barcode.Length];
itemvalues = new StringBuilder[5+barcode.Length];
string str = barcode.Trim(); // 去掉字符串首尾处的空格
char[] charBuf = str.ToArray(); // 将字符串转换为字符数组
ASCIIEncoding charToASCII = new ASCIIEncoding();
byte[] TxdBuf = new byte[charBuf.Length]; // 定义发送缓冲区;
TxdBuf = charToASCII.GetBytes(charBuf);    // 转换为各字符对应的ASCII
for (int i = 0; i < (5+barcode.Length); i++)
{
itemnames[i] = new StringBuilder("");
itemvalues[i] = new StringBuilder("");
}
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[0].Append("0");
itemnames[1].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 1)).Append(",b");
itemvalues[1].Append(Order.ToString());
itemnames[2].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 2)).Append(",i");
itemvalues[2].Append(TaskIndex.ToString());
itemnames[3].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 4)).Append(",di");
itemvalues[3].Append(ArrowDeviceIndex.ToString());
itemnames[4].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 8)).Append(",b");
itemvalues[4].Append(type.ToString());
for (int i = 5; i < (5 + barcode.Length); i++)
{
itemnames[i].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + i+5)).Append(",b");
itemvalues[i].Append(TxdBuf[i-5]);
}
}
CCommonOPCClient.Hostname = CommonClassLib.AppSettings.GetValue("HostName");//20090922 devinfo.RemoteIP;
CCommonOPCClient.ProgID = CommonClassLib.AppSettings.GetValue("OPCProgID");
CCommonOPCClient.PlcConnectionID = devinfo.S7Connection;//20110216
if (CCommonOPCClient.SyncWriteAllItemValue(itemnames, itemvalues) == false)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + CCommonOPCClient.OpcError;
return false;
}
itemnames[0].Remove(0, itemnames[0].Length);
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[0].Remove(0, itemvalues[0].Length);
itemvalues[0].Append(MessageIndex);
if (CCommonOPCClient.SyncWriteAllItemValue(itemnames, itemvalues) == false)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + CCommonOPCClient.OpcError;
return false;
}
sss.Remove(0, sss.Length);
sss.Append("条码:").Append(barcode).Append("**写标志").Append(MessageIndex.ToString()).Append("**命令字" + Order.ToString()).Append("**任务号" + TaskIndex.ToString())
.Append("**目标位置" + ArrowDeviceIndex.ToString());
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "发送指令", devinfo.DeviceIndex.ToString(), sss.ToString());
//if (MessageIndex == 1)
//{
// if (WriteBarcode(DeviceIndex, TaskIndex) == false)
// {
// return false;
// }
//}
return true;
}
catch (Exception ex)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + ex.Message + DeviceIndex.ToString();
return false;
}
finally
{
devinfo = null;
itemnames = null;
itemvalues = null;
}
}
private void GetHMISendInfo(out int reSendFlag, out int HMISendDb1Address, int taskindex)
{//20120220
reSendFlag = 0;
HMISendDb1Address = 0;
try
{
DataView dv = dbo.ExceSQL(string.Format("SELECT F_NumParam2, F_SendFlag FROM T_Monitor_Task where F_MonitorIndex={0}", taskindex)).Tables[0].DefaultView;
if (dv.Count > 0)
{
reSendFlag = Convert.ToInt32(dv[0]["F_SendFlag"]);
HMISendDb1Address = Convert.ToInt32(dv[0]["F_NumParam2"]);//触摸屏F_DBW1Address
}
}
catch (Exception ex)
{
_commLayerError = "OPCClient.CSendDeviceOrder.GetHMISendInfo发生错误:" + ex.Message;
}
}
/// <summary>
/// 上位机给下位机发送烟箱按品牌码分道信息共15字节,有数据时写入实际数据,否则全部写零
/// </summary>
/// <param name="DeviceIndex">码垛位设备号索引</param>
/// <param name="TobaccoCode">第3--15字节,烟箱码</param>
/// <param name="HaveFirstProjectCode">第1字节,1-有一号工程码,0-无一号工程码</param>
/// <param name="IfSmallTobacco">第2字节,1-异型烟箱,0-正常烟箱</param>
/// <returns>发送烟箱按品牌码分道信息是否成功</returns>
public bool SendDeviceOrder(int DeviceIndex, string TobaccoCode, bool HaveFirstProjectCode, bool IfSmallTobacco, int Count)
{
StringBuilder[] itemnames = new StringBuilder[16];
StringBuilder[] itemvalues = new StringBuilder[16];
devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIndex);
try
{
int sn = 0;
if (devinfo == null)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:设备所引不存在!";
return false;
}
else
{
sn = Convert.ToInt32(devinfo.Dbw1Address);
itemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append((sn + 0).ToString()).Append(",b");
if (HaveFirstProjectCode == true)
{
itemvalues[0].Append("1");
}
else
{
itemvalues[0].Append("0");
}
itemnames[1].Append(Model.CGeneralFunction.DBSend).Append(".").Append((sn + 1).ToString()).Append(",b");
if (IfSmallTobacco == true)
{
itemvalues[1].Append("1");
}
else
{
itemvalues[1].Append("0");
}
for (int i = 2; i <= 14; i++)
{
itemnames[i].Append(Model.CGeneralFunction.DBSend).Append(".").Append((sn + i).ToString()).Append(",b");
itemvalues[i].Append(Strings.Asc(TobaccoCode.Substring(i - 2, 1)).ToString());
}
itemnames[15].Append(Model.CGeneralFunction.DBSend).Append(".").Append((sn + 15).ToString()).Append(",b");
itemvalues[15].Append(Count.ToString());
CCommonOPCClient.Hostname = CommonClassLib.AppSettings.GetValue("HostName");//20090922 devinfo.RemoteIP;
CCommonOPCClient.ProgID = CommonClassLib.AppSettings.GetValue("OPCProgID");
CCommonOPCClient.PlcConnectionID = devinfo.S7Connection;//20110216
if (CCommonOPCClient.SyncWriteAllItemValue(itemnames, itemvalues) == false)
{
return false;
}
}
return true;
}
catch (Exception ex)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + ex.Message;
return false;
}
finally
{
devinfo = null;
itemnames = null;
itemvalues = null;
}
}
public bool WriteBarcode(int deviceindex, int barcode)
{
Model.MDevice devinfo;
devinfo= Model.CGetInfo.GetDeviceInfo(deviceindex);
StringBuilder[] itemnames = new StringBuilder[9];
StringBuilder[] itemvalues = new StringBuilder[9];
for (int i = 0; i < 9; i++)
{
itemnames[i] = new StringBuilder("");
itemvalues[i] = new StringBuilder("");
}
int sn = 0;
try
{
sn = Convert.ToInt32(devinfo.Dbw2Address);
itemnames[0].Append(Model.CGeneralFunction.DBGet).Append(".").Append(Convert.ToString(sn )).Append(",b");
itemvalues[0].Append("0").ToString();
itemnames[1].Append(Model.CGeneralFunction.DBGet).Append(".").Append(Convert.ToString(sn+1)).Append(",b");
itemvalues[1].Append("1").ToString();
for (int i = 0; i < 7; i++)
{
itemnames[i+2].Append(Model.CGeneralFunction.DBGet).Append(".").Append(Convert.ToString(sn + i + 2)).Append(",b");
itemvalues[i+2].Append(Strings.Asc(barcode.ToString().Substring((i), 1)).ToString());
}
CCommonOPCClient.Hostname = CommonClassLib.AppSettings.GetValue("HostName");//20090922 devinfo.RemoteIP;
CCommonOPCClient.ProgID = CommonClassLib.AppSettings.GetValue("OPCProgID");
CCommonOPCClient.PlcConnectionID = devinfo.S7Connection;//20110216
if (CCommonOPCClient.SyncWriteAllItemValue(itemnames, itemvalues) == false)
{
return false;
}
itemnames[0].Remove(0, itemnames[0].Length);
itemnames[0].Append(Model.CGeneralFunction.DBGet).Append(".").Append(Convert.ToString(sn + 0)).Append(",b");
itemvalues[0].Remove(0, itemvalues[0].Length);
itemvalues[0].Append("1");
if (CCommonOPCClient.SyncWriteAllItemValue(itemnames, itemvalues) == false)
{
return false;
}
//CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "SendDeviceOrder", deviceindex.ToString(), sss.ToString());
return true;
}
catch (Exception ex)
{
_commLayerError = "OPCClient.CSendDeviceOrder.WriteBarcode发生错误:" + ex.Message;
return false;
}
finally
{
devinfo = null;
itemnames = null;
itemvalues = null;
}
}
public bool WriteGroupBarcode(int deviceindex, string GroupBarcode)
{
int BarcodeDevice = Convert.ToInt32(dbo.GetSingle("select F_DeviceIndex from T_Base_PLC_Ask where F_BindingDevice=" + deviceindex));
int BarcodeLenth= Convert.ToInt32(dbo.GetSingle("select F_PalletBarcodeLength from T_Base_PLC_Ask where F_BindingDevice=" + deviceindex));
string[] barcode = GroupBarcode.Split('|');
int count = barcode.GetLength(0);
Model.MDevice devinfo;
devinfo = Model.CGetInfo.GetDeviceInfo(BarcodeDevice);
StringBuilder[] itemnames = new StringBuilder[60];
StringBuilder[] itemvalues = new StringBuilder[60];
for (int i = 0; i < 60; i++)
{
itemnames[i] = new StringBuilder("");
itemvalues[i] = new StringBuilder("");
}
int sn = 0;
try
{
sn = Convert.ToInt32(devinfo.Dbw2Address);
for (int i = 0; i < 70; i++)
{
itemnames[i].Append(Model.CGeneralFunction.DBGet).Append(".").Append(Convert.ToString(sn+i)).Append(",b");
itemvalues[i].Append("0").ToString();
}
for (int i = 0; i < count; i++)
{
for (int j = 0; j < BarcodeLenth; j++)
{
itemvalues[(i + 1) * 10 + j].Clear();
itemvalues[(i + 1)*10+j].Append(Strings.Asc(barcode[i].ToString().Substring((j), 1)).ToString());
}
}
CCommonOPCClient.Hostname = CommonClassLib.AppSettings.GetValue("HostName");//20090922 devinfo.RemoteIP;
CCommonOPCClient.ProgID = CommonClassLib.AppSettings.GetValue("OPCProgID");
CCommonOPCClient.PlcConnectionID = devinfo.S7Connection;//20110216
if (CCommonOPCClient.SyncWriteAllItemValue(itemnames, itemvalues) == false)
{
return false;
}
//CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "SendDeviceOrder", deviceindex.ToString(), sss.ToString());
return true;
}
catch (Exception ex)
{
_commLayerError = "OPCClient.CSendDeviceOrder.WriteBarcode发生错误:" + ex.Message;
return false;
}
finally
{
devinfo = null;
itemnames = null;
itemvalues = null;
}
}
/// <summary>
/// 向PLC的DB区写入数据
/// </summary>
/// <param name="ItemNames">标签变量名称数组</param>
/// <param name="ItemValues">标签值数组</param>
/// <returns></returns>
public bool WriteDBData(StringBuilder[] ItemNames, StringBuilder[] ItemValues)
{
try
{
if (CCommonOPCClient.SyncWriteAllItemValue(ItemNames, ItemValues) == false)
{
return false;
}
else
{
sss.Remove(0, sss.Length);
sss.Append("**" + ItemNames[0].ToString() + "**" + ItemValues[0].ToString());
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "发送应答标志", "----", sss.ToString());
return true;
}
}
catch (Exception ex)
{
_commLayerError = "OPCClient.CSendDeviceOrder.WriteDBData发生错误:" + ex.Message;
return false;
}
finally
{
ItemNames = null;
ItemValues = null;
}
}
public bool WriteDBData(StringBuilder[] ItemNames, StringBuilder[] ItemValues, string PLCconnectionID)
{
try
{
CCommonOPCClient.Hostname = CommonClassLib.AppSettings.GetValue("HostName");//20090922 devinfo.RemoteIP;
CCommonOPCClient.ProgID = CommonClassLib.AppSettings.GetValue("OPCProgID");
CCommonOPCClient.PlcConnectionID = PLCconnectionID;
if (CCommonOPCClient.SyncWriteAllItemValue(ItemNames, ItemValues) == false)
{
return false;
}
else
{
sss.Remove(0, sss.Length);
for (int i = 0; i < ItemNames.Length; i++)
{
sss.Append("**" + ItemNames[i].ToString() + "**" + ItemValues[i].ToString());
}
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "发送应答标志", "----", sss.ToString());
return true;
}
}
catch (Exception ex)
{
_commLayerError = "OPCClient.CSendDeviceOrder.WriteDBData发生错误:" + ex.Message;
return false;
}
finally
{
ItemNames = null;
ItemValues = null;
}
}
string GetBarcodeFromMonitorIndex(int taskindex)
{
sss.Remove(0, sss.Length);
sss.Append("SELECT F_TxtParam FROM T_Monitor_Task WHERE (F_MonitorIndex = ").Append(taskindex).Append(")");
DataView dvb = dbo.ExceSQL(sss.ToString()).Tables[0].DefaultView;
if (dvb.Count > 0)
{
return dvb[0]["F_TxtParam"].ToString();
}
else
{
return "-";
}
}
int GetNowDevice(int taskindex)
{
sss.Remove(0, sss.Length);
sss.Append("SELECT F_NumParam1 FROM T_Monitor_Task WHERE (F_MonitorIndex = ").Append(taskindex).Append(")");
DataView dvb = dbo.ExceSQL(sss.ToString()).Tables[0].DefaultView;
if (dvb.Count > 0)
{
return Convert.ToInt32(dvb[0]["F_NumParam1"]);
}
else
{
return 0;
}
}
int IfInworkBench(int taskindex)
{
int fid = Model.CGeneralFunction.GetManageTaskIndexfromMonitor(taskindex);
int mti = Model.CGeneralFunction.GetManageTaskKindIndexFromMonitor(taskindex);
object ob = dbo.GetSingle(string.Format("SELECT WORK_MODE FROM T_Manage_Task WHERE (F_ManageTaskKindIndex = {0}) AND (FID = {1})", mti, fid));
if (ob != null)
{
return Convert.ToInt32(ob);
}
else
{
return 2;
}
}
List<int> GetNextDevice(int CurRouteIDSub, int CurSerialNumber)
{
List<int> keyDevice = new List<int>(); DataView dvRoute;
try
{
//然后依次判断后续设备最近的设备
sql.Remove(0, sql.Length);
sql.Append("SELECT T_Base_Route_Device.F_DeviceIndex,F_DeviceOrder, T_Base_Route_Device.F_SerialNumber, ").Append(
"T_Base_Device_Command.F_DeviceCommandIndex,T_Base_Device.F_DeviceKindIndex FROM T_Base_Device_Command ").Append(
",T_Base_Device,T_Base_Route_Device where T_Base_Device_Command.F_DeviceKindIndex = T_Base_Device.F_DeviceKindIndex").Append(
" and T_Base_Device.F_DeviceIndex = T_Base_Route_Device.F_DeviceIndex and F_RouteIDSub=").Append(
CurRouteIDSub).Append(" and F_SerialNumber > ").Append(CurSerialNumber).Append(" order by F_SerialNumber asc ");
dvRoute = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvRoute.Count > 0)
{
keyDevice.Add(Convert.ToInt32(dvRoute[0]["F_DeviceIndex"]));
keyDevice.Add(Convert.ToInt32(dvRoute[0]["F_DeviceKindIndex"]));
keyDevice.Add(Convert.ToInt32(dvRoute[0]["F_SerialNumber"]));
keyDevice.Add(Convert.ToInt32(dvRoute[0]["F_DeviceOrder"]));
}
return keyDevice;
}
catch (Exception ex)
{
_commLayerError = "OPCClient.CSendDeviceOrder.GetNextDevice:" + ex.Message;
return null;
}
finally
{
keyDevice = null;
dvRoute = null;
}
}
int GetNextDeviceFromTaskDevice(int TaskIndex, int DeviceIndex)
{//20111226
int RouteIDSub = 0; int sn = 0;
DataView dv = dbo.ExceSQL(string.Format("SELECT F_RouteID FROM T_Monitor_Task WHERE (F_MonitorIndex = {0})", TaskIndex)).Tables[0].DefaultView;
if (dv.Count > 0)
{
RouteIDSub = Convert.ToInt32(dv[0][0]);
}
else
{
return -1;
}
try
{
//20101124
sql.Remove(0, sql.Length);
sql.Append("SELECT F_SerialNumber FROM T_Base_Route_Device WHERE (F_RouteIDSub = ").Append(RouteIDSub).Append(") AND (F_DeviceIndex = ").Append(DeviceIndex).Append(")");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
sn = (int)dv[0]["F_SerialNumber"];
List<int> nd = GetNextDevice(RouteIDSub, sn);
if (nd != null)
{
return nd[0];
}
else
{
return -1;
}
}
else
{
return -1;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv = null;
}
}
/// <summary>
/// 根据堆垛机坐标获得(是双叉对等关联站台的)站台设备索引
/// </summary>
/// <param name="stackdeviceindex"></param>
/// <param name="stackzxy"></param>
/// <returns></returns>
int GetDeviceLaneGateInfoFromStackCoor(int stackdeviceindex, string stackzxy, out int useawayfork)
{
devinfo = Model.CGetInfo.GetDeviceInfo(stackdeviceindex);
if (devinfo != null)
{
if (devinfo.VirtualStack > 0)
{
stackdeviceindex = devinfo.VirtualStack;
}
}
int laneway = 0; useawayfork = 0;
DataView dvl = dbo.ExceSQL(string.Format("SELECT F_LaneDeviceIndex FROM T_Base_LaneInfo WHERE (F_StackIndex = {0})", stackdeviceindex)).Tables[0].DefaultView;
if (dvl.Count > 0)
{
laneway = Convert.ToInt32(dvl[0][0]);
}
else
{
return -1;
}
sql.Remove(0, sql.Length);
sql.Append("SELECT F_LaneGateDeviceIndex,F_UseAwayFork FROM T_Base_Lane_Gate where F_CorrelDeviceIndex<>'' and (F_LaneIndex=").Append(laneway).Append(" and T_Base_Lane_Gate.F_ZXY = '").Append(stackzxy).Append("')");
DataView dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
useawayfork = Convert.ToInt32(dv[0]["F_UseAwayFork"]);
return Convert.ToInt32(dv[0]["F_LaneGateDeviceIndex"]);
}
return -1;
}
bool SetLaneGateReplace(int mti, int fid, int DeviceIndex, int TaskIndex, int UseAwayFork)
{//20120820
//201112231同时考虑调整路径所选站台和提前检测有问题
if (UseAwayFork > 0)
{
int[] zxy = GetCoordinatesFromMonitorTask(TaskIndex);
StringBuilder zxystr = new StringBuilder();
if (zxy != null)
{
zxystr.Append((zxy[3].ToString().Length == 1 ? "0" + zxy[3].ToString() : zxy[3].ToString())).Append("-").Append(
((zxy[4].ToString().Length == 1) ? ("0" + zxy[4].ToString()) : (zxy[4].ToString()))).Append("-").Append(
((zxy[5].ToString().Length == 1) ? ("0" + zxy[5].ToString()) : (zxy[5].ToString())));
}
int LaneGateDevice = 0; int oldawayfork = 0;
int oNextDevice = GetDeviceLaneGateInfoFromStackCoor(DeviceIndex, zxystr.ToString(), out oldawayfork);
if (oNextDevice > 0)
{
int n5 = zxy[4]; //Convert.ToInt32(sp[1]);
if (UseAwayFork == oldawayfork)
{
//不调整
return false;//20120217
}
else
{
//堆垛机的原点属性
char[] cc = new char[1] { ',' };
string[] lc = devinfo.StackZeroColLayer.Split(cc);
if (Convert.ToInt32(lc[0]) < n5)//正常情况,货叉顺序号和列顺序号相同
{
n5 = n5 + (UseAwayFork - oldawayfork);
}
else
{//双堆垛机的原点在最大列的货叉顺序号和列顺序号相反
n5 = n5 - (UseAwayFork - oldawayfork);
}
zxystr.Clear();
zxystr.Append((zxy[3].ToString().Length == 1 ? "0" + zxy[3].ToString() : zxy[3].ToString())).Append("-").Append(
((n5.ToString().Length == 1) ? ("0" + n5.ToString()) : (n5.ToString()))).Append("-").Append(
((zxy[5].ToString().Length == 1) ? ("0" + zxy[5].ToString()) : (zxy[5].ToString())));
LaneGateDevice = GetDeviceLaneGateInfoFromStackCoor(DeviceIndex, zxystr.ToString(), out oldawayfork);
//替换路径
//修改堆垛机提前检测,RunLock
sql.Clear();
sql.Append("UPDATE T_Monitor_Task SET F_RunningLock='").Append(LaneGateDevice).Append("', F_AheadDetect=Replace(F_AheadDetect,'").Append(oNextDevice).Append("','").Append(LaneGateDevice).Append("') WHERE (F_ManageTaskIndex = ")
.Append(fid).Append(") AND (F_ManageTASKKINDINDEX = ")
.Append(mti).Append(") AND F_DeviceIndex = ").Append(DeviceIndex);
dbo.ExecuteSql(sql.ToString());
//修改堆垛机送货坐标
sql.Clear();
sql.Append("UPDATE T_Monitor_Task SET F_NumParam5=").Append(n5).Append(" WHERE (F_ManageTaskIndex = ")
.Append(fid).Append(") AND (F_ManageTASKKINDINDEX = ")
.Append(mti).Append(")").Append(" AND F_DeviceIndex = ").Append(DeviceIndex);
dbo.ExecuteSql(sql.ToString());
//修改输送机,提前检测,RunLock,F_NumParam1
sql.Clear();
sql.Append("UPDATE T_Monitor_Task SET F_RouteID=").Append(GetRouteIDsub(LaneGateDevice)).Append(",F_DeviceIndex=").Append(LaneGateDevice).Append(", F_NumParam1=").Append(LaneGateDevice).Append(", F_RunningLock='").Append(LaneGateDevice).Append("', F_AheadDetect=Replace(F_AheadDetect,'").Append(oNextDevice).Append("','").Append(LaneGateDevice).Append("') WHERE (F_ManageTaskIndex = ")
.Append(fid).Append(") AND (F_ManageTASKKINDINDEX = ")
.Append(mti).Append(") AND F_DeviceIndex = ").Append(oNextDevice);
dbo.ExecuteSql(sql.ToString());
return true;//20120217
}
}
else
{
return false;
}
}
else
{
return false;//20120217
}
}
int GetGoodsHigh(int taskindex)
{
DataView dv = dbo.ExceSQL(string.Format("SELECT CELL_MODEL FROM T_Manage_Task WHERE (F_ManageTaskKindIndex = {0}) AND (FID = {1})", Model.CGeneralFunction.GetManageTaskKindIndexFromMonitor(taskindex), Model.CGeneralFunction.GetManageTaskIndexfromMonitor(taskindex))).Tables[0].DefaultView;
if (dv.Count > 0)
{
int gh = 1;
//P工装板,B标准,G高货位,D大货位
switch (dv[0][0].ToString().ToUpper())
{
case "P":
gh = 3;
break;
case "B":
gh = 2;
break;
case "G":
gh = 1;
break;
//case "D":
// gh = 4;
// break;
default:
gh = 1;
break;
}
return gh;
}
else
{
return 1;
}
}
int MinRouteID(int startdevice, int enddevice, int nowdevice, object useAwayfork)
{
try
{
StringBuilder dff = new StringBuilder();
if (useAwayfork.ToString() == "-")
{
dff.Append("F_UseAwayFork<>'n'");
}
else
{
dff.Append("(F_UseAwayFork='").Append(useAwayfork).Append("' or F_UseAwayFork='-' )");//20101028
}
//选择最短调度路径并且判断此路径上是否有设备发生故障
//20101124
sql.Remove(0, sql.Length);
sql.Append("SELECT distinct(T_Base_Route_Device.F_RouteIDSub) FROM T_Base_Device,T_Base_Route_Device,").Append(
"T_Base_Route where T_Base_Route_Device.F_RouteID = T_Base_Route.F_RouteID and ").Append(
" T_Base_Route_Device.F_DeviceIndex = T_Base_Device.F_DeviceIndex and ").Append(
" F_StartDevice=").Append(startdevice).Append(" and F_EndDevice=").Append(enddevice).Append(" and F_Status=1 and T_Base_Device.F_DeviceIndex =").Append(nowdevice).Append(" and ").Append(dff.ToString());
DataView dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
List<double> minroute = new List<double>();//0,routIDSub;1,路径最小值
if (dv.Count == 0)
{
//RefreshMonitorEventArgs rme = new RefreshMonitorEventArgs("tsStatus", "起点设备:" + startdevice + "和终点设备:" + enddevice + "之间路径不可用!");
//OnRefreshMonitor(rme);
return -1;
}
for (int i = 0; i < dv.Count; i++)
{
//20101124
sql.Remove(0, sql.Length);
sql.Append("SELECT F_RouteIDSub, F_LockedState FROM T_Base_Device,T_Base_Route_Device WHERE ").Append(
" T_Base_Device.F_DeviceIndex = T_Base_Route_Device.F_DeviceIndex and (T_Base_Route_Device.F_RouteIDSub = ").Append(
dv[i]["F_RouteIDSub"]).Append(") AND (T_Base_Device.F_LockedState = - 1)");
DataView dvd = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvd.Count > 0)
{
continue;
}
List<double> route = new List<double>();//0,routIDSub;1,步长;2,路径使用频率;3,路径设备任务数
//路径步长(设备总数)最短(权重0.3),路径使用频率最小(权重0.3)的路径,路径设备任务数(权重0.3)
route.Add(Convert.ToDouble(dv[i]["F_RouteIDSub"]));//RouteIDSub
//20101124
sql.Remove(0, sql.Length);
sql.Append("select count(F_DeviceIndex) as steps from T_Base_Route_Device where F_RouteIDSub="
).Append(dv[i]["F_RouteIDSub"]);
DataView dv1 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv1.Count > 0)
{
route.Add(Convert.ToDouble(dv1[0]["steps"]));//步长
//route.Add(0);
}
else
{
continue;
}
//路径使用频率:路径执行调度任务的数量
//20101124
sql.Remove(0, sql.Length);
sql.Append("SELECT COUNT(DISTINCT F_ManageTaskIndex) AS ManCount FROM T_Monitor_Task GROUP BY F_RouteID HAVING (F_RouteID = ").Append(dv[i]["F_RouteIDSub"]).Append(")");
DataView dv2 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv2.Count > 0)
{
double a = 0;
if (double.TryParse(dv2[0]["ManCount"].ToString(), out a) == true)
{
route.Add(Convert.ToDouble(dv2[0]["ManCount"]));//路径使用频率
}
else
{
route.Add(0);//路径使用频率
}
}
else
{
route.Add(0);//路径使用频率
}
//路径设备任务数
//20101124
sql.Remove(0, sql.Length);
sql.Append("SELECT COUNT(T_Monitor_Task.F_MonitorIndex) AS mtask FROM T_Monitor_Task ,T_Base_Route_Device where (T_Monitor_Task.F_DeviceIndex = T_Base_Route_Device.F_DeviceIndex) and (T_Base_Route_Device.F_RouteIDSub = ").Append(dv[i]["F_RouteIDSub"]).Append(")");
dv2 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv2.Count > 0)
{
double a = 0;
if (double.TryParse(dv2[0]["mtask"].ToString(), out a) == true)
{
route.Add(Convert.ToDouble(dv2[0]["mtask"]));//路径设备任务数
}
else
{
route.Add(0);//路径设备任务数
}
}
else
{
route.Add(0);//路径设备任务数
}
//求最短路径((路径步长*0.3+路径使用频率*0.3+设备占有数*0.3)的最小值)
if (minroute.Count == 0)
{
minroute.Add(route[0]);
minroute.Add(route[1] * 0.3 + route[2] * 0.3 + route[3] * 0.3);
}
else
{
if (minroute[1] > (route[1] * 0.3 + route[2] * 0.3 + route[3] * 0.3))
{
minroute[0] = route[0];
minroute[1] = (route[1] * 0.3 + route[2] * 0.3 + route[3] * 0.3);
}
}
}
if (minroute.Count > 0)
{
return Convert.ToInt32(minroute[0]);
}
else
{
return -1;
}
}
catch (Exception ex)
{
_commLayerError = "OPCClient.CSendDeviceOrder.MinRouteID时发生错误:" + ex.Message;
return -1;
}
}
int GetRouteIDsub(int device)
{
DataView dv = dbo.ExceSQL("SELECT F_RouteIDSub, F_DeviceIndex, F_RouteID FROM T_Base_Route_Device where F_DeviceIndex=" + device + "").Tables[0].DefaultView;
if (dv.Count > 0)
{
return Convert.ToInt32(dv[0]["F_RouteIDSub"]);
}
else
{
return -1;
}
}
int[] GetCoordinatesFromMonitorTask(int TaskIdx)
{
//20100108
DataView dv;
int[] gc;
try
{
//20101124
sql.Remove(0, sql.Length);
sql.Append("select F_NumParam1,F_NumParam2,F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 from T_Monitor_Task where F_MonitorIndex=").Append(TaskIdx);
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
gc = new int[6];
//F_NumParam1--z,x--2,y--3;F_NumParam4--z,5--x,6--y
if (dv.Count > 0)
{
gc[0] = Convert.ToInt32(dv[0]["F_NumParam1"]);
gc[1] = Convert.ToInt32(dv[0]["F_NumParam2"]);
gc[2] = Convert.ToInt32(dv[0]["F_NumParam3"]);
gc[3] = Convert.ToInt32(dv[0]["F_NumParam4"]);
gc[4] = Convert.ToInt32(dv[0]["F_NumParam5"]);
gc[5] = Convert.ToInt32(dv[0]["F_NumParam6"]);
return gc;
}
return null;
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv = null;
gc = null;
}
}
string GetUseAwayForkFromLaneGate(int device)
{
DataView dv = dbo.ExceSQL(string.Format("SELECT F_UseAwayFork FROM T_Base_Lane_Gate where F_LaneGateDeviceIndex={0}", device)).Tables[0].DefaultView;
if (dv.Count > 0)
{
return dv[0][0].ToString();
}
else
{
return "-";
}
}
public bool SetWorkMode(int dev, int mode)
{
Model.MDevice devinfo;
StringBuilder[] wv = new StringBuilder[2] { new StringBuilder(""), new StringBuilder("") };
StringBuilder[] witemnames = new StringBuilder[2] { new StringBuilder(""), new StringBuilder("") };
devinfo = Model.CGetInfo.GetDeviceInfo(dev);
int sn = Convert.ToInt32(devinfo.Dbw1Address);
witemnames[0].Remove(0, witemnames[0].Length);
//witemnames[0].Append(Model.CGeneralFunction.DBSend).Append(",b,").Append(Convert.ToString(devinfo.Dbw1Address + 0));
witemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(devinfo.Dbw1Address + 0)).Append(",b");
witemnames[1].Remove(0, witemnames[1].Length);
witemnames[0].Append(Model.CGeneralFunction.DBSend).Append(".").Append(Convert.ToString(devinfo.Dbw1Address + 1)).Append(",b");
wv[0].Remove(0, wv[0].Length);
wv[0].Append("1");
wv[1].Remove(0, wv[1].Length);
wv[1].Append(mode.ToString());
//CCommonOPCClient.Hostname = CommonClassLib.AppSettings.GetValue("HostName");//20090922 devinfo.RemoteIP;
//CCommonOPCClient.ProgID = CommonClassLib.AppSettings.GetValue("OPCProgID");
//CCommonOPCClient.PlcConnectionID = devinfo.S7Connection;//20110216
//if (CCommonOPCClient.SyncWriteAllItemValue(witemnames, wv) == false)
//{
// _commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + CCommonOPCClient.OpcError;
// return false;
//}
//else
//{
// return true;
//}
if (WriteDBData(witemnames, wv, devinfo.S7Connection) == false)
{
_commLayerError = "OPCClient.CSendDeviceOrder.SendDeviceOrder发生错误:" + CCommonOPCClient.OpcError;
return false;
}
else
{
return true;
}
}
}
}