private void button16_Click(object sender, EventArgs e) { MessageBox.Show(String.Join(",", myConn.PLCListBlocks(PLCBlockType.AllEditableBlocks).ToArray())); string newVal = ""; System.Windows.Forms.DialogResult ret = Form1.InputBox("Block löschen", "Welchen Block?", ref newVal); if (ret == DialogResult.OK) { myConn.PLCDeleteBlock(newVal); MessageBox.Show(String.Join(",", myConn.PLCListBlocks(PLCBlockType.AllEditableBlocks).ToArray())); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { if (_myconn == null) { _myconn = new PLCConnection(_connname); _myconn.Connect(); foreach (string itm in _myconn.PLCListBlocks(PLCBlockType.AllEditableBlocks)) { BlockList.Items.Add(itm); } } else { if (dispatcherTimer != null) { dispatcherTimer.Stop(); } if (myDiag != null) { myDiag.Close(); myDiag.RemoveDiagnosticData(); textEditor.Text = myBlock.ToString(); } _myconn.Dispose(); _myconn = null; myDiag = null; BlockList.Items.Clear(); blockName.Content = "FCxx"; Upload.IsEnabled = false; Optimize.IsEnabled = false; Diag.IsEnabled = false; } }
private void Button_Click_1(object sender, RoutedEventArgs e) { if (_myconn == null) { _myconn = new PLCConnection(_connname); _myconn.Connect(); foreach (string itm in _myconn.PLCListBlocks(PLCBlockType.AllEditableBlocks)) BlockList.Items.Add(itm); } else { if (dispatcherTimer!=null) dispatcherTimer.Stop(); if (myDiag != null) { myDiag.Close(); myDiag.RemoveDiagnosticData(); textEditor.Text = myBlock.ToString(); } _myconn.Dispose(); _myconn = null; myDiag = null; BlockList.Items.Clear(); blockName.Content = "FCxx"; Upload.IsEnabled = false; Optimize.IsEnabled = false; Diag.IsEnabled = false; } }
private void cmdLoadBlockList_Click(object sender, RoutedEventArgs e) { myConn.Connect(); var blks = myConn.PLCListBlocks(PLCBlockType.AllEditableBlocks); lstBlocks.ItemsSource = blks; myConn.Disconnect(); }
private void DownloadBlock_Load(object sender, EventArgs e) { try { myConn = new PLCConnection(ConnectionName); label1.Text = ConnectionName + "\r\n" + (new PLCConnectionConfiguration(ConnectionName)).ToString(); myConn.Connect(); listBox1.Items.AddRange(myConn.PLCListBlocks(PLCBlockType.AllEditableBlocks).ToArray()); //myConn.PLCSendPassword("admin"); } catch (Exception ex) { MessageBox.Show(ex.Message); this.Close(); } }
private void DownloadBlock_Load(object sender, EventArgs e) { try { myConn = new PLCConnection(ConnectionName); label1.Text = ConnectionName + "\r\n" + (new PLCConnectionConfiguration(ConnectionName)).ToString(); myConn.Connect(); listBox1.Items.AddRange(myConn.PLCListBlocks(PLCBlockType.AllEditableBlocks).ToArray()); //myConn.PLCSendPassword("admin"); } catch(Exception ex) { MessageBox.Show(ex.Message); this.Close(); } }
public List <ProjectBlockInfo> readPlcBlocksList() { SymbolTable symtab = null; if (((S7ProgrammFolder)Parent) != null) { symtab = (SymbolTable)((S7ProgrammFolder)Parent).SymbolTable; } List <ProjectBlockInfo> retVal = new List <ProjectBlockInfo>(); Connection.Connect(); List <string> blks = Connection.PLCListBlocks(PLCBlockType.AllBlocks); foreach (var blk in blks) { ProjectPlcBlockInfo tmp = new ProjectPlcBlockInfo(); tmp.ParentFolder = this; if (blk.Substring(0, 2) == "DB") { tmp.BlockType = PLCBlockType.DB; tmp.BlockNumber = Convert.ToInt32(blk.Substring(2)); } else if (blk.Substring(0, 2) == "OB") { tmp.BlockType = PLCBlockType.OB; tmp.BlockNumber = Convert.ToInt32(blk.Substring(2)); } else if (blk.Substring(0, 2) == "FC") { tmp.BlockType = PLCBlockType.FC; tmp.BlockNumber = Convert.ToInt32(blk.Substring(2)); } else if (blk.Substring(0, 2) == "FB") { tmp.BlockType = PLCBlockType.FB; tmp.BlockNumber = Convert.ToInt32(blk.Substring(2)); } else if (blk.Substring(0, 3) == "SFC") { tmp.BlockType = PLCBlockType.SFC; tmp.BlockNumber = Convert.ToInt32(blk.Substring(3)); } else if (blk.Substring(0, 3) == "SFB") { tmp.BlockType = PLCBlockType.SFB; tmp.BlockNumber = Convert.ToInt32(blk.Substring(3)); } else if (blk.Substring(0, 3) == "SDB") { tmp.BlockType = PLCBlockType.SDB; tmp.BlockNumber = Convert.ToInt32(blk.Substring(3)); } /* * if (symtab != null) * { * SymbolTableEntry sym = symtab.GetEntryFromOperand(tmp.ToString()); * if (sym != null) * tmp.Symbol = sym.Symbol; * } */ retVal.Add(tmp); } return(retVal); }
private void button1_Click(object sender, EventArgs e) { var lst = myConn.PLCListBlocks(PLCBlockType.DB); listBox1.Items.AddRange(lst.ToArray()); }
static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine(); Console.WriteLine("Bitte so starten:"); Console.WriteLine(); Console.WriteLine("BackupS7 Configfile Zielverzeichnis"); Console.WriteLine(); Console.ReadLine(); } else { Console.WriteLine(); Console.WriteLine("Creating Directory..."); var configFile = args[0]; var targetDirectory = Path.Combine(Environment.CurrentDirectory, args[1]); var text = File.ReadAllText(configFile); var config = JsonConvert.DeserializeObject <Config>(text); Directory.CreateDirectory(targetDirectory); Console.WriteLine("Connecting to PLC..."); var connection = new PLCConnection(new PLCConnectionConfiguration("BackupS7", LibNodaveConnectionConfigurationType.ObjectSavedConfiguration) { ConnectionType = LibNodaveConnectionTypes.ISO_over_TCP, CpuIP = config.Ip, CpuRack = config.Rack, CpuSlot = config.Slot }); connection.Connect(); var szlDat = connection.PLCGetSZL(0x0111, 1); if (szlDat.SZLDaten.Length > 0) { xy11Dataset xy11Szl = szlDat.SZLDaten[0] as xy11Dataset; if (xy11Szl != null) { Console.WriteLine("Connected, MLFB: " + xy11Szl.MlfB); } } Console.WriteLine("Read Blocks..."); var existingBlocks = connection.PLCListBlocks(PLCBlockType.AllEditableBlocks); var backupBlocks = new List <string>(); if (config.BackupBlocks != null) { foreach (var b in config.BackupBlocks) { var txt = b.Trim().ToUpper().Replace(" ", ""); if (txt.Contains("-")) { var range = txt.Split('-'); var type = range[0].Substring(0, 2); var start = int.Parse(range[0].Substring(2)); var end = int.Parse(range[1].Substring(2)); backupBlocks.AddRange(Enumerable.Range(start, (end - start) + 1).Select(x => type + x)); } else { backupBlocks.Add(txt); } } } Console.WriteLine("Backup Blocks..."); foreach (var b in existingBlocks) { bool backUp = false; if (config.BackupType.HasFlag(BackupType.Datablocks) && b.StartsWith("DB")) { backUp = true; } if (config.BackupType.HasFlag(BackupType.Functions) && b.StartsWith("FC")) { backUp = true; } if (config.BackupType.HasFlag(BackupType.FunctionBlocks) && b.StartsWith("FB")) { backUp = true; } if (backupBlocks.Contains(b.ToUpper().Trim())) { backUp = true; } if (backUp) { var blk = connection.PLCGetBlockInMC7(b); string file = Path.Combine(targetDirectory, b + ".blk"); BinaryWriter wrt = new BinaryWriter(File.Open(file, FileMode.Create)); wrt.Write(blk); wrt.Close(); } } connection.Disconnect(); Console.WriteLine("Finish"); } }