/// <summary> /// Generate Tree View /// </summary> private void PopulateTreeView() { var xlApp = new Excel.Application(); var xlWorkbook = OpennessHelper.GetExcelFile(networkListPath, xlApp); foreach (Excel.Worksheet xlWorksheet in xlWorkbook.Worksheets) { string sheetName = xlWorksheet.Name; var matrix = OpennessHelper.ExcelToMatrix(xlWorksheet); if (OpennessHelper.IsNetworkList(matrix)) { Worksheets.Add(sheetName); } } xlWorkbook.Close(0); xlApp.Quit(); var projectTreeView = new TreeView(); foreach (var ws in Worksheets) { TreeViewItem tvi = new TreeViewItem { Tag = ws, Header = new CheckBox() { Content = new TextBlock() { Text = ws }, Tag = ws } }; projectTreeView.Items.Add(tvi); } if (projectTreeView.Items.Count == 0) { TreeViewItem tvi = new TreeViewItem { Header = "Excel does not contain a valid Worksheet" }; projectTreeView.Items.Add(tvi); BtnEnabled = false; } ProjectTree.Refresh(projectTreeView); }
/// <summary> /// Add PLC Tags in PLC DB file /// </summary> private void AddPlcDbTags(string robName) { Excel.Application xlApp = new Excel.Application(); Workbook xlWorkBook = OpennessHelper.GetExcelFile(PlcDBPath, xlApp); Worksheet xlWorksheet = null; if (xlWorkBook == null) { return; } try { xlWorksheet = xlWorkBook.Sheets["PLC Tags"]; } catch (Exception) { MessageBox.Show("Could not find sheet named \"PLC Tags\" in file: \"" + PlcDBPath + "\"\n\nPLC DB Tags will not be imported.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); xlWorkBook.Close(0); xlApp.Quit(); return; } int lastRow = xlWorksheet.Cells.Find("*", System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlPrevious, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value).Row; object[,] matrix = OpennessHelper.ExcelToMatrix(xlWorksheet); //SEARCH TAGS IN EXCEL AND ADD TO ROBBASE for (int row = 1; row <= lastRow; row++) { if (Convert.ToString(matrix[row, 1]) != null) //If Column 'A' is not Null { //Check if name equals Robot Name if (Convert.ToString(matrix[row, 1]).Contains(robName)) { string symbolic = Convert.ToString(matrix[row, 1]); string datatype = Convert.ToString(matrix[row, 3]); string address = Convert.ToString(matrix[row, 4]); string comment = Convert.ToString(matrix[row, 5]); RobotBase rb = new RobotBase(symbolic, datatype, address, comment); if (address.Contains('A')) // If startaddress is output { int outputIndexRob = -1; outputIndexRob = robBase[0].FindIndex(a => a.Address.Equals(rb.Address)); if (outputIndexRob != -1) { robBase[0][outputIndexRob] = rb; } } else if (address.Contains('E')) // If startaddress is input { int inputIndexRob = -1; inputIndexRob = robBase[1].FindIndex(a => a.Address.Equals(rb.Address)); if (inputIndexRob != -1) { robBase[1][inputIndexRob] = rb; } } } } } xlWorkBook.Close(0); xlApp.Quit(); }
/// <summary> /// Event handler generate hardware button click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GenerateHardwareCommand_Executed(object sender, EventArgs e) { List <string> sheetsToUse = GetSelectedSheets(); if (!StartConditions(sheetsToUse)) { return; } TaskScheduler uiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); Task.Factory.StartNew(() => { WindowEnabled = false; Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook = OpennessHelper.GetExcelFile(networkListPath, xlApp); Excel.Worksheet xlWorksheet; List <AddressData> addressDataList = new List <AddressData>(); //1st IP 2nd Start Address List <DeviceData> DeviceDataList = new List <DeviceData>(); List <int> pneuList = new List <int>(); List <int> t200List = new List <int>(); List <int> motorsList = new List <int>(); List <int> murrDi6List = new List <int>(); List <int> listCoupler = new List <int>(); List <List <string> > HWInformation = null; List <string> linesL = new List <string>(); List <string> delimL = new List <string>(); UpdateStatus("Generating...", uiScheduler); List <int> garetelistPages = OpennessHelper.GetGaretelistePages(eplanPath); //UpdateStatus("Getting devices from Worksheets...", uiScheduler); //GET ALL THE DEVICES FROM EXCEL FILE foreach (var sheet in sheetsToUse) { xlWorksheet = xlWorkbook.Sheets[sheet]; DeviceDataList = OpennessHelper.GetAllDevicesNetworkList(xlWorksheet); } //UpdateStatus("Getting Library...", uiScheduler); xlWorkbook.Close(0); xlApp.Quit(); MasterCopySystemFolder MasterCopy = null; Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() => { if (FromPathLibrary == Visibility.Visible) { MasterCopy = OpennessHelper.GetHWMasterCopies(tiaPortal, _libraryPath, true); } else { MasterCopy = OpennessHelper.GetHWMasterCopies(tiaPortal, _selectedLib, false); } })); //UpdateStatus("Creating Hardware...", uiScheduler); Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() => { using (var access = tiaPortal.ExclusiveAccess("Creating Hardware...")) { foreach (DeviceData device in DeviceDataList) { string type = device.FGroup.Substring(3, 3); switch (type) { case "TRR": OpennessHelper.InsertHWOperatorDoor(device.deviceName, device.addressData.IPAdress, device.addressData.StartAddress, tiaPortalProject, MasterCopy); //ALBANY break; case "RB_": if (device.deviceName.Substring(14, 3) == "-kf") { OpennessHelper.InsertHWRobot(device.deviceName, device.addressData.IPAdress, device.addressData.StartAddress, tiaPortalProject); //ROBOT } else { OpennessHelper.InsertHWRobotScalance(device.deviceName, device.addressData.IPAdress, tiaPortalProject); //ROBOT SWITCH } break; case "STU": ///SAFETY DOOR OpennessHelper.InsertHWEuchner(device.deviceName, device.addressData.IPAdress, device.addressData.StartAddress, !device.option, tiaPortalProject, MasterCopy); break; case "VRF": ///FESTO case "DTW": case "LME": case "VR_": case "GST": case "LE_": case "VRX": case "SAE": case "VRE": case "ABS": pneuList = new List <int>(); // Reset List HWInformation = OpennessHelper.HWInfo(eplanPath, device.FGroup, device.identifier, garetelistPages); if (HWInformation != null) // If List has elements { int count16DI = 0, countDoH = 0, countFDI = 0, countFDO = 0; foreach (List <string> info in HWInformation) { string part = OpennessHelper.GetHWPart(info[1]); if (part.Contains("16DI")) { count16DI++; } else if (part.Contains("DO-H")) { countDoH++; } else if (part.Contains("F8DI")) { countFDI++; } else if (part.Contains("FVDO")) { countFDO++; } } pneuList.Add(count16DI); // 16DI pneuList.Add(countDoH); // DO-H pneuList.Add(countFDI); // FDI pneuList.Add(countFDO); // FDO } else { pneuList.Add(1); //1 - 16DI pneuList.Add(1); //1 - DO-H pneuList.Add(1); //1 - FDI pneuList.Add(1); //1 - FDO } if (device.deviceName.Substring(12, 2) != "ta") { OpennessHelper.InsertHWPneumatic(device.deviceName, device.addressData.IPAdress, device.addressData.StartAddress, pneuList, tiaPortalProject); } break; case "LS_": OpennessHelper.InsertHwPLS(device.deviceName, device.addressData.IPAdress, device.addressData.StartAddress, tiaPortalProject, device.option, MasterCopy); //PLS CAN BE SICK S3000 or KEYENCE break; case "BR_": case "BS_": case "BRT": if (device.deviceName.Substring(15, 2) == "kf") { OpennessHelper.InsertHWKP32F(device.deviceName, device.addressData.IPAdress, device.addressData.StartAddress, tiaPortalProject, MasterCopy); } if (device.deviceName.Substring(15, 2) == "xf") { OpennessHelper.InsertHWScalanceKP32F(device.deviceName, device.addressData.IPAdress, tiaPortalProject, MasterCopy); } break; //case "ek-": //et200F or LocBox case "PMF": //et200s case "EE_": //gateway or et200sp t200List = new List <int>(); // Reset List t200List.Add(1); // 1 - 8DI t200List.Add(1); // 1 - 16DI t200List.Add(1); // 1 - 8DQ t200List.Add(1); // 1 - 16DQ t200List.Add(1); // 1 - F-8DI t200List.Add(1); // 1 - F-8DQ t200List.Add(1); // 1 - SvModule OpennessHelper.InsertHWT200(device.deviceName, device.addressData.IPAdress, device.addressData.StartAddress, t200List, tiaPortalProject); break; case "WAS": // vi switch OpennessHelper.InsertHWEuchnermgb(device.deviceName, device.addressData.IPAdress, tiaPortalProject); break; case "ZV_": case "RF_": case "QF_": case "PNE": //MURR case "SPX": murrDi6List = new List <int>(); murrDi6List.Add(1); // IO-Link Output murrDi6List.Add(1); // IO-Link input/output if (device.terminalType.Contains("FDI8")) { OpennessHelper.InsertHWMURRFDI8FDO4MVK(device.deviceName, device.addressData.IPAdress, device.addressData.StartAddress, tiaPortalProject); } else if (device.terminalType.Contains("DI6")) { OpennessHelper.InsertHWMURRDI6DO6MVK(device.deviceName, murrDi6List, device.addressData.IPAdress, device.addressData.StartAddress, tiaPortalProject); } else if (device.terminalType.Contains("Lenze")) { motorsList = new List <int>(); // Reset List motorsList.Add(1); // PZD motorsList.Add(1); // Safety OpennessHelper.InsertHWLenze(device.deviceName, device.addressData.IPAdress, device.addressData.StartAddress, motorsList, tiaPortalProject, "RF_"); } break; case "KH_": case "RF2": break; //Motores case "HE_": case "HER": case "FX_": case "HTS": motorsList = new List <int>(); // Reset List motorsList.Add(1); // PZD motorsList.Add(1); // Safety OpennessHelper.InsertHWLenze(device.deviceName, device.addressData.IPAdress, device.addressData.StartAddress, motorsList, tiaPortalProject, type); break; case "DGT": OpennessHelper.InsertHWIDENTControl(device.deviceName, device.addressData.IPAdress, tiaPortalProject); break; case "DGC": OpennessHelper.InsertHWMV5(device.deviceName, device.addressData.IPAdress, tiaPortalProject); break; case "EV_": //Coupler X1 case "XEV": //Coupler X2 listCoupler = new List <int>(); listCoupler.Add(1); // In 32 Bytes listCoupler.Add(1); // Out 32 Bytes listCoupler.Add(1); // PROFIsafe in/out 6 byte listCoupler.Add(1); // PROFIsafe in/out 12 Byte OpennessHelper.InsertHWCoupler(device.deviceName, device.addressData.IPAdress, device.addressData.StartAddress, listCoupler, type, tiaPortalProject); break; //CONTINUE WITH ALL DEVICES FROM THE DEVICELIST FROM NETWORK LIST default: break; } } } })); }).ContinueWith(t2 => { WindowEnabled = true; UpdateStatus("Done!", uiScheduler); }); }