Пример #1
0
        private void t_Tick(object sender, EventArgs e)
        {
            string ss = "";

            //  ReadArea();
            ss = DateTime.Now.ToString() + "    " + "ddddddd\n";
            TxtDump.AppendText(ss);
            StreamWriter sw = new StreamWriter(@"d:\aa.txt", true);

            sw.WriteLine(ss);
            sw.Close();
        }
Пример #2
0
        private void SaveBlock(string Type_name, string firstname, int type_num)
        {
            string path; //firstName = @"\Saves";
            string number_path;

            StreamWriter output;

            byte[]   Save_Buffer = new byte[65536];
            ushort[] new_List = new ushort[1000];
            int      Count = 1000, i, number, result2, BlockSize = 65536, result1, inforesult;

            Snap7.S7Client.S7BlockInfo Info = new Snap7.S7Client.S7BlockInfo();

            System.IO.DirectoryInfo drInfo = new DirectoryInfo(firstname + Type_name);
            if (!drInfo.Exists)
            {
                drInfo.Create();
            }
            number_path = firstname + Type_name + @"\Number.txt";
            output      = new StreamWriter(number_path);
            if (!File.Exists(number_path))
            {
                File.Create(number_path);
            }
            result1 = Client.ListBlocksOfType(type_num, new_List, ref Count);
            if (result1 == 0)
            {
                TxtDump.Clear();
                for (i = 0; i < Count; i++)
                {
                    number      = Convert.ToInt32(new_List[i]);
                    Save_Buffer = new byte[65536];
                    inforesult  = Client.GetAgBlockInfo(type_num, number, ref Info);
                    if (inforesult == 0)
                    {
                        BlockSize = Info.LoadSize;
                    }
                    output.Write(number + ":" + BlockSize + "\n");
                    Save_Buffer = new byte[BlockSize];
                    result2     = Client.FullUpload(type_num, number, Save_Buffer, ref BlockSize);
                    if (result2 == 0)
                    {
                        path = firstname + Type_name + @"\states" + number.ToString() + ".dat";
                        BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.OpenOrCreate));
                        writer.Write(Save_Buffer);
                        writer.Close();
                    }
                }
                output.Close();
            }
        }
Пример #3
0
        private void Read_Click(object sender, EventArgs e)
        {
            int    Result, c;
            string s;

            int BlockNumber, BlockType, BlockSize;

            BlockType   = Block_Of[comboBox1.SelectedIndex];
            BlockNumber = System.Convert.ToInt32(TxtDB.Text);
            BlockSize   = 65536;
            // Unsafe context: can use pointers here.
            label4.Text = BlockType.ToString();

            Result = Client.FullUpload(BlockType, BlockNumber, Buffer, ref BlockSize);
            ShowResult(Result);
            if (Result == 0)
            {
                //label4.Text = "";
                TxtDump.Clear();
                for (c = 0; c <= BlockSize - 1; c++)
                {
                    s = Convert.ToString(Buffer[c], 16);
                    if (s.Length == 1)
                    {
                        s = "0" + s;
                    }
                    TxtDump.Text = TxtDump.Text + s + " ";
                    //y = y + 1;
                    //if (y == 8)
                    //{
                    //    y = 0;
                    //    Text = Text + "\n";
                    //}
                }
            }
            else
            {
                label4.Text = Result.ToString();
            }
        }
Пример #4
0
        private void LoadBlock(string Type_name, string firstname, int type_num)
        {
            TxtDump.Clear();
            string path;
            string number_path, number, line, size;

            StreamReader output;
            BinaryReader reader_bin;

            byte[] Save_Buffer;
            int    result2, index;

            number_path = firstname + Type_name + @"\Number.txt";
            output      = new StreamReader(number_path);
            while ((line = output.ReadLine()) != null)
            {
                index  = line.LastIndexOf(':');
                number = line.Substring(0, index);

                size = line.Substring(index + 1, line.Length - index - 1);
                path = firstname + Type_name + @"\states" + number + ".dat";
                //label4.Text = path;
                reader_bin  = new BinaryReader(File.OpenRead(path));
                Save_Buffer = new byte[Convert.ToInt32(size)];
                Save_Buffer = reader_bin.ReadBytes(Convert.ToInt32(size));
                reader_bin.Close();
                //label4.Text = Int32.Parse(size).ToString();
                result2 = Client.Download(Convert.ToInt32(number), Save_Buffer, Convert.ToInt32(size));
                ShowResult(result2);
                if (result2 == 0)
                {
                    //label4.Text += "Gut";
                }
                else
                {
                    label4.Text += Type_name + " ";
                }
            }
            output.Close();
        }