Menu

Reading/writing PLC tags from PLC s7-1500

Sev
2016-03-01
2019-02-05
  • Sev

    Sev - 2016-03-01

    Hi all,

    I was wondering if there is any way to read and write data from the PLC tags folder using a custom c# application?

    I have tried using Snap7 which is great tool to use and actually got it working, but only reading and writing data blocks and not tags which I am willing to achieve. Would someone please show me an exmaple on how to do so. Is possible using Snap7?

     

    Last edit: Sev 2016-03-01
  • Sev

    Sev - 2016-03-03

    Any Idea's regarding this subject? I read in order to do this, I might need to setup OPC server which extracts values (I/O) en set and get as well.

    I greatly appreciate any help and assistance, and sorry if I've missed any obvious guides that cover this subject.

     
  • Davide Nardella

    Davide Nardella - 2016-03-03

    Using ReadArea() and WriteArea() you can read/write also Merkers and I/O.
    You cannot do it "by name" but only by Index/Address, the same that you would do using a non siemens-integrated OPC.
    Please refer to pag.104 of the reference manual and also to pag.34 if you are using S71200/1500.

     
  • Sev

    Sev - 2016-03-07

    Thank you for answering! It would be alright if I just could read the address. Not interested in names. Would you please explain what Merkers are? I can't find it anywhere. I have read the manual, but wasn't able to understand how to use it. Sorry I'm new to PLC world :(

    Thank you.

     
  • Sev

    Sev - 2016-03-08

    I have managed to understand what merkers are. But what about reading & writing Input and outputs? such as those.

     

    Last edit: Sev 2016-03-08
  • Davide Nardella

    Davide Nardella - 2016-03-08

    %M0.3 is a Merker Bit whose address (index) is 3
    %M4.3 index is 35 (48+3)
    %I1.0 is a digital input whose index is 8 (1
    8+0)

    To read bits you need ReadArea passing S7WLBit as wordlength and their index as address (the bits are indexed).

    To read analog inputs you need to address their word image into the IPI (process images).

    Please read the manuals.

     
  • Sev

    Sev - 2016-03-10

    Davide, Thanks again for taking time and explaining it. The CLI_ReadArea method takes 6 arguments.

    public int ReadArea(int Area, int DBNumber, int Start, int Amount, int WordLen, byte[] Buffer);

    So in case of this example (%I1.0) I might do sometihing like this.

    res =client.ReadArea(8,1,8,0, s7client.S7WBit, buffer);

    Would you please verify it for me, please.

    I have spend 3 hours reading through the manules, I believe I have now far beter understanding than before. Some of the concepts are still fresh to me and hard to grasp. Please forgive me if I am asking stuiped questions.

     

    Last edit: Sev 2016-03-10
  • Davide Nardella

    Davide Nardella - 2016-03-11

    res =client.ReadArea(S7client.S7AreaPE,0,8,1, S7client.S7WBit, buffer);

     
  • Sev

    Sev - 2016-03-16

    Davide, Thanks again for helping out.

    I gave this a try, but couldn't get it working. I have tried python snap7, I was able to get it working, but I might have missed a minor thing which I am not gettting it working using C#.

    class Program
    {
        static S7Client client = null;
    
        static void Main(string[] args)
        {
                S7Client client = new S7Client();
                int res = client.ConnectTo("192.168.2.16", 0, 0);
    
                byte[] buffer = new byte[1];
    
                res = client.WriteArea(S7Client.S7AreaPA, 0, 8, 1, S7Client.S7WLBit, buffer);
        }
    }
    

    Any idea's?

     

    Last edit: Sev 2016-03-16
  • Davide Nardella

    Davide Nardella - 2016-03-17

    If you want to write a variable into the PLC you should first write something into it :D
    As far I see buffer is unassigned and can contain everything.

     
  • Sev

    Sev - 2016-03-18

    Oeps :| Thanks a lot Davide. I got it working :-)

     
  • ricky tad

    ricky tad - 2019-02-05

    I have also some questions regarding the read/write access to S7 1500.
    What happens when writing a bit (Bool in S7), are the other bits from the DWORD masked to avoid thate they are overwritten?
    And is there any possibility to access (read) the S7 programmable alarms?

     
  • Davide Nardella

    Davide Nardella - 2019-02-05

    If you use WriteArea with S7Client.S7WLBit parameter, only that bit si affected, the other (into the same byte/word/dword) are untouched.
    no way for alarms, you have to first move them into a DB.

     
  • ricky tad

    ricky tad - 2019-02-05

    Thanks for the information.
    Is it possible to get a list with all DataBlocks from a S7 1500 (a list of S7BlockInfo structures) ?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.