using System; using System.Collections.Generic; using System.Collections.Concurrent; using System.Text; using System.Data; using DBFactory; namespace Model { public static class CGetInfo { static System.Object lockThis = new System.Object(); public static DBOperator dbo = CommonClassLib.AppSettings.dbo; //20130510 public static DBOperator dboM = CommonClassLib.AppSettings.dboM; //20130510 static Dictionary _DeviceErrors; static StringBuilder sql = new StringBuilder(); /// /// 设备状态集合:KEY设备号,VALUE:指令索引,状态,申请类型/命令字,条码,检尺高度/数量,重量; /// public static ConcurrentDictionary DeviceStatesInfo = new ConcurrentDictionary(); public static Dictionary DeviceErrors { get { return _DeviceErrors; } set { _DeviceErrors = value; } } /// /// 初始化设备故障信息 /// public static void AddDeviceErrors() {//20160501 lock (lockThis) { _DeviceErrors = new Dictionary(); sql.Remove(0, sql.Length); sql.Append("SELECT F_IfAlarm,f_ErrorKind,F_ErrorIndex, F_DeviceKindIndex, F_DeviceErrorIndex, F_ErrorName, F_ErrorLevel, F_ManageStatus FROM T_Base_Device_State where F_DeviceErrorIndex>=30"); DataView dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; for (int i = 0; i < dv.Count; i++) { Model.MError errs = new Model.MError(); errs.ErrorIndex = Convert.ToInt32(dv[i]["F_ErrorIndex"]); errs.DeviceErrorIndex = Convert.ToInt32(dv[i]["F_DeviceErrorIndex"]); errs.DeviceKindIndex = Convert.ToInt32(dv[i]["F_DeviceKindIndex"]); errs.DeviceErrorIndex = Convert.ToInt32(dv[i]["F_DeviceErrorIndex"]); errs.ErrorName = dv[i]["F_ErrorName"].ToString(); errs.ErrorLevel = Convert.ToInt32(dv[i]["F_ErrorLevel"]); errs.ManageStatus = Convert.ToInt32(dv[i]["F_ManageStatus"]); if (dv[i]["F_IfAlarm"] == DBNull.Value) {//20160501 errs.IfAlarm = '1'; } else { errs.IfAlarm = Convert.ToChar(dv[i]["F_IfAlarm"]); } if (dv[i]["F_ErrorKind"] == DBNull.Value) {//20160501 errs.ErrorKind = 'O'; } else { errs.ErrorKind = Convert.ToChar(dv[i]["F_ErrorKind"]); } if (_DeviceErrors.ContainsKey(Convert.ToInt32(errs.DeviceKindIndex.ToString() + errs.DeviceErrorIndex.ToString())) == false) { _DeviceErrors.Add(Convert.ToInt32(errs.DeviceKindIndex.ToString() + errs.DeviceErrorIndex.ToString()), errs); } } } } /// /// 通过设备类型+设备故障代码获取故障信息 /// /// 设备类型+设备故障代码 /// public static Model.MError GetErrorInfo(int errID) { lock (lockThis) { if (_DeviceErrors.ContainsKey(errID) == true) { return _DeviceErrors[errID]; } else { return null; } } } /// /// 可以改道的设备信息 /// public static Dictionary ModifyPathDeviceInfo { get; set; } /// /// 所有设备信息 /// static Dictionary _DeviceInfo; /// /// 加载到内存中的设备信息集合 /// public static Dictionary DeviceInfo { get { return _DeviceInfo; } set { _DeviceInfo = value; } } /// /// 向内中添加设备信息 /// public static void AddDeviceInfo() { lock (lockThis) { DataView dv1 = new DataView(); _DeviceInfo = new Dictionary(); sql.Remove(0, sql.Length); sql.Append("select * from T_Base_Device order by F_DeviceIndex asc"); DataView dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; for (int i = 0; i < dv.Count; i++) { Model.MDevice devinfo = new Model.MDevice(); if (dv[i]["F_AppendBarcode"] == DBNull.Value) { devinfo.AppendBarcode = 0; } else { devinfo.AppendBarcode = Convert.ToInt32(dv[i]["F_AppendBarcode"]); } if (dv[i]["F_BeDetected"] == DBNull.Value) { devinfo.BeDetected = null; } else { devinfo.BeDetected = dv[i]["F_BeDetected"].ToString(); } if (dv[i]["F_BindingDevice"] == DBNull.Value) { devinfo.BindingDevice = null; } else { devinfo.BindingDevice = dv[i]["F_BindingDevice"].ToString(); } if (dv[i]["F_BindingDeviceOut"] == DBNull.Value) { devinfo.BindingDeviceOut = null; } else { devinfo.BindingDeviceOut = dv[i]["F_BindingDeviceOut"].ToString(); } if (dv[i]["F_CommType"] == DBNull.Value) { devinfo.CommType = null; } else { devinfo.CommType = dv[i]["F_CommType"].ToString(); } if (dv[i]["F_DBW1Address"] == DBNull.Value) { devinfo.Dbw1Address = -1; } else { devinfo.Dbw1Address = Convert.ToInt32(dv[i]["F_DBW1Address"]); } if (dv[i]["F_DBWSendLength"] == DBNull.Value) { devinfo.Dbw1SendLength = 0; } else { devinfo.Dbw1SendLength = Convert.ToInt32(dv[i]["F_DBWSendLength"]); } if (dv[i]["F_DBW2Address"] == DBNull.Value) { devinfo.Dbw2Address = -1; } else { devinfo.Dbw2Address = Convert.ToInt32(dv[i]["F_DBW2Address"]); } if (dv[i]["F_DBWGetLength"] == DBNull.Value) { devinfo.Dbw2Getlength = 0; } else { devinfo.Dbw2Getlength = Convert.ToInt32(dv[i]["F_DBWGetLength"]); } if (dv[i]["F_DeviceIndex"] == DBNull.Value) { devinfo.DeviceIndex = 0; } else { devinfo.DeviceIndex = Convert.ToInt32(dv[i]["F_DeviceIndex"]); } if (dv[i]["F_DeviceKindIndex"] == DBNull.Value) { devinfo.DeviceKind = 0; } else { devinfo.DeviceKind = Convert.ToInt32(dv[i]["F_DeviceKindIndex"]); } if (dv[i]["F_DeviceName"] == DBNull.Value) { devinfo.DeviceName = null; } else { devinfo.DeviceName = (string)dv[i]["F_DeviceName"]; } if (dv[i]["F_DeviceVisual"] == DBNull.Value) { devinfo.DeviceVisual = 0; } else { devinfo.DeviceVisual = Convert.ToInt32(dv[i]["F_DeviceVisual"]); } if (dv[i]["F_KeyDevice"] == DBNull.Value) { devinfo.IfKeyDevice = '0'; } else { devinfo.IfKeyDevice = Convert.ToChar(dv[i]["F_KeyDevice"]); } if (dv[i]["F_MaxSendCount"] == DBNull.Value) { devinfo.MaxSendCount = 0; } else { devinfo.MaxSendCount = Convert.ToInt32(dv[i]["F_MaxSendCount"]); } if (dv[i]["F_NeedOptimize"] == DBNull.Value) { devinfo.NeedOptimize = '0'; } else { devinfo.NeedOptimize = Convert.ToChar(dv[i]["F_NeedOptimize"]); } if (dv[i]["F_SendInterval"] == DBNull.Value) { devinfo.SendInterval = 0; } else { devinfo.SendInterval = Convert.ToInt32(dv[i]["F_SendInterval"]); } if (dv[i]["F_LocalIP"] == DBNull.Value) { devinfo.LocalIP = ""; } else { devinfo.LocalIP = (string)dv[i]["F_LocalIP"]; } if (dv[i]["F_LocalPort"] == DBNull.Value) { devinfo.LocalPort = 0; } else { devinfo.LocalPort = Convert.ToInt32(dv[i]["F_LocalPort"]); } if (dv[i]["F_RemoteIP"] == DBNull.Value) { devinfo.RemoteIP = ""; } else { devinfo.RemoteIP = (string)dv[i]["F_RemoteIP"]; } if (dv[i]["F_RemotePort"] == DBNull.Value) { devinfo.RemotePort = 0; } else { devinfo.RemotePort = Convert.ToInt32(dv[i]["F_RemotePort"]); } if (dv[i]["F_OPCProgID"] == DBNull.Value) { devinfo.OPCProgID = ""; } else { devinfo.OPCProgID = (string)dv[i]["F_OPCProgID"]; } if (dv[i]["F_ErrorTaskNo"] == DBNull.Value) { devinfo.ErrorTaskNo = 0; } else { devinfo.ErrorTaskNo = Convert.ToInt32(dv[i]["F_ErrorTaskNo"]); } if (dv[i]["F_SendOutDetect"] == DBNull.Value) { devinfo.SendOutDetect = ""; } else { devinfo.SendOutDetect = dv[i]["F_SendOutDetect"].ToString(); } // if (dv[i]["F_OnlyDetectIO"] == DBNull.Value) { devinfo.OnlyDetectIO = "0"; } else { devinfo.OnlyDetectIO = dv[i]["F_OnlyDetectIO"].ToString(); } if (dv[i]["F_UseCommonDB"] == DBNull.Value) { devinfo.UseCommonDB = "0"; } else { devinfo.UseCommonDB = dv[i]["F_UseCommonDB"].ToString(); } if (dv[i]["F_IfCorrelDoubleFork"] == DBNull.Value) { devinfo.IfCorrelDoubleFork = "0"; } else { devinfo.IfCorrelDoubleFork = dv[i]["F_IfCorrelDoubleFork"].ToString(); } //20100609 if (dv[i]["F_SerialPort"] == DBNull.Value) { devinfo.SerialPort = 0; } else { devinfo.SerialPort = Convert.ToInt32(dv[i]["F_SerialPort"]); } //20100609 if (dv[i]["F_CommSettings"] == DBNull.Value) { devinfo.CommSettings = "0"; } else { devinfo.CommSettings = dv[i]["F_CommSettings"].ToString(); } //20100714 if (dv[i]["F_S7Connection"] == DBNull.Value) { devinfo.S7Connection = "S7:[S7 connection_1]"; } else { devinfo.S7Connection = dv[i]["F_S7Connection"].ToString(); } //20101118 if (dv[i]["F_SplitByte"] == DBNull.Value) { devinfo.SplitByte = -1; } else { devinfo.SplitByte = Convert.ToInt32(dv[i]["F_SplitByte"]); } if (dv[i]["F_ManTaskReserve"] == DBNull.Value) { devinfo.ManTaskReserve = 0; } else { devinfo.ManTaskReserve = Convert.ToInt32(dv[i]["F_ManTaskReserve"]); } if (dv[i]["F_HaveGoods"] == DBNull.Value) { devinfo.LogicHaveGoods = false; } else { devinfo.LogicHaveGoods = Convert.ToInt32(dv[i]["F_HaveGoods"]) >0 ? true : false; } if (dv[i]["F_ReadSubscription"] == DBNull.Value) { devinfo.ReadSubscription = "0"; } else { devinfo.ReadSubscription = dv[i]["F_ReadSubscription"].ToString(); } if (dv[i]["F_UnControl"] == DBNull.Value) { devinfo.UnControl = "0"; } else { devinfo.UnControl = dv[i]["F_UnControl"].ToString(); } switch (devinfo.DeviceKind) {//20120820 case 1://堆垛机的特定属性 sql.Clear(); sql.Append("SELECT F_ForkAmount, F_Reach,F_Mutex,F_VirtualStack,F_AbendOut,F_ZeroColLayer,F_SpecialZXArea,F_PRIZXArea FROM T_Base_StackInfo WHERE F_StackIndex = ").Append(devinfo.DeviceIndex); dv1 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv1.Count > 0) { devinfo.ForkAmount = Convert.ToInt32(dv1[0]["F_ForkAmount"]); devinfo.StackReach = Convert.ToInt32(dv1[0]["F_Reach"]); if (dv1[0]["F_VirtualStack"] != DBNull.Value) { devinfo.VirtualStack = Convert.ToInt32(dv1[0]["F_VirtualStack"]); } else { devinfo.VirtualStack = 0; } if (dv1[0]["F_Mutex"] != DBNull.Value) { devinfo.MutexStack = Convert.ToInt32(dv1[0]["F_Mutex"]); } else { devinfo.MutexStack = 0; } if (dv1[0]["F_AbendOut"] != DBNull.Value) { devinfo.StackAbendOut = Convert.ToInt32(dv1[0]["F_AbendOut"]); } else { devinfo.StackAbendOut = 0; } if (dv1[0]["F_ZeroColLayer"] != DBNull.Value) { devinfo.StackZeroColLayer = dv1[0]["F_ZeroColLayer"].ToString(); } else { devinfo.StackZeroColLayer = ""; } if (dv1[0]["F_SpecialZXArea"] != DBNull.Value) { devinfo.SpecialZXArea = dv1[0]["F_SpecialZXArea"].ToString(); } else { devinfo.SpecialZXArea = ""; } if (dv1[0]["F_PRIZXArea"] != DBNull.Value) { devinfo.PRIZXArea = dv1[0]["F_PRIZXArea"].ToString(); } else { devinfo.PRIZXArea = ""; } } else { devinfo.ForkAmount = 1; devinfo.StackReach = 1; devinfo.VirtualStack = 0; devinfo.MutexStack =0; devinfo.StackAbendOut = 0; devinfo.StackZeroColLayer =""; devinfo.PRIZXArea = ""; devinfo.SpecialZXArea = ""; } break; case 2://检查是否为巷道口多叉堆垛机取放操作设备 sql.Clear(); sql.Append("SELECT F_UseAwayFork FROM T_Base_Lane_Gate WHERE F_LaneGateDeviceIndex =").Append(devinfo.DeviceIndex); dv1 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv1.Count > 0) { devinfo.DoubleFork = dv1[0]["F_UseAwayFork"].ToString(); } else { devinfo.DoubleFork = "0"; } break; case 4://RGV的特定属性 sql.Clear(); sql.Append("SELECT F_ForkAmount, F_Reach,F_Mutex,F_VirtualRGV,F_AbendOut,F_ZeroColLayer,F_SpecialZXArea,F_PRIZXArea FROM T_Base_RGVInfo WHERE F_RGVIndex = ").Append(devinfo.DeviceIndex); dv1 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv1.Count > 0) { devinfo.ForkAmount = Convert.ToInt32(dv1[0]["F_ForkAmount"]); devinfo.StackReach = Convert.ToInt32(dv1[0]["F_Reach"]); if (dv1[0]["F_VirtualRGV"] != DBNull.Value) { devinfo.VirtualStack = Convert.ToInt32(dv1[0]["F_VirtualRGV"]); } else { devinfo.VirtualStack = 0; } if (dv1[0]["F_Mutex"] != DBNull.Value) { devinfo.MutexStack = Convert.ToInt32(dv1[0]["F_Mutex"]); } else { devinfo.MutexStack = 0; } if (dv1[0]["F_AbendOut"] != DBNull.Value) { devinfo.StackAbendOut = Convert.ToInt32(dv1[0]["F_AbendOut"]); } else { devinfo.StackAbendOut = 0; } if (dv1[0]["F_ZeroColLayer"] != DBNull.Value) { devinfo.StackZeroColLayer = dv1[0]["F_ZeroColLayer"].ToString(); } else { devinfo.StackZeroColLayer = ""; } if (dv1[0]["F_SpecialZXArea"] != DBNull.Value) { devinfo.SpecialZXArea = dv1[0]["F_SpecialZXArea"].ToString(); } else { devinfo.SpecialZXArea = ""; } if (dv1[0]["F_PRIZXArea"] != DBNull.Value) { devinfo.PRIZXArea = dv1[0]["F_PRIZXArea"].ToString(); } else { devinfo.PRIZXArea = ""; } } else { devinfo.ForkAmount = 1; devinfo.StackReach = 1; devinfo.VirtualStack = 0; devinfo.MutexStack = 0; devinfo.StackAbendOut = 0; devinfo.StackZeroColLayer = ""; devinfo.PRIZXArea = ""; devinfo.SpecialZXArea = ""; } break; case 9://检查是否为多叉AGV取放口操作设备 sql.Clear(); sql.Append("SELECT F_UseAwayFork FROM T_Base_AGV_Gate WHERE F_AGVGateDeviceIndex= " ).Append(devinfo.DeviceIndex ); dv1 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv1.Count > 0) { devinfo.DoubleFork = dv1[0]["F_UseAwayFork"].ToString(); } else { devinfo.DoubleFork = "0"; } break; default: devinfo.DoubleFork = "0"; devinfo.ForkAmount = 1; devinfo.StackReach = 1; devinfo.VirtualStack = 0; devinfo.MutexStack =0; devinfo.StackAbendOut = 0; devinfo.StackZeroColLayer =""; break; } if (dv[i]["F_IfClearDB1"] == DBNull.Value) { devinfo.IfClearDB1 = "0"; } else { devinfo.IfClearDB1 = dv[i]["F_IfClearDB1"].ToString(); } if (dv[i]["F_ScheduledDailyTaskCount"] == DBNull.Value) {//20160501 devinfo.ScheduledDailyTaskCount = 320; } else { devinfo.ScheduledDailyTaskCount = Convert.ToInt32(dv[i]["F_ScheduledDailyTaskCount"]); } //richard.liu20230718初始化鸿安环穿主站报警 devinfo.EmergencyStop = new bool[16]; devinfo.SafetyDoor = new bool[16]; devinfo.SafetyLightGrid = new bool[16]; sql.Clear(); sql.Append("SELECT station_inout_mode FROM T_BASE_IOMODE_SWITCH WHERE input_station_code= ").Append(devinfo.DeviceIndex); dv1 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; if (dv1.Count > 0) { devinfo.IOWorkMode = dv1[0]["station_inout_mode"].ToString(); } else { devinfo.IOWorkMode=""; } if (_DeviceInfo.ContainsKey(devinfo.DeviceIndex) == false) { _DeviceInfo.Add(devinfo.DeviceIndex, devinfo); } } } } /// /// 添加可以改道设备信息 /// public static void AddModifyPathDeviceInfo() { lock (lockThis) { ModifyPathDeviceInfo = new Dictionary(); sql.Remove(0, sql.Length); sql.Append("select * from T_Base_Device where (F_DeviceKindIndex=1 or F_DeviceKindIndex=2 or F_DeviceKindIndex=4 or F_DeviceKindIndex=40) and F_DBW2Address is not null order by F_DeviceIndex asc");//20130226richard.liu DataView dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView; for (int i = 0; i < dv.Count; i++) { Model.MDevice devinfo = new Model.MDevice(); if (dv[i]["F_AppendBarcode"] == DBNull.Value) { devinfo.AppendBarcode = 0; } else { devinfo.AppendBarcode = Convert.ToInt32(dv[i]["F_AppendBarcode"]); } if (dv[i]["F_BeDetected"] == DBNull.Value) { devinfo.BeDetected = null; } else { devinfo.BeDetected = dv[i]["F_BeDetected"].ToString(); } if (dv[i]["F_BindingDevice"] == DBNull.Value) { devinfo.BindingDevice = null; } else { devinfo.BindingDevice = dv[i]["F_BindingDevice"].ToString(); } if (dv[i]["F_BindingDeviceOut"] == DBNull.Value) { devinfo.BindingDeviceOut = null; } else { devinfo.BindingDeviceOut = dv[i]["F_BindingDeviceOut"].ToString(); } if (dv[i]["F_CommType"] == DBNull.Value) { devinfo.CommType = null; } else { devinfo.CommType = dv[i]["F_CommType"].ToString(); } if (dv[i]["F_DBW1Address"] == DBNull.Value) { devinfo.Dbw1Address = -1; } else { devinfo.Dbw1Address = Convert.ToInt32(dv[i]["F_DBW1Address"]); } if (dv[i]["F_DBWSendLength"] == DBNull.Value) { devinfo.Dbw1SendLength = 0; } else { devinfo.Dbw1SendLength = Convert.ToInt32(dv[i]["F_DBWSendLength"]); } if (dv[i]["F_DBW2Address"] == DBNull.Value) { devinfo.Dbw2Address = -1; } else { devinfo.Dbw2Address = Convert.ToInt32(dv[i]["F_DBW2Address"]); } if (dv[i]["F_DBWGetLength"] == DBNull.Value) { devinfo.Dbw2Getlength = 0; } else { devinfo.Dbw2Getlength = Convert.ToInt32(dv[i]["F_DBWGetLength"]); } if (dv[i]["F_DeviceIndex"] == DBNull.Value) { devinfo.DeviceIndex = 0; } else { devinfo.DeviceIndex = Convert.ToInt32(dv[i]["F_DeviceIndex"]); } if (dv[i]["F_DeviceKindIndex"] == DBNull.Value) { devinfo.DeviceKind = 0; } else { devinfo.DeviceKind = Convert.ToInt32(dv[i]["F_DeviceKindIndex"]); } if (dv[i]["F_DeviceName"] == DBNull.Value) { devinfo.DeviceName = null; } else { devinfo.DeviceName = (string)dv[i]["F_DeviceName"]; } if (dv[i]["F_DeviceVisual"] == DBNull.Value) { devinfo.DeviceVisual = 0; } else { devinfo.DeviceVisual = Convert.ToInt32(dv[i]["F_DeviceVisual"]); } if (dv[i]["F_KeyDevice"] == DBNull.Value) { devinfo.IfKeyDevice = '0'; } else { devinfo.IfKeyDevice = Convert.ToChar(dv[i]["F_KeyDevice"]); } if (dv[i]["F_MaxSendCount"] == DBNull.Value) { devinfo.MaxSendCount = 0; } else { devinfo.MaxSendCount = Convert.ToInt32(dv[i]["F_MaxSendCount"]); } if (dv[i]["F_NeedOptimize"] == DBNull.Value) { devinfo.NeedOptimize = '0'; } else { devinfo.NeedOptimize = Convert.ToChar(dv[i]["F_NeedOptimize"]); } if (dv[i]["F_SendInterval"] == DBNull.Value) { devinfo.SendInterval = 0; } else { devinfo.SendInterval = Convert.ToInt32(dv[i]["F_SendInterval"]); } if (dv[i]["F_LocalIP"] == DBNull.Value) { devinfo.LocalIP = ""; } else { devinfo.LocalIP = (string)dv[i]["F_LocalIP"]; } if (dv[i]["F_LocalPort"] == DBNull.Value) { devinfo.LocalPort = 0; } else { devinfo.LocalPort = Convert.ToInt32(dv[i]["F_LocalPort"]); } if (dv[i]["F_RemoteIP"] == DBNull.Value) { devinfo.RemoteIP = ""; } else { devinfo.RemoteIP = (string)dv[i]["F_RemoteIP"]; } if (dv[i]["F_RemotePort"] == DBNull.Value) { devinfo.RemotePort = 0; } else { devinfo.RemotePort = Convert.ToInt32(dv[i]["F_RemotePort"]); } if (dv[i]["F_OPCProgID"] == DBNull.Value) { devinfo.OPCProgID = ""; } else { devinfo.OPCProgID = (string)dv[i]["F_OPCProgID"]; } if (dv[i]["F_ErrorTaskNo"] == DBNull.Value) { devinfo.ErrorTaskNo = 0; } else { devinfo.ErrorTaskNo = Convert.ToInt32(dv[i]["F_ErrorTaskNo"]); } if (dv[i]["F_SendOutDetect"] == DBNull.Value) { devinfo.SendOutDetect = ""; } else { devinfo.SendOutDetect = dv[i]["F_SendOutDetect"].ToString(); } // if (dv[i]["F_OnlyDetectIO"] == DBNull.Value) { devinfo.OnlyDetectIO = "0"; } else { devinfo.OnlyDetectIO = dv[i]["F_OnlyDetectIO"].ToString(); } if (dv[i]["F_UseCommonDB"] == DBNull.Value) { devinfo.UseCommonDB = "0"; } else { devinfo.UseCommonDB = dv[i]["F_UseCommonDB"].ToString(); } if (dv[i]["F_IfCorrelDoubleFork"] == DBNull.Value) { devinfo.IfCorrelDoubleFork = "0"; } else { devinfo.IfCorrelDoubleFork = dv[i]["F_IfCorrelDoubleFork"].ToString(); } //if (dv[i]["F_DoubleFork"] == DBNull.Value) //{ // devinfo.DoubleFork = "0"; //} //else //{ // devinfo.DoubleFork = dv[i]["F_DoubleFork"].ToString(); //} //20100609 if (dv[i]["F_SerialPort"] == DBNull.Value) { devinfo.SerialPort = 0; } else { devinfo.SerialPort = Convert.ToInt32(dv[i]["F_SerialPort"]); } //20100609 if (dv[i]["F_CommSettings"] == DBNull.Value) { devinfo.CommSettings = "0"; } else { devinfo.CommSettings = dv[i]["F_CommSettings"].ToString(); } //20100714 if (dv[i]["F_S7Connection"] == DBNull.Value) { devinfo.S7Connection = "S7:[S7 connection_1]"; } else { devinfo.S7Connection = dv[i]["F_S7Connection"].ToString(); } //20101118 if (dv[i]["F_SplitByte"] == DBNull.Value) { devinfo.SplitByte = -1; } else { devinfo.SplitByte = Convert.ToInt32(dv[i]["F_SplitByte"]); } if (dv[i]["F_ManTaskReserve"] == DBNull.Value) { devinfo.ManTaskReserve = 0; } else { devinfo.ManTaskReserve = Convert.ToInt32(dv[i]["F_ManTaskReserve"]); } if (dv[i]["F_HaveGoods"] == DBNull.Value) { devinfo.LogicHaveGoods = false; } else { devinfo.LogicHaveGoods = Convert.ToInt32(dv[i]["F_HaveGoods"])>0 ? true : false; } if (dv[i]["F_ReadSubscription"] == DBNull.Value) { devinfo.ReadSubscription = "0"; } else { devinfo.ReadSubscription = dv[i]["F_ReadSubscription"].ToString(); } if (dv[i]["F_UnControl"] == DBNull.Value) { devinfo.UnControl = "0"; } else { devinfo.UnControl = dv[i]["F_UnControl"].ToString(); } if (ModifyPathDeviceInfo.ContainsKey(devinfo.DeviceIndex) == false) { ModifyPathDeviceInfo.Add(devinfo.DeviceIndex, devinfo); } } } } public static Model.MDevice GetModifyPathDeviceInfo(int DeviceIndex) { //20091102 lock (lockThis) { if (ModifyPathDeviceInfo.ContainsKey(DeviceIndex) == true) { Model.MDevice md = ModifyPathDeviceInfo[DeviceIndex]; return md; } else { return null; } } } /// /// 更新内存中的设备可变信息:故障码,是否有物,运行状态,任务号,当前X、Y坐标,控制方式 /// /// public static void SetModifyPathDeviceInfo(Model.MDevice deviceinfo) { lock (lockThis) { ModifyPathDeviceInfo[deviceinfo.DeviceIndex].ErrorCode = deviceinfo.ErrorCode; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].HaveGoods = deviceinfo.HaveGoods; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].RunState = deviceinfo.RunState; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].TaskNo = deviceinfo.TaskNo; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].XCoor = deviceinfo.XCoor; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].YCoor = deviceinfo.YCoor; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].ControlMode = deviceinfo.ControlMode; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].Barcode = deviceinfo.Barcode; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].ArrowLocation = deviceinfo.ArrowLocation; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].HaveGoods = deviceinfo.HaveGoods; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].LogicHaveGoods = deviceinfo.LogicHaveGoods; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].SplitByte_0 = deviceinfo.SplitByte_0; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].SplitByte_1 = deviceinfo.SplitByte_1; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].SplitByte_2 = deviceinfo.SplitByte_2; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].SplitByte_3 = deviceinfo.SplitByte_3; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].SplitByte_4 = deviceinfo.SplitByte_4; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].SplitByte_5 = deviceinfo.SplitByte_5; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].SplitByte_6 = deviceinfo.SplitByte_6; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].SplitByte_7 = deviceinfo.SplitByte_7; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].SendMessage = deviceinfo.SendMessage; ModifyPathDeviceInfo[deviceinfo.DeviceIndex].ReturnMessage = deviceinfo.ReturnMessage; } } /// /// 通过设备索引反馈设备信息 /// /// 设备索引 /// public static Model.MDevice GetDeviceInfo(int DeviceIndex) { //20091102 lock (lockThis) { if (_DeviceInfo.ContainsKey(DeviceIndex) == true) { return _DeviceInfo[DeviceIndex]; } else { return null; } } } /// /// 更新内存中的设备可变信息:故障码,是否有物,运行状态,任务号,当前X、Y坐标,控制方式 /// /// public static void SetDeviceInfo(Model.MDevice deviceinfo) { lock (lockThis) { _DeviceInfo[deviceinfo.DeviceIndex].ErrorCode = deviceinfo.ErrorCode; _DeviceInfo[deviceinfo.DeviceIndex].HaveGoods = deviceinfo.HaveGoods; _DeviceInfo[deviceinfo.DeviceIndex].RunState = deviceinfo.RunState; _DeviceInfo[deviceinfo.DeviceIndex].TaskNo = deviceinfo.TaskNo; _DeviceInfo[deviceinfo.DeviceIndex].XCoor = deviceinfo.XCoor; _DeviceInfo[deviceinfo.DeviceIndex].YCoor = deviceinfo.YCoor; _DeviceInfo[deviceinfo.DeviceIndex].ControlMode = deviceinfo.ControlMode; _DeviceInfo[deviceinfo.DeviceIndex].Barcode = deviceinfo.Barcode; _DeviceInfo[deviceinfo.DeviceIndex].ArrowLocation = deviceinfo.ArrowLocation; _DeviceInfo[deviceinfo.DeviceIndex].HaveGoods = deviceinfo.HaveGoods; _DeviceInfo[deviceinfo.DeviceIndex].LogicHaveGoods = deviceinfo.LogicHaveGoods; _DeviceInfo[deviceinfo.DeviceIndex].SplitByte_0 = deviceinfo.SplitByte_0; _DeviceInfo[deviceinfo.DeviceIndex].SplitByte_1 = deviceinfo.SplitByte_1; _DeviceInfo[deviceinfo.DeviceIndex].SplitByte_2 = deviceinfo.SplitByte_2; _DeviceInfo[deviceinfo.DeviceIndex].SplitByte_3 = deviceinfo.SplitByte_3; _DeviceInfo[deviceinfo.DeviceIndex].SplitByte_4 = deviceinfo.SplitByte_4; _DeviceInfo[deviceinfo.DeviceIndex].SplitByte_5 = deviceinfo.SplitByte_5; _DeviceInfo[deviceinfo.DeviceIndex].SplitByte_6 = deviceinfo.SplitByte_6; _DeviceInfo[deviceinfo.DeviceIndex].SplitByte_7 = deviceinfo.SplitByte_7; _DeviceInfo[deviceinfo.DeviceIndex].SendMessage = deviceinfo.SendMessage; _DeviceInfo[deviceinfo.DeviceIndex].ReturnMessage = deviceinfo.ReturnMessage; } } public static void SetDeviceMessage(Model.MDevice deviceinfo) { lock (lockThis) { _DeviceInfo[deviceinfo.DeviceIndex].ReturnMessage = deviceinfo.ReturnMessage; } } static Dictionary _IOControlStatus; static Dictionary _DeviceKind; /// /// 加载到内存中的与管理任务交互的调度任务状态信息集合 /// public static Dictionary IOControlStatus { get { return CGetInfo._IOControlStatus; } set { CGetInfo._IOControlStatus = value; } } public static void AddIOControlStatus() { lock (lockThis) { _IOControlStatus = new Dictionary(); DataView dv = dbo.ExceSQL("SELECT * FROM T_Base_IOControlStatus ").Tables[0].DefaultView; for (int i = 0; i < dv.Count; i++) { Model.MIOControlStatus ioStatus = new Model.MIOControlStatus(); ioStatus.StatusCode = dv[i]["F_StatusCode"].ToString(); if (dv[i]["F_StatusID"] == DBNull.Value) { ioStatus.StatusID = 0; } else { ioStatus.StatusID = Convert.ToInt32(dv[i]["F_StatusID"]); } if (dv[i]["F_Remark"] == DBNull.Value) { ioStatus.Remark = "-"; } else { ioStatus.Remark = dv[i]["F_Remark"].ToString(); } if (dv[i]["F_ForkNo"] == DBNull.Value) { ioStatus.ForkNo = "-"; } else { ioStatus.ForkNo = dv[i]["F_ForkNo"].ToString(); } if (_IOControlStatus.ContainsKey(ioStatus.StatusCode) == false) { _IOControlStatus.Add(ioStatus.StatusCode, ioStatus); } } } } public static Model.MIOControlStatus GetIOControlStatus(string StatusCode) { lock (lockThis) { if (_IOControlStatus.ContainsKey(StatusCode) == true) { return _IOControlStatus[StatusCode]; } else { return null; } } } public static Model.MIOControlStatus GetIOControlStatus(int errid) { lock (lockThis) { DataView dv = dbo.ExceSQL(string.Format("SELECT F_StatusCode FROM T_Base_IOControlStatus where F_StatusID={0}",errid)).Tables[0].DefaultView; if (dv.Count > 0) { if (_IOControlStatus.ContainsKey(dv[0]["F_StatusCode"].ToString()) == true) { return _IOControlStatus[dv[0]["F_StatusCode"].ToString()]; } else { return null; } } else { return null; } } } public static Model.MDeviceKind GetDeviceKind(string DeviceKindCode) { lock (lockThis) { if (_DeviceKind.ContainsKey(DeviceKindCode) == true) { return _DeviceKind[DeviceKindCode]; } else { return null; } } } public static void AddDeviceKindInfo() { lock (lockThis) { _DeviceKind = new Dictionary(); DataView dv = dbo.ExceSQL("SELECT * FROM T_Base_Device_Kind ").Tables[0].DefaultView; for (int i = 0; i < dv.Count; i++) { Model.MDeviceKind dk = new Model.MDeviceKind(); dk.DeviceKindCode = dv[i]["F_DeviceKindCode"].ToString(); if (dv[i]["F_DeviceKindIndex"] == DBNull.Value) { dk.DeviceKindIndex = 0; } else { dk.DeviceKindIndex = Convert.ToInt32(dv[i]["F_DeviceKindIndex"]); } if (dv[i]["F_GoodsMoveKindIndex"] == DBNull.Value) { dk.GoodsMoveKindIndex = 0; } else { dk.GoodsMoveKindIndex = Convert.ToInt32(dv[i]["F_GoodsMoveKindIndex"]); } if (dv[i]["F_DeviceKindName"] == DBNull.Value) { dk.DeviceKindName = "-"; } else { dk.DeviceKindName = dv[i]["F_DeviceKindName"].ToString(); } if (_DeviceKind.ContainsKey(dk.DeviceKindCode) == false) { _DeviceKind.Add(dk.DeviceKindCode, dk); } } } } } }