agrippa1994 / iOS-PLC

Siemens Simatic S7 communication software for iOS using Snap7
MIT License
14 stars 8 forks source link

Read DB2 values #1

Open DaveyGiesen opened 8 years ago

DaveyGiesen commented 8 years ago

Dear agrippa1994,

I would like to read a value from a Siemens S7-1200. For example: "DB2.DBW36" I use the following code:

client.read("DB2.DBW36", defaultValue: DWORD(0)) {
                    NSLog("Read value \($0)")
                }

It is a DEC value in the PLC, what is the correct code to get the value?

Greetings, Davey

agrippa1994 commented 8 years ago

Hello,

I do not work on this project anymore because I have no PLC system anymore but I am going to help you anyway. As far as I know, reading from the PLC system was working fine for me. Did you get any console output in Xcode?

With kind regards

DaveyGiesen commented 8 years ago

Dear Agrippa, Oh sorry to hear that. Thank you anyway for helping me.

I have a test with the following code:

let client = S7Client()
        client.connect("192.168.2.180", rack: 0, slot: 0) {

            NSLog("connect test: %x", $0)

            client.read("DB2.DBW36", defaultValue: false) {
                NSLog("Readed DB2.DBW36 \($0)")
            }

        }

This is the output:

2015-11-27 16:45:42.211 PLC[4508:537869] connect test: 0

When I open the app and I want to create a connection with Verbindungen -> Click address -> Verbinden I get a box: Connection has been successfully established!

I have a good connection but I think the return values are not parsed good. A lot of values are DEC_UNSIGNED (following the S7App). I use a S7-1200 PLC by the way.

Could you point me in the right way?

agrippa1994 commented 8 years ago

Okay, that sounds really strange. Are the rack and slot numbers the same as defined in the hardware configuration?

Internally I use SNAP7 as a communication service between the PLC and iOS. It's an Open Source library written in C++ which can be embedded in any programm. If you are familiar with C++, you can give a try on a small console application which creates a connection to your PLC. With a few lines of code you should be able to read decimal values from your system. If it's not working there, then this is an internal problem with the library itself.