public bool ProcessInit() { // nodeList = new List<CtlNodeBaseModel>(); MesAcc = new YHMesWrapper(); monitorNodeList = new List <CtlNodeBaseModel>(); this.nodeStatusList = new List <CtlNodeStatus>(); //解析配置文件 string reStr = ""; //string xmlCfgFile = System.AppDomain.CurrentDomain.BaseDirectory + @"data/AcCfg.xml"; XElement root = null; if (!SysCfg.SysCfgModel.LoadCfg(ref root, ref reStr)) { Console.WriteLine("系统配置解析错误,{0}", reStr); return(false); } //1 通信设备创建、初始化 hkAccessList = new List <IHKAccess>(); if (SysCfg.SysCfgModel.SimMode) { plcRWs = new List <IPlcRW>(); for (int i = 0; i < 5; i++) { IPlcRW plcRW = new PlcRWSim(); plcRW.PlcID = i + 1; plcRWs.Add(plcRW); } rfidRWs = new List <IrfidRW>(); for (int i = 0; i < 13; i++) { int rfidID = i + 1; IrfidRW rfidRW = new rfidRWSim(); rfidRW.ReaderID = (byte)rfidID; rfidRWs.Add(rfidRW); } HKAccess hk = new HKAccess(1, "127.0.0.1", 13535); hkAccessList.Add(hk); hk = new HKAccess(2, "127.0.0.1", 13535); hkAccessList.Add(hk); if (!hk.Conn(ref reStr)) { Console.WriteLine(reStr); } string ocvDBConn = "Data Source = 192.168.100.20;Initial Catalog=SRANCH;User ID=L_Guest;Password=Guest@123;";; // ocvAccess = new OcvAccess(ocvDBConn, 36); } else { XElement commDevXERoot = root.Element("CommDevCfg"); if (!ParseCommDevCfg(commDevXERoot, ref reStr)) { //logRecorder.AddLog(new LogModel(objectName, "PLC初始化错误,"+reStr, EnumLoglevel.错误)); Console.WriteLine("通信设备错误," + reStr); return(false); } } //2 控制节点初始化 XElement CtlnodeRoot = root.Element("CtlNodes"); if (!ParseCtlnodes(CtlnodeRoot, ref reStr)) { logRecorder.AddLog(new LogModel(objectName, "节点初始化错误," + reStr, EnumLoglevel.错误)); return(false); } foreach (AsrsCtlModel asrsModel in asrsCtlPresenter.AsrsCtls) { monitorNodeList.Add(asrsModel.StackDevice); monitorNodeList.AddRange(asrsModel.Ports.ToArray()); } //3 工位控制线程初始化 this.threadList = new List <ThreadRunModel>(); XElement ThreadnodeRoot = root.Element("ThreadAlloc"); if (!ParseTheadNodes(ThreadnodeRoot, ref reStr)) { logRecorder.AddLog(new LogModel(objectName, "任务分配错误," + reStr, EnumLoglevel.错误)); return(false); } NodeSwitch switchNode = GetNodeByID("7001") as NodeSwitch; List <AsrsControl.AsrsPortalModel> targetPorts = new List <AsrsPortalModel>(); foreach (string portID in switchNode.TargetPortIDs) { AsrsPortalModel portObj = GetNodeByID(portID) as AsrsControl.AsrsPortalModel; targetPorts.Add(portObj); } switchNode.TargetPorts = targetPorts; foreach (ThreadRunModel threadObj in threadList) { threadObj.LogRecorder = logRecorder; } for (int i = 0; i < this.monitorNodeList.Count(); i++) { CtlNodeBaseModel node = this.monitorNodeList[i]; node.LogRecorder = this.logRecorder; this.nodeStatusList.Add(node.CurrentStat); } //ThreadRunModel palletBindThread = new ThreadRunModel("工装板绑定"); //palletBindThread.TaskInit(); //CtlNodeBaseModel palletBindNode = GetNodeByID("6001"); //if(palletBindNode != null && palletBindNode.NodeEnabled) //{ // palletBindThread.AddNode(palletBindNode); //} //this.threadList.Add(palletBindThread); //4 plc通信线程初始化 //5 历史数据清理线程 historyDataClearThread = new ThreadBaseModel("历史数据集清理"); historyDataClearThread.SetThreadRoutine(ClearHistoryLoop); historyDataClearThread.LoopInterval = 60000; historyDataClearThread.TaskInit(); //5 通信对象分配 asrsCtlPresenter.PlcRWs = this.plcRWs; asrsCtlPresenter.RfidRWs = this.rfidRWs; asrsCtlPresenter.BarcodeRWs = this.barcodeRWList; foreach (AsrsCtlModel asrsCtl in asrsCtlPresenter.AsrsCtls) { asrsCtl.MesAcc = this.MesAcc; if (asrsCtl.HouseName == AsrsModel.EnumStoreHouse.A1库房.ToString()) { asrsCtl.dlgtGetTaskTorun = GetCheckoutOfA1; } } if (!asrsCtlPresenter.AsrsCommCfg()) { return(false); } //view.InitNodeMonitorview(); bool re = asrsCtlPresenter.DevStatusRestore(); if (!re) { return(false); } return(true); }
private bool ParseCommDevCfg(XElement commDevRoot, ref string reStr) { try { //1 PLC XElement plcRoot = commDevRoot.Element("PLCCfg"); plcRWs = new List <IPlcRW>(); IEnumerable <XElement> plcXES = plcRoot.Elements("PLC"); foreach (XElement plcXE in plcXES) { string connStr = plcXE.Value.ToString(); int db1Len = 100, db2Len = 100; db1Len = int.Parse(plcXE.Attribute("db1Len").Value.ToString()); db2Len = int.Parse(plcXE.Attribute("db2Len").Value.ToString()); int plcID = int.Parse(plcXE.Attribute("id").Value.ToString()); EnumPlcCata plcCata = EnumPlcCata.FX5U; if (plcXE.Attribute("cata") != null) { string strPlcCata = plcXE.Attribute("cata").Value.ToString(); plcCata = (EnumPlcCata)Enum.Parse(typeof(EnumPlcCata), strPlcCata); } PLCRwMCPro plcRW = new PLCRwMCPro(plcCata, db1Len, db2Len); // PLCRwMCPro2 plcRW = new PLCRwMCPro2(db1Len, db2Len); plcRW.ConnStr = plcXE.Value.ToString(); plcRW.PlcID = plcID; plcRWs.Add(plcRW); } //2 rfid XElement rfidRootXE = commDevRoot.Element("RfidCfg"); IEnumerable <XElement> rfidXES = rfidRootXE.Elements("RFID"); this.rfidRWs = new List <IrfidRW>(); foreach (XElement rfidXE in rfidXES) { byte id = byte.Parse(rfidXE.Attribute("id").Value.ToString()); string addr = rfidXE.Attribute("CommAddr").Value.ToString(); string[] strAddrArray = addr.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries); string ip = strAddrArray[0]; ushort port = ushort.Parse(strAddrArray[1]); //WqwlRfidRW rfidRW = new WqwlRfidRW(EnumTag.TagEPCC1G2, id, ip, port); WqRfidUdp rfidRW = new WqRfidUdp(EnumTag.TagEPCC1G2, id, ip, port, (uint)(9000 + id)); //rfidRW.HostIP = "192.168.1.251"; // rfidRW.HostPort = (uint)(9000+id); //SygoleHFReaderIF.HFReaderIF readerIF = new SygoleHFReaderIF.HFReaderIF(); //SgrfidRW rfidRW = new SgrfidRW(id); //rfidRW.ReaderIF = readerIF; //rfidRW.ReaderIF.ComPort = commPort; rfidRWs.Add(rfidRW); } //3 条码枪 XElement barcoderRootXE = commDevRoot.Element("BarScannerCfg"); IEnumerable <XElement> barcodes = barcoderRootXE.Elements("BarScanner"); barcodeRWList = new List <IBarcodeRW>(); foreach (XElement barcodeXE in barcodes) { byte id = byte.Parse(barcodeXE.Attribute("id").Value.ToString()); string commPort = barcodeXE.Attribute("CommAddr").Value.ToString(); BarcodeRWHonevor barcodeReader = new BarcodeRWHonevor(id); barcodeReader.TriggerMode = EnumTriggerMode.序命令触发; //System.IO.Ports.SerialPort comPort = new System.IO.Ports.SerialPort(commPort); //comPort.BaudRate = 115200; //comPort.DataBits = 8; //comPort.StopBits = System.IO.Ports.StopBits.One; //comPort.Parity = System.IO.Ports.Parity.None; barcodeReader.ComPortObj.PortName = commPort; barcodeReader.ComPortObj.BaudRate = 115200; barcodeReader.ComPortObj.DataBits = 8; barcodeReader.ComPortObj.StopBits = System.IO.Ports.StopBits.One; barcodeReader.ComPortObj.Parity = System.IO.Ports.Parity.None; barcodeRWList.Add(barcodeReader); } //4 杭可装载服务器 XElement hkFillSvcXECfg = commDevRoot.Element("HKFillServerCfg"); string hkSvcIP = "127.0.0.1"; int hkSvcPort = 13535; if (hkFillSvcXECfg != null) { foreach (XElement hkXE in hkFillSvcXECfg.Elements("HkServer")) { int hkID = int.Parse(hkXE.Attribute("id").Value.ToString()); hkSvcIP = hkXE.Attribute("ip").Value.ToString(); hkSvcPort = int.Parse(hkXE.Attribute("port").Value.ToString()); HKAccess hk = new HKAccess(hkID, hkSvcIP, hkSvcPort); hk.RecvTimeOut = 5000; hkAccessList.Add(hk); } } string ocvDBConn = hkFillSvcXECfg.Element("HkOCVDB").Attribute("conn").Value.ToString(); // "Data Source = 192.168.100.20;Initial Catalog=SRANCH;User ID=L_Guest;Password=Guest@123;"; ocvAccess = new OcvAccess(ocvDBConn, 36); CommDevConnect(); return(true); } catch (Exception ex) { reStr = ex.ToString(); return(false); } }