private void button1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                SaveFileDialog sav = new SaveFileDialog();
                sav.Filter = "*.hex|*.hex|*.*|*'.*";
                DialogResult res = sav.ShowDialog();
                if (res == DialogResult.OK)
                {
                    try
                    {
                        byte[] blk = myConn.PLCGetBlockInMC7(listBox1.SelectedItem.ToString());

                        System.IO.FileStream _FileStream = new System.IO.FileStream(sav.FileName,
                                                                                    System.IO.FileMode.Create,
                                                                                    System.IO.FileAccess.Write);
                        _FileStream.Write(blk, 0, blk.Length);
                        _FileStream.Close();

                        MessageBox.Show("Block " + listBox1.SelectedItem.ToString() + " saved to: " + sav.FileName);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: " + ex.Message);
                    }
                }
            }
        }
Beispiel #2
0
        private void button4_Click(object sender, EventArgs e)
        {
            myConn = new PLCConnection("SimpleCSharpDemonstrationConnection");
            myConn.Connect();

            var db = myConn.PLCGetBlockInMC7("DB99");
            MessageBox.Show("DB:" + Encoding.ASCII.GetString(db));
            myConn.PLCPutBlockFromMC7toPLC("DB98", db);
        }
Beispiel #3
0
        private void button4_Click(object sender, EventArgs e)
        {
            myConn = new PLCConnection("SimpleCSharpDemonstrationConnection");
            myConn.Connect();

            var db = myConn.PLCGetBlockInMC7("DB99");

            MessageBox.Show("DB:" + Encoding.ASCII.GetString(db));
            myConn.PLCPutBlockFromMC7toPLC("DB98", db);
        }
        private void BlockList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            string nm = BlockList.SelectedItem.ToString();

            if (dispatcherTimer != null)
            {
                dispatcherTimer.Stop();
            }
            if (myDiag != null)
            {
                myDiag.Close();
                myDiag = null;
            }
            myBlock = MC7Converter.GetAWLBlock(_myconn.PLCGetBlockInMC7(nm), 0, myblkFld);
            if (myBlock != null)
            {
                if (myBlock.BlockType == PLCBlockType.DB)
                {
                    toppanel.ClearValue(HeightProperty);
                    toppanel.ClearValue(DockPanel.DockProperty);
                    textEditor.Visibility = System.Windows.Visibility.Collapsed;
                }
                else
                {
                    toppanel.Height = 160;
                    toppanel.SetValue(DockPanel.DockProperty, Dock.Top);
                    textEditor.Visibility = System.Windows.Visibility.Visible;
                }
                textEditor.Text    = myBlock.ToString();
                blockName.Content  = nm;
                Upload.IsEnabled   = true;
                Optimize.IsEnabled = true;
                Diag.IsEnabled     = true;

                if (myBlock.BlockType == PLCBlockType.DB)
                {
                    myTree.DataContext = ((S7DataBlock)myBlock).Structure.Children;
                }
                else
                {
                    myTree.DataContext = ((S7FunctionBlock)myBlock).Parameter.Children;
                }
            }
        }
Beispiel #5
0
        private void cmdDownload_Click(object sender, RoutedEventArgs e)
        {
            string fldname = lblFolder.Text;

            myConn.Connect();

            foreach (string selectedBlock in lstBlocks.SelectedItems)
            {
                var blk = myConn.PLCGetBlockInMC7(selectedBlock);

                string       file = Path.Combine(fldname, selectedBlock + ".blk");
                BinaryWriter wrt  = new BinaryWriter(File.Open(file, FileMode.Create));

                wrt.Write(blk);
                wrt.Close();

                LoadFiles();
            }

            myConn.Disconnect();
        }
Beispiel #6
0
 public Block GetBlock(string BlockName)
 {
     byte[] tmp = Connection.PLCGetBlockInMC7(BlockName);
     return(MC7Converter.GetAWLBlock(tmp, Project != null ? (int)Project.ProjectLanguage : 0, Parent as S7ProgrammFolder));
 }
        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");
            }
        }