using Mesnac.Compressor.Entity; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; //using watchFile; namespace Mesnac.Compressor.Unity { public class Common { #region 单例模式 private static Common _trayFactory; private static readonly object sysany = new object(); public static Common Instance { get { if (_trayFactory == null) { lock(sysany) { _trayFactory = new Common(); } } return _trayFactory; } } #endregion /// /// 读写器默认超时时间 5000毫秒 十六进制1388 /// //public string ReadTimeOut = "1388"; #region 变量 public List StationList = new List(); public string ReadTimeOut = System.Configuration.ConfigurationManager.AppSettings["ReadTimeOut"]; //当前平板对应的工位名 public string WorkName = System.Configuration.ConfigurationManager.AppSettings["WorkName"]; //当前平板对应的机种切换写入PLC地址 public string MachinePlCAddress = System.Configuration.ConfigurationManager.AppSettings["MachinePlCAddress"]; public string ChangeMachineOK = System.Configuration.ConfigurationManager.AppSettings["ChangeMachineOK"]; public string CurrentMachineType = System.Configuration.ConfigurationManager.AppSettings["CurrentMachineType"]; //手动自动对应pLC的地址位 public string AutoFlagConfig = System.Configuration.ConfigurationManager.AppSettings["AutoFlagConfig"]; public bool AutoFlag = true; /// /// 手动还是自动模式 /// public bool IsAuto = false; #region 连接状态 //服务器连接状态 public bool ServerConnect = true; //本地数据库连接状态 public bool LocalConnect = true; /// /// 读写器连接状态 /// public bool SocketConnect = true; /// /// 条码枪连接状态 /// public bool GunConnect = true; /// /// 是否连接本地数据库 /// public bool ReadLocalDB = false; #endregion public EventHandler SerialReconnect; public EventHandler SocketReconnect; public DictionaryOperation ScanCodeDic = new DictionaryOperation(); #endregion public void Init() { XmlRead(); //InitWatchFile(); } //public void InitWatchFile() //{ // Console.WriteLine(Common.Instance.WorkName+"WorkName"); // if (Common.Instance.WorkName.Trim().ToUpper() == "B2") // { // Console.WriteLine("B2开始监测"); // watchFileManager watch = new watchFileManager(); // watch.Start(); // } //} private void XmlRead() { try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("Config.xml"); //加载xml文件 XmlNode xn = xmlDoc.SelectSingleNode("Setting/work"); XmlNodeList xnl = xn.ChildNodes; foreach (XmlNode xnf in xnl) { XmlElement xe = (XmlElement)xnf; XmlNodeList xnf1 = xe.ChildNodes; Station station = new Station(); foreach (XmlNode xn2 in xnf1) { //Console.WriteLine(xn2.InnerText);//显示子节点点文本 XmlElement xmm = (XmlElement)xn2; if (xmm.Name == "workName") { station.StationName = xmm.InnerText; continue; } else if (xmm.Name == "stationID") { station.stationID = xmm.InnerText; continue; } else if (xmm.Name == "Ant") { station.Ant = xmm.InnerText; continue; } else if (xmm.Name == "IP") { station.IP = xmm.InnerText; continue; } else if (xmm.Name == "StationType") { station.StationType = xmm.InnerText; continue; } else if (xmm.Name == "DbTableName") { station.DbTableName = xmm.InnerText; continue; } else if (xmm.Name == "PlcReadyAddress") { station.plcAdress.PlcReadyAddress = xmm.InnerText; continue; } else if (xmm.Name == "WorkedAlready") { station.plcAdress.WorkedAlready = xmm.InnerText; continue; } else if (xmm.Name == "NullLetGo") { station.plcAdress.NullLetGo = xmm.InnerText; continue; } else if (xmm.Name == "ReStart") { station.plcAdress.ReStart = xmm.InnerText; continue; } else if (xmm.Name == "Unbunding") { station.plcAdress.Unbunding = xmm.InnerText; continue; } else if (xmm.Name == "AlarmUnbuding") { station.plcAdress.AlarmUnbuding = xmm.InnerText; continue; } else if (xmm.Name == "BarcodeAdress") { station.plcAdress.BarcodeAdress = xmm.InnerText; continue; } else if (xmm.Name == "Writeaddress") { station.plcAdress.Writeaddress = xmm.InnerText; continue; } else if (xmm.Name == "PlcDataAdress") { station.plcAdress.PlcDataAdress = xmm.InnerText; continue; } else if (xmm.Name == "PlcDataQuantity") { station.plcAdress.PlcDataQuantity = Convert.ToInt32(xmm.InnerText); continue; } else if (xmm.Name == "BarcodeWriteAddress") { station.plcAdress.BarcodeWriteAddress = xmm.InnerText; continue; } else if (xmm.Name == "RestartGOAddress") { station.plcAdress.RestartGOAddress = xmm.InnerText; continue; } else if (xmm.Name == "PlcQuality") { station.plcAdress.PlcQuality = xmm.InnerText; continue; } else if (xmm.Name == "IsRestart") { station.IsRestart = Convert.ToInt32(xmm.InnerText) > 0; continue; } else if (xmm.Name == "RestartCom") { station.RestartCom = xmm.InnerText; continue; } else if (xmm.Name == "IsChangeLine") { station.IsChangeLine = Convert.ToInt32(xmm.InnerText) > 0; continue; } else if (xmm.Name == "ChangeLineCom") { station.ChangeLineCom = xmm.InnerText; continue; } else if (xmm.Name == "BarcodeScan") { station.BarcodeScan = Convert.ToInt32(xmm.InnerText) > 0; continue; } else if (xmm.Name == "EngravingCom") { station.EngravingCom = xmm.InnerText; continue; } else if (xmm.Name == "Engraving") { station.Engraving = Convert.ToInt32(xmm.InnerText) > 0; continue; } else if (xmm.Name == "BarcodeScanCom") { station.BarcodeScanCom = xmm.InnerText; continue; } else if (xmm.Name == "NGstation") { station.NGstation = Convert.ToInt32(xmm.InnerText) > 0; continue; } else if (xmm.Name == "FirstStation") { station.FirstStation = Convert.ToInt32(xmm.InnerText) > 0; continue; } else if (xmm.Name == "subStation") { station.subStation = Convert.ToInt32(xmm.InnerText) > 0; continue; } else if (xmm.Name == "ParentStationName") { station.ParentStationName = xmm.InnerText; continue; } else if (xmm.Name == "SubStattionName") { station.SubStattionName = xmm.InnerText; continue; } else if (xmm.Name == "SendToNext") { station.SendToNext = Convert.ToInt32(xmm.InnerText) > 0; continue; } else if (xmm.Name == "SendPath") { station.SendPath = xmm.InnerText; continue; } else if (xmm.Name == "AllowMitiRFID") { station.AllowMitiRFID = Convert.ToInt32(xmm.InnerText) > 0; continue; } else if (xmm.Name == "DeletePreRFID") { station.DeletePreRFID = Convert.ToInt32(xmm.InnerText) > 0; continue; } } //虚拟站没有读RFID if (station.StationType.ToUpper() == "VartualStation".ToUpper()) { DataFormat df = new DataFormat(); df.PrepareWork = true; //测试用 df.HaveWorked = true; //测试用 station.InsertQueue(df); } StationList.Add(station); } } catch (Exception e) { //初始化错误2017 Console.WriteLine(e.ToString()); } } } }