668 lines
33 KiB
C#
668 lines
33 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Text;
|
||
using DBFactory;
|
||
using ICommLayer;
|
||
using System.Data;
|
||
using Microsoft.VisualBasic;
|
||
namespace SimensProdave6
|
||
{
|
||
public class CGetDeviceState:IGetDeviceState
|
||
{
|
||
string _commLayerError;
|
||
|
||
public string CommLayerError
|
||
{
|
||
get { return _commLayerError; }
|
||
set { _commLayerError = value; }
|
||
}
|
||
DBOperator dbo = CSimensProdave6_S7.dbo;
|
||
public CGetDeviceState()
|
||
{
|
||
dbo.Open();
|
||
}
|
||
/// <summary>
|
||
///1、下位机给上位机发送设备(任务)状态信息
|
||
///检测开关: 0-无货1-有货
|
||
///确认按钮:
|
||
///第1字节:
|
||
///一个变化的值,每确认一次,该值变化一次,以标志一个
|
||
///新的确认消息。例如可以是0、1交替变化,也可以是递
|
||
///增变化。
|
||
///第2字节:
|
||
///1-无货确认
|
||
///2-有货确认
|
||
///其他设备:
|
||
///第1字 节:设备状态
|
||
///堆垛机:0-空闲
|
||
///1-正在运行
|
||
///2-任务完成
|
||
///3-要求调度重发命令
|
||
///4-通知调度取消当前任务
|
||
///其它值表示错误
|
||
/// 穿梭车:
|
||
/// 0-空闲
|
||
/// 1-正在运行
|
||
/// 2-完成
|
||
/// 3-要求调度重发命令
|
||
/// 4-通知调度取消当前任务
|
||
/// 其它值表示错误
|
||
/// 输送机:
|
||
/// 0-空闲
|
||
/// 1-正在运行
|
||
/// 2-完成(只有PC下发的目标设备才允许汇报完成)
|
||
/// 组合机构需要单独定义状态
|
||
/// 其它值表示错误
|
||
/// 第2、3字节: 任务号,即上位机下达任务时的任务号
|
||
/// 第4、5、6、7字节
|
||
/// 堆垛机、穿梭车:
|
||
/// 终点X坐标(沿轨道方向)
|
||
/// (第8字节以后部分只对堆垛机有意义)
|
||
/// 第8、9、10、11字节
|
||
/// 终点Y坐标(沿高度方向)
|
||
///
|
||
/// 2.下位机给上位机发送条码信息
|
||
/// 托盘条码:
|
||
/// 第1-10字节:由左到右依次存放托盘上的10位条形码信息
|
||
/// 烟箱一号工程码:
|
||
/// 第1-9字节: 由左到右依次存放烟箱上的后9位一号工程码信息
|
||
/// 一号工程码是32位,相同品牌烟箱的一号工程码的前23位相同,
|
||
/// 所以只存放后9位条码。每个码垛位进烟口有两个烟箱一号工程码存放区,
|
||
/// 共18个字节,上位机一次将两个烟箱一号工程码的信息同时读取。
|
||
/// 上位机成功读取18个字节后,把这18个字节全部写入零,
|
||
/// 下位机只有检测到18个字节全都是零时才可以写入新的一号工程码信息。
|
||
///
|
||
/// 3.下位机给上位机发送现场控制触摸屏申请信号
|
||
/// 第1字节 申请指令
|
||
/// 1- 重发当前设备指令
|
||
/// 2- 申请修改当前设备所执行任务的目标位置
|
||
/// 第2、3字节 设备索引(当前申请设备的索引)
|
||
/// 第4、5字节 任务号(需要修改目标位置的任务号)
|
||
/// 第6、15字节 托盘条码(当前申请设备上的托盘的条码)
|
||
/// 下位机可能因开关误动作等情况而引起任务记忆丢失,
|
||
/// 此时根据设备上停放托盘的条码可以重新申请获得任务。
|
||
/// 上位机收到此申请后重新发送当前设备的指令。
|
||
/// 有设备发生故障时,下位机可以申请修改任务的目标位置。
|
||
/// 上位机收到此申请后,如果可以找到新的路径,则修改此任务号的目标位置。
|
||
/// 当申请指令为1时,任务号可以是任意值;当申请指令为2时,托盘条码可以是任意值。
|
||
/// </summary>
|
||
/// <param name="DeviceIndex">设备编号</param>
|
||
/// <returns>获得上行消息成功后,发送应答消息后返回22个字的状态</returns>
|
||
public int[] GetDeviceState(int DeviceIndex, int TaskIndex)
|
||
{
|
||
try
|
||
{
|
||
int[] _Rword = new int[20];
|
||
byte[] _RRword;
|
||
int add = 0;
|
||
int Bit = 0;
|
||
//int isn=0;
|
||
Model.MDevice devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIndex);
|
||
//DataView dv = dbo.ExceSQL("SELECT F_DBW2Address,F_DBWGetLength,F_DeviceIndex,F_DeviceKindIndex,F_OPCProgID, F_RemoteIP FROM T_Base_Device where F_DeviceIndex=" + DeviceIndex).Tables[0].DefaultView;
|
||
if (devinfo.DeviceIndex== 0)
|
||
{
|
||
_commLayerError = "SimensProdave6.CGetDeviceState.GetDeviceState发生错误:在设备表中没找到设备所引!";
|
||
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
|
||
switch (devinfo.DeviceKind.ToString())
|
||
{
|
||
#region 光电开关总的采集
|
||
case "28":
|
||
_RRword = CSimensProdave6_S7.DB_Read_Prodave(0, 2, Convert.ToUInt16( devinfo.Dbw2Address), Convert.ToUInt32( devinfo.Dbw2Getlength));
|
||
if (_RRword == null)
|
||
{
|
||
_commLayerError = "SimensProdave6.CGetDeviceState.GetDeviceState发生错误:" + CSimensProdave6_S7.ErrorsText;
|
||
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
int[] rrr=new int[Convert.ToInt32( devinfo.Dbw2Getlength)];
|
||
Array.Copy(_RRword, rrr,Convert.ToInt32( devinfo.Dbw2Getlength));
|
||
return rrr;
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region 光电开关
|
||
case "18":
|
||
Bit = Convert.ToInt16(Convert.ToDecimal(devinfo.Dbw2Getlength) * 8) - 1;//转换成bit0--bit7
|
||
if (Bit > 7)
|
||
{
|
||
add = 1;
|
||
Bit = Bit - 8;
|
||
}
|
||
else
|
||
{
|
||
add = 0;
|
||
}
|
||
_RRword = CSimensProdave6_S7.DB_Read_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address + add), 1, Bit);
|
||
if (_RRword == null)
|
||
{
|
||
_commLayerError = "SimensProdave6.CGetDeviceState.GetDeviceState发生错误:" + CSimensProdave6_S7.ErrorsText;
|
||
|
||
return null;
|
||
}
|
||
_Rword[0] = _RRword[0];
|
||
|
||
_Rword[1] = 3;//3-检测开关状态
|
||
_Rword[2] = TaskIndex;//任务号
|
||
_Rword[3] = 0;
|
||
_Rword[4] = 0;
|
||
_Rword[5] = DeviceIndex;//设备号索引
|
||
|
||
break;
|
||
#endregion
|
||
|
||
#region 按钮
|
||
case "14":
|
||
Bit = Convert.ToInt16(devinfo.Dbw2Getlength * 8) - 1;//转换成bit0--bit7
|
||
if (Bit > 7)
|
||
{
|
||
add = 1;
|
||
Bit = Bit - 8;
|
||
}
|
||
else
|
||
{
|
||
add = 0;
|
||
}
|
||
_RRword = CSimensProdave6_S7.DB_Read_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address + add), 1, Bit);
|
||
if (_RRword == null)
|
||
{
|
||
_commLayerError = "SimensProdave6.CGetDeviceState.GetDeviceState发生错误:" + CSimensProdave6_S7.ErrorsText;
|
||
|
||
return null;
|
||
}
|
||
_Rword[0] = _RRword[0];
|
||
|
||
_Rword[1] = 3;//3-检测开关状态
|
||
_Rword[2] = TaskIndex;//任务号
|
||
_Rword[3] = 0;
|
||
_Rword[4] = 0;
|
||
_Rword[5] = DeviceIndex;//设备号索引
|
||
|
||
break;
|
||
#endregion
|
||
|
||
#region 现场控制触摸屏申请信息(16个字节)
|
||
case "22":
|
||
_RRword = CSimensProdave6_S7.DB_Read_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address), Convert.ToUInt32(devinfo.Dbw2Getlength));
|
||
if (_RRword == null)
|
||
{
|
||
_commLayerError = "SimensProdave6.CGetDeviceState.GetDeviceState发生错误:" + CSimensProdave6_S7.ErrorsText;
|
||
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
_Rword[0] = TaskIndex;
|
||
_Rword[1] = DeviceIndex;
|
||
_Rword[2] = _RRword[1];
|
||
_Rword[3]=(_RRword[2] << 8) + _RRword[3];
|
||
_Rword[4] = (_RRword[4] << 8) + _RRword[5];
|
||
}
|
||
//_Rword[2];//命令字
|
||
//_Rword[3];//设备索引(当前申请设备的索引)
|
||
//_Rword[4];//任务号(需要修改目标位置的任务号)
|
||
int bcz = 0;
|
||
byte[] www = new byte[1];
|
||
string barcode = string.Empty;
|
||
for (int j = 6; j <= 15; j++)
|
||
{
|
||
bcz = bcz + _RRword[j];
|
||
barcode = barcode += Convert.ToChar(_RRword[j]);
|
||
}
|
||
#region 申请重发当前设备指令(1)
|
||
|
||
if (_Rword[2] == 1)//命令字
|
||
{
|
||
if (_Rword[4] == 0)//无任务号
|
||
{
|
||
if (bcz == 0)//无条码号
|
||
{
|
||
//32申请的任务号和条形码都不存在
|
||
www[0]=32;
|
||
CSimensProdave6_S7.DB_Write_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address), 1, www);
|
||
return null;
|
||
}
|
||
else//有条码号
|
||
{
|
||
#region 有条码号
|
||
//DataView dv = dbo.ExceSQL("SELECT F_BarCode, F_Askkind, F_DeviceIndex FROM T_Base_PLC_Ask where F_DeviceIndex=" + DeviceIndex).Tables[0].DefaultView;
|
||
//if (dv.Count > 0)
|
||
//{
|
||
// if (barcode == dv[i]["F_BarCode"].ToString())
|
||
// {
|
||
// return null;
|
||
// }
|
||
// else
|
||
// {
|
||
DataView dvbc = dbo.ExceSQL("SELECT F_MonitorIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2," +
|
||
"F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_TxtParam = '" +
|
||
barcode + "' and F_DeviceIndex="+_Rword[3]+" order by F_MonitorIndex asc").Tables[0].DefaultView;
|
||
if (dvbc.Count > 0)
|
||
{
|
||
|
||
|
||
www[0]=4;
|
||
CSimensProdave6_S7.DB_Write_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address), 1, www);
|
||
return _Rword;
|
||
}
|
||
else
|
||
{
|
||
//35申请的设备号和条形码不匹配
|
||
www[0]=35 ;
|
||
CSimensProdave6_S7.DB_Write_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address), 1, www);
|
||
return null;
|
||
}
|
||
// }
|
||
//}
|
||
#endregion
|
||
}
|
||
}
|
||
else//有任务号
|
||
{
|
||
#region 有任务号
|
||
//DataView dv = dbo.ExceSQL("SELECT F_TaskIndex, F_Askkind, F_DeviceIndex FROM T_Base_PLC_Ask where F_DeviceIndex=" + DeviceIndex).Tables[0].DefaultView;
|
||
//if (dv.Count > 0)
|
||
//{
|
||
// if (_Rword[4] == dv[i]["F_TaskIndex"].ToString())
|
||
// {
|
||
// return null;
|
||
// }
|
||
// else
|
||
// {
|
||
DataView dvbc = dbo.ExceSQL("SELECT F_MonitorIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2," +
|
||
"F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_MonitorIndex = '" +
|
||
_Rword[4] + "' and F_DeviceIndex=" + _Rword[3] + " order by F_MonitorIndex asc").Tables[0].DefaultView;
|
||
if (dvbc.Count > 0)
|
||
{
|
||
|
||
//RestoreDevice(Convert.ToInt32(dvbc[0]["F_MonitorIndex"]));
|
||
www[0]= 4 ;
|
||
CSimensProdave6_S7.DB_Write_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address), 1, www);
|
||
////记录任务号
|
||
//dbo.ExceSQL("update T_Base_PLC_Ask set F_TaskIndex='" + _Rword[4]
|
||
// + "' where F_DeviceIndex=" + DeviceIndex);
|
||
return _Rword;
|
||
}
|
||
else
|
||
{
|
||
//36申请的设备号和任务号不匹配
|
||
www[0]= 36;
|
||
CSimensProdave6_S7.DB_Write_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address), 1, www);
|
||
return null;
|
||
}
|
||
// }
|
||
//}
|
||
#endregion
|
||
}
|
||
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 申请修改当前设备所执行任务目标位置(2)
|
||
|
||
else if (_Rword[2] == 2)//命令字
|
||
{
|
||
//申请修改当前设备所执行任务目标位置的F_TaskIndex重复时不允许相应申请
|
||
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 上报完成(3)
|
||
else if (_Rword[2] == 3)//命令字
|
||
{
|
||
#region 有任务号
|
||
//DataView dv = dbo.ExceSQL("SELECT F_TaskIndex, F_Askkind, F_DeviceIndex FROM T_Base_PLC_Ask where F_DeviceIndex=" + DeviceIndex).Tables[0].DefaultView;
|
||
//if (dv.Count > 0)
|
||
//{
|
||
// if (_Rword[4] == dv[i]["F_TaskIndex"].ToString())
|
||
// {
|
||
// return null;
|
||
// }
|
||
// else
|
||
// {
|
||
DataView dvbc = dbo.ExceSQL("SELECT F_MonitorIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2," +
|
||
"F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_MonitorIndex = '" +
|
||
_Rword[4] + "' and F_DeviceIndex=" + _Rword[3] + " order by F_MonitorIndex asc").Tables[0].DefaultView;
|
||
if (dvbc.Count > 0)
|
||
{
|
||
www[0]=2;
|
||
CSimensProdave6_S7.DB_Write_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address), 1, www);
|
||
////记录任务号
|
||
//dbo.ExceSQL("update T_Base_PLC_Ask set F_TaskIndex='" + _Rword[4]
|
||
// + "' where F_DeviceIndex=" + DeviceIndex);
|
||
return _Rword;
|
||
}
|
||
else
|
||
{
|
||
//36申请的设备号和任务号不匹配
|
||
www[0]=36;
|
||
CSimensProdave6_S7.DB_Write_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address), 1, www);
|
||
return null;
|
||
}
|
||
// }
|
||
//}
|
||
#endregion
|
||
}
|
||
#endregion
|
||
|
||
#region 删除当前设备所执行的任务(4)(托盘拿走)
|
||
else if (_Rword[2] == 4)//命令字
|
||
{
|
||
DataView dvbc = dbo.ExceSQL("SELECT F_MonitorIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2," +
|
||
"F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_MonitorIndex = '" +
|
||
_Rword[4] + "' and F_DeviceIndex=" + _Rword[3] + " order by F_MonitorIndex asc").Tables[0].DefaultView;
|
||
if (dvbc.Count > 0)
|
||
{
|
||
www[0] = 3;
|
||
CSimensProdave6_S7.DB_Write_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address), 1, www);
|
||
////记录任务号
|
||
//dbo.ExceSQL("update T_Base_PLC_Ask set F_TaskIndex='" + _Rword[4]
|
||
// + "' where F_DeviceIndex=" + DeviceIndex);
|
||
return _Rword;
|
||
}
|
||
else
|
||
{
|
||
//36申请的设备号和任务号不匹配
|
||
www[0]= 36 ;
|
||
CSimensProdave6_S7.DB_Write_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address), 1, www);
|
||
return null;
|
||
}
|
||
}
|
||
#endregion
|
||
break;
|
||
#endregion
|
||
|
||
#region 其他设备
|
||
case "1"://堆垛机
|
||
_RRword = CSimensProdave6_S7.DB_Read_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address), Convert.ToUInt32(devinfo.Dbw2Getlength));
|
||
if (_RRword == null)
|
||
{
|
||
_commLayerError = "SimensProdave6.CGetDeviceState.GetDeviceState发生错误:" + CSimensProdave6_S7.ErrorsText;
|
||
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
_Rword[0] = Convert.ToInt32(_RRword[0]);//读写标志
|
||
_Rword[1] = Convert.ToInt32(_RRword[1]);//状态
|
||
_Rword[2] = Convert.ToInt32((_RRword[2] << 8) + _RRword[3]);//任务号
|
||
_Rword[3] = Convert.ToInt32(_RRword[7] + (_RRword[6] << 8) + (_RRword[5] << 16) + (_RRword[4] << 32));//X坐标
|
||
_Rword[4] = Convert.ToInt32(_RRword[11] + (_RRword[10] << 8) + (_RRword[9] << 16) + (_RRword[8] << 32));//Y坐标
|
||
_Rword[5] = DeviceIndex;//设备号索引
|
||
}
|
||
|
||
break;
|
||
case "2"://输送机
|
||
_RRword = CSimensProdave6_S7.DB_Read_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address), Convert.ToUInt32(devinfo.Dbw2Getlength));
|
||
if (_RRword == null)
|
||
{
|
||
_commLayerError = "SimensProdave6.CGetDeviceState.GetDeviceState发生错误:" + CSimensProdave6_S7.ErrorsText;
|
||
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
www = new byte[4];
|
||
Array.Copy(_RRword, www, 4);
|
||
CommonClassLib.CCarryConvert.WriteDarkCasket("ReadTcpIp", "CGetDeviceState", DeviceIndex.ToString(), www);
|
||
_Rword[0] = Convert.ToInt32(_RRword[0]);//读写标志
|
||
_Rword[1] = Convert.ToInt32(_RRword[1]);//状态
|
||
_Rword[2] = Convert.ToInt32((_RRword[2] << 8) + _RRword[3]);//任务号
|
||
_Rword[3] = 0;
|
||
_Rword[4] = 0;
|
||
_Rword[5] = DeviceIndex;//设备号索引
|
||
}
|
||
break;
|
||
case "4"://RGV
|
||
_RRword = CSimensProdave6_S7.DB_Read_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address), Convert.ToUInt32(devinfo.Dbw2Getlength));
|
||
if (_RRword == null)
|
||
{
|
||
_commLayerError = "SimensProdave6.CGetDeviceState.GetDeviceState发生错误:" + CSimensProdave6_S7.ErrorsText;
|
||
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
www=new byte[8];
|
||
Array.Copy(_RRword, www, 8);
|
||
CommonClassLib.CCarryConvert.WriteDarkCasket("ReadTcpIp", "CGetDeviceState", DeviceIndex.ToString(), www);
|
||
_Rword[0] = Convert.ToInt32(_RRword[0]);//读写标志
|
||
_Rword[1] = Convert.ToInt32(_RRword[1]);//状态
|
||
_Rword[2] = Convert.ToInt32((_RRword[2] <<8) + _RRword[3]);//任务号
|
||
_Rword[3] = Convert.ToInt32(_RRword[7] + (_RRword[6]<<8) + (_RRword[5] << 16) + (_RRword[4] <<32));//X坐标
|
||
_Rword[4] = 0;
|
||
_Rword[5] = DeviceIndex;//设备号索引
|
||
}
|
||
break;
|
||
#endregion
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
return _Rword;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_commLayerError = "SimensProdave6.CGetDeviceState.GetDeviceState发生错误:" + ex.Message;
|
||
return null;
|
||
}
|
||
|
||
}
|
||
public string GetStringData(int DeviceIndex, int TaskIndex)
|
||
{
|
||
try
|
||
{
|
||
byte[] _RRword;
|
||
string headstr = "";
|
||
string retdata = "";
|
||
Model.MDevice devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIndex);
|
||
//DataView dv = dbo.ExceSQL("SELECT F_DBW2Address,F_DBWGetLength,F_DeviceIndex,F_DeviceKindIndex,F_OPCProgID, F_RemoteIP FROM T_Base_Device where F_DeviceIndex=" + DeviceIndex).Tables[0].DefaultView;
|
||
if (devinfo.DeviceIndex == 0)
|
||
{
|
||
_commLayerError = "SimensProdave6.CGetDeviceState.GetStringData发生错误:在设备表中没找到设备所引!";
|
||
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
_RRword = CSimensProdave6_S7.DB_Read_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address), Convert.ToUInt32(devinfo.Dbw2Getlength));
|
||
if (_RRword == null)
|
||
{
|
||
_commLayerError = "SimensProdave6.CGetDeviceState.GetDeviceState发生错误:" + CSimensProdave6_S7.ErrorsText;
|
||
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
switch (devinfo.DeviceKind.ToString())
|
||
{
|
||
|
||
#region 托盘条码信息(10个字节)
|
||
case "7":
|
||
headstr = _RRword[0].ToString();
|
||
for (int i = 1; i <= 10;i++ )
|
||
{
|
||
retdata += Convert.ToChar(_RRword[i]);
|
||
|
||
}
|
||
|
||
|
||
break;
|
||
#endregion
|
||
#region 烟箱一号工程码(18个字节)
|
||
case "21":
|
||
headstr = _RRword[0].ToString();
|
||
for (int i = 1; i <= 18; i++)
|
||
{
|
||
retdata += Convert.ToChar(_RRword[i]);
|
||
|
||
}
|
||
|
||
break;
|
||
#endregion
|
||
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
if (headstr == "1")
|
||
{
|
||
byte[] ww=new byte[1]{2};
|
||
if (CSimensProdave6_S7.DB_Write_Prodave(0, 2, Convert.ToUInt16(devinfo.Dbw2Address), 1, ww) == false)
|
||
{
|
||
_commLayerError = "SimensProdave6.CGetDeviceState.GetDeviceState:" + CSimensProdave6_S7.ErrorsText;
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
return retdata;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return null;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_commLayerError = "SimensProdave6.CGetDeviceState.GetStringData发生错误:" + ex.Message;
|
||
return null;
|
||
}
|
||
}
|
||
void RestoreDevice(int mindex)
|
||
{
|
||
SimensProdave6.CSendDeviceOrder sdo=new CSendDeviceOrder();
|
||
int DeviceIdx, devKind;
|
||
DataView dv = dbo.ExceSQL("select F_MonitorIndex,F_DeviceIndex from T_Monitor_Task where F_MonitorIndex=" + mindex).Tables[0].DefaultView;
|
||
if (dv.Count > 0)
|
||
{
|
||
//检查关联命令一起复位
|
||
//如果mindex是主动任务(f_associatemonitor有数据),先复位被动的任务;如果mindex是被动任务,先复位自己,再复位主动任务;
|
||
DataView dv1 = dbo.ExceSQL("select F_DeviceIndex,F_Associate from T_Monitor_Task where F_Associate IS NOT NULL and F_MonitorIndex=" + mindex).Tables[0].DefaultView;
|
||
if (dv1.Count > 0)
|
||
{
|
||
DataView dv2 = dbo.ExceSQL("select F_DeviceIndex,F_MonitorIndex from T_Monitor_Task where F_MonitorIndex=" + Convert.ToInt32(dv1[0]["F_Associate"])).Tables[0].DefaultView;
|
||
if (dv2.Count > 0)//有关联命令,先复位关联命令
|
||
{
|
||
|
||
DeviceIdx = Convert.ToInt32(dv2[0]["F_DeviceIndex"]);
|
||
devKind = GetDeviceKindIdx(DeviceIdx);
|
||
if ((devKind == 2) || (devKind == 4))
|
||
{//输送机清零
|
||
sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0);
|
||
}
|
||
if ((devKind == 1)) //堆垛机、RGV
|
||
{
|
||
|
||
sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0, 0, 0, 0, 0, 0);
|
||
}
|
||
dbo.ExceSQL("update T_Base_Device set F_LockedState=0 where F_DeviceIndex=" + Convert.ToInt32(dv2[0]["F_DeviceIndex"]));
|
||
dbo.ExceSQL("update T_Monitor_Task set F_Status=0 where F_MonitorIndex=" + Convert.ToInt32(dv2[0]["F_MonitorIndex"]));
|
||
}
|
||
//再复位自己
|
||
DeviceIdx = Convert.ToInt32(dv[0]["F_DeviceIndex"]);
|
||
devKind = GetDeviceKindIdx(DeviceIdx);
|
||
if ((devKind == 2) || (devKind == 4))
|
||
{//输送机、RGV清零
|
||
sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0);
|
||
}
|
||
if ((devKind == 1)) //堆垛机
|
||
{
|
||
|
||
sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0, 0, 0, 0, 0, 0);
|
||
}
|
||
dbo.ExceSQL("update T_Base_Device set F_LockedState=0 where F_DeviceIndex=" + Convert.ToInt32(dv[0]["F_DeviceIndex"]));
|
||
dbo.ExceSQL("update T_Monitor_Task set F_Status=0 where F_MonitorIndex=" + Convert.ToInt32(dv[0]["F_MonitorIndex"]));
|
||
|
||
}
|
||
else
|
||
{
|
||
//自己是否被关联,先复位自己,再复位主任务
|
||
DataView dv3 = dbo.ExceSQL("select F_DeviceIndex,F_MonitorIndex from T_Monitor_Task where F_Associate ='" + mindex + "'").Tables[0].DefaultView;
|
||
if (dv3.Count > 0)
|
||
{ //先复位自己
|
||
DeviceIdx = Convert.ToInt32(dv[0]["F_DeviceIndex"]);
|
||
devKind = GetDeviceKindIdx(DeviceIdx);
|
||
if ((devKind == 2) || (devKind == 4))
|
||
{//输送机、RGV清零
|
||
|
||
sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0);
|
||
}
|
||
if ((devKind == 1)) //堆垛机
|
||
{
|
||
|
||
sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0, 0, 0, 0, 0, 0);
|
||
}
|
||
dbo.ExceSQL("update T_Base_Device set F_LockedState=0 where F_DeviceIndex=" + Convert.ToInt32(dv[0]["F_DeviceIndex"]));
|
||
dbo.ExceSQL("update T_Monitor_Task set F_Status=0 where F_MonitorIndex=" + mindex);
|
||
//再复位主任务
|
||
DeviceIdx = Convert.ToInt32(dv3[0]["F_DeviceIndex"]);
|
||
devKind = GetDeviceKindIdx(DeviceIdx);
|
||
if ((devKind == 2) || (devKind == 4))
|
||
{//输送机、RGV清零
|
||
sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0);
|
||
}
|
||
if ((devKind == 1)) //堆垛机
|
||
{
|
||
|
||
sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0, 0, 0, 0, 0, 0);
|
||
}
|
||
dbo.ExceSQL("update T_Base_Device set F_LockedState=0 where F_DeviceIndex=" + Convert.ToInt32(dv3[0]["F_DeviceIndex"]));
|
||
dbo.ExceSQL("update T_Monitor_Task set F_Status=0 where F_MonitorIndex=" + Convert.ToInt32(dv3[0]["F_MonitorIndex"]));
|
||
}
|
||
else
|
||
{
|
||
//无关联任务,只复位自己
|
||
DeviceIdx = Convert.ToInt32(dv[0]["F_DeviceIndex"]);
|
||
devKind = GetDeviceKindIdx(DeviceIdx);
|
||
if ((devKind == 2) || (devKind == 4))
|
||
{//输送机、RGV清零
|
||
sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0);
|
||
}
|
||
if ((devKind == 1)) //堆垛机
|
||
{
|
||
|
||
sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0, 0, 0, 0, 0, 0);
|
||
}
|
||
dbo.ExceSQL("update T_Base_Device set F_LockedState=0 where F_DeviceIndex=" + Convert.ToInt32(dv[0]["F_DeviceIndex"]));
|
||
dbo.ExceSQL("update T_Monitor_Task set F_Status=0 where F_MonitorIndex=" + mindex);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
int GetDeviceKindIdx(int devIdx)
|
||
{
|
||
try
|
||
{
|
||
|
||
string strSql = "SELECT F_DeviceIndex, F_DeviceKindIndex FROM T_Base_Device WHERE F_DeviceIndex=" + devIdx;
|
||
DataSet ds = dbo.ExceSQL(strSql);
|
||
DataView dv = ds.Tables[0].DefaultView;
|
||
if (dv.Count > 0)
|
||
{
|
||
return Convert.ToInt32(dv[0]["F_DeviceKindIndex"]);
|
||
}
|
||
else
|
||
return 0;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
}
|
||
}
|