dotnetprojects / DotNetSiemensPLCToolBoxLibrary

Library to Access Siemens PLCs and Step5/Step7 Project Files
GNU Lesser General Public License v2.1
375 stars 194 forks source link

how read the IP address for PLC from Hardware? #18

Closed SevenMag closed 10 years ago

SevenMag commented 10 years ago

wie Sie die IP-Adresse der PLC von Hardware lesen?

SevenMag commented 10 years ago

I'm found number Rack and Slot for CP and CPU (3xx and 4xx) in file HOBJECT1.DBF column SUBSTATN is number rack, column MODULN is slot. checked in more S7 projects with H-system. You can add to LibNoDaveConnectionLibrary ?

jogibear9988 commented 10 years ago

Have you also find out where the IP is stored?

SevenMag commented 10 years ago

I am looking for. But it's not easy.

Ich bin für. Aber es ist nicht einfach.

jogibear9988 commented 10 years ago

Ich glaube die sind eher im Ordner CONN... also nicht bei der Hardware! Aber sicher bin Ich da nicht...

jogibear9988 commented 10 years ago

I've also tried again. I used Winmerge, and compared two projects after changeing a IP, but I had no success

SevenMag commented 10 years ago

Ich glaube die sind eher im Ordner CONN... also nicht bei der Hardware!

No. IP address is in file \S7Netze\S7NONFGX.tab as hex to string. exsample: ip = 192.168.2.200; string = "C0A802C8"; file S7NONFGX.tab has this string, but many times. Where is the offset for each CPFolder I have not found.

jogibear9988 commented 10 years ago

The Byte before the IP Adress String is the Length of the String.

SevenMag commented 10 years ago

The Byte before the IP Adress String is the Length of the String.

Pascal? This file also has mask and MAC-address. When save hardware without changing the file changes.

jogibear9988 commented 10 years ago

Pascal? what do you mean?

SevenMag commented 10 years ago

Pascal has string as: first byte is length, the rest up to 255 bytes is text. it simply washed. I have a few ideas on this file, I will try

SevenMag commented 10 years ago

I'm disassembled file S7NONFGX.DLL, but that does not found.

jogibear9988 commented 10 years ago

What do you mean?

SevenMag commented 10 years ago

File S7NONFGX.DLL is the only file that has a string of "S7Netze", then it reads the file "\S7Netze\S7NONFGX.tab", but in this file I could not find how to read this structure with IP, mask and MAC.

jogibear9988 commented 10 years ago

here is also little bit info:

http://www.sps-forum.de/hochsprachen-opc/73225-s7-projektdateien-ip-adressen-auslesen-2.html#post509151

SevenMag commented 10 years ago

so einfach? bravo!

SevenMag commented 10 years ago

I found for the CP: IP address, MAC, mask and router, but only for simple CP. For 6GK7443-1EX20-0XE0 ( which has 2 Ethernet ) compliance can not find.

SevenMag commented 10 years ago

I'm a little confused. made changes in two pull Requests.

jogibear9988 commented 10 years ago

I will modifie your changes a little bit, because for Example a CPU or PG can have more than one Network Interface...

SevenMag commented 10 years ago

Good. CP 6GK7443-1EX20-0XE0 has two network interface, but not fill this code.

jogibear9988 commented 10 years ago

I need the code of "IndexOfByteArray"

SevenMag commented 10 years ago

ups. sorry. something like this:

    public int IndexOfByteArray(byte[] array, byte[] pattern, int offset, int maxLen)
    {
        int success = 0;
        int length = array.Length;
        for (int i = offset; i < length; i++)
        {
            if (array[i] == pattern[success])
                success++;
            else if ( success > 0 )
            {
                ii--;
                success = 0;
            }
            if (pattern.Length == success)
                return i - pattern.Length + 1;
             if ( --maxLen == 0 ) return -1;
        }
        return -1;
    }
SevenMag commented 10 years ago

more:

      if (cp.IP != ip) 

always is TRUE. need change to

     if (cp.IP.ToString() != ip.ToString() )
SevenMag commented 10 years ago
  1. why CP is added only when TobjTyp == 1314972? I have project with row["TOBJTYP"] is 1314972 and 11314865, so the draft CPFolder was empty.
  2. file \s7wb53ax\HRELATI1.DBF: row["TOBJID"] need to remember when row["RELID"] is equal to 64, otherwise TobjId is not valid.
jogibear9988 commented 10 years ago

in my test project every cp is added twice (lean 340) so i looked in the hrelatio file and se, i have two entrys for every cp. but i will overwoek it, i also see in the hobject dbf in this folder also the ports seem to be in that file... i will look to repair it, maybe today, or tomorrow....

SevenMag commented 10 years ago

Today I downloaded the new version, in my project, he showed the CPFolder.Count = 0, I removed the condition "if (x.TobjTyp == 1314972)", the CP appeared, but without Network. Corrected as I sent yesterday, appeared Network. Add "pull Requests" with my changes?

SevenMag commented 10 years ago

I can send the project on which I am trying to

jogibear9988 commented 10 years ago

why is your network info missing? i changed nothing on your reading code!

jogibear9988 commented 10 years ago

i mean nothing functional!

SevenMag commented 10 years ago

in "//Get The CP Folders" i'm add code:

            int sobjid;
            foreach (DataRow row in dbfTbl.Rows)
            {
                if (!(bool)row["DELETED_FLAG"] || _showDeleted)
                {
                    if ((int)row["RELID"] == 64)
                    {
                        sobjid = (int)row["SOBJID"];
                        var cp = CPFolders.FirstOrDefault(x => x.ID == sobjid);
                        if (cp != null)
                            cp.TobjId = (int)row["TOBJID"];
                    }
                }
            }

you do not have this

SevenMag commented 10 years ago

Yes!!!!!! I found a match for the CP with 2 network interfaces.

SevenMag commented 10 years ago

twoip

jogibear9988 commented 10 years ago

With your Code, and remove my x.TobjId = Convert.ToInt32(row["TOBJID"]); I get not CP Folder!

I look for it at the weekend...

jogibear9988 commented 10 years ago

Maybe you can send me also your Project...

SevenMag commented 10 years ago

I sent a test project and 2 file with the new changes for reading in the Multi-Interface CP Please send me your project, I'll see why we read differently IP

SevenMag commented 10 years ago

I sent the file Step7ProjectV5.cs it has 3 lines:

                    byte[] bbb = new byte[1960];
                    Array.Copy(completeBuffer, position, bbb, 0, 1960);
                    File.WriteAllBytes(@"d:\Temp\Temp\" + number + ".txt", bbb);

they help to find small changes, but in the release are not needed.

SevenMag commented 10 years ago

hello received a project Test2. looked. Very strange situation, in my project was simple. If you look in the reverse order, then: S7NONFGX.tab file has 5 structures beginning with 0x03, 0x52, 0x14, 0x00, ie 5 addresses. these structures number: 3.4, 6, 7, 8. file \s7wb53ax\HRELATI1.DBF with row["RELID"] == 64 only 4 addresses: 4, 6, 7, 8; file \s7hssiox\HRELATI1.DBF(for multi-Interface) with row ["RELID"] == 64 has address 3. but how to compare the values ​​of CP and it is hard to find. and more: project Test2 has 8 CP, may be 3 CP is profibus.

I hope these thoughts as they will help. Ich hoffe, dass diese Gedanken, wie sie helfen

SevenMag commented 10 years ago

I now checked my code for 30 different projects, always determine the correct IP address. For project Test2 I had an idea how to compare, but to test this idea a little project.

impoetk commented 10 years ago

Which code you use for reading the IP address?? I get the cpufolder but the property NetworkInterfaces is always null. Should I run some code before to parse the addresses?

jogibear9988 commented 10 years ago

Yes SvenMag, can you create a Git Pull Request, with the changes yu have to the current Master Branch? I've now reverted my changes to reading from the hrelatio.dbf. I will add your Code that works for your Projects, still I've no time at the moment to look into this.

SevenMag commented 10 years ago

I'm change my project (https://github.com/SevenMag/DotNetSiemensPLCToolBoxLibrary) for read IP. now read IP for CPU with ethernet, for CP with 2 Ethernet and another CP. Please testing.

jogibear9988 commented 10 years ago

I send you a Project wich does not work. There are read now 4 CP's (it only has two), in my Tree in the Toolbox, only the two are shon, but the other two get the IPs. I think we have two combine this two CP entrys in any way! And the IP of the CPU is also not read!

SevenMag commented 10 years ago

I'm add to CPFolder one more CPFolder as SubModul, see it. CPU in project Test2 (sent me an e-mail) I read IP normal. maybe it's the other project?

SevenMag commented 10 years ago

may be a little to alter the reading of the DB-files. In each folder, you first need to read HOBJECT1.DBF and then HRELATI1.DBF. UNITID in HRELATI1 is ID in the HOBJECT1.DBF

SevenMag commented 10 years ago

When HW Config shows two CP, but raed 4 this is may be because the 2 Ethernet CP and 2 CP Profibus. We must unite and do 2 NetworkInterfaces for each CP

jogibear9988 commented 10 years ago

Can I send you a Example Project? (I thought I did, but I don't find your EMail adress, i replied to github...)

SevenMag commented 10 years ago

Yes. send to berlyakov.ev@npoa.mmk.ru

SevenMag commented 10 years ago

I have not received anything.

SevenMag commented 10 years ago

We have found for the networkInterface: IP, MAC, Router, Name; I have found a property useIP, useISO, useROUTER; There are many options, I found 32. But I think others do not want, or something you want?

jogibear9988 commented 10 years ago

I send it to you now...

jogibear9988 commented 10 years ago

If there are more options you read out, feel free to create Properties and fill them...