gijzelaerr / python-snap7

A Python wrapper for the snap7 PLC communication library
http://python-snap7.readthedocs.org/
MIT License
661 stars 246 forks source link

Unable to Read #185

Closed biswaKL closed 4 years ago

biswaKL commented 4 years ago

Hi Team,

I have a S7-1200 with me, i cant code it. Programmer uploaded the code and left. He gave me the register address which i am trying to read, but not happening.

these are the address: DB1.DBW0, DB1.DBW1, DB1.DBW2, DB1.DBD42

Can any one please tell me how to read these.

biswaKL commented 4 years ago

I am getting message like: CLI : function refused by CPU (Unknown error)

lautarodapin commented 4 years ago

What code are u using to read the db? Maybe in the plc program the blocks have check the optimized block, which will cause problems. If you are using get_db function, try to use db_read( n_db, start, length)

swamper123 commented 4 years ago

Indeed this could have multiple issues:

Here are the notes from snap7 about this topic:

S7 1200/1500 Notes

An external equipment can access to S71200/1500 CPU using the S7 “base” protocol, only working as an HMI, i.e. only basic data transfer are allowed.

All other PG operations (control/directory/etc..) must follow the extended protocol, not (yet) covered by Snap7. Particularly to access a DB in S71500 some additional setting plc-side are needed.

  1. Only global DBs can be accessed.
  2. The optimized block access must be turned off.
  3. The access level must be “full” and the “connection mechanism” must allow GET/PUT.
biswaKL commented 4 years ago

I reporigrammed the PLC, and i am able to read now using db_read.

Now my question is can i use: "DB1.DBD42" directly instead of giving address and size. 2020-08-20

swamper123 commented 4 years ago

I don't know if such a feature already exist (especially if this repo shall just be a wrapper), but you may make your own methods.

You can parse yourself the string into DBnumber (1), Start (here 42), Size (DBD) (there you make yourself a dict of datasizes of word, byte etc., don't forget the endian stuff! and compare it) and this should be it. Then you throw all the stuff in e.g. db_read() and that should be it.

lautarodapin commented 4 years ago

you could write yourself a function to read using "DB1.DBD42" I suggest using regex

r'DB([0-9]+)\.DB([DXBW])([0-9]+)\.?([0-9]+)?'   ##<-- starting point, you will get the DB number, Type of data, offset or byte and bit if it has
gijzelaerr commented 4 years ago

Did this solve your issue?

biswaKL commented 4 years ago

yes its resolved now. sorry i forgot to close. thanks everyone for your help.

On Fri, Sep 11, 2020 at 12:49 PM Gijs Molenaar notifications@github.com wrote:

Did this solve your issue?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gijzelaerr/python-snap7/issues/185#issuecomment-690922760, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEJX3WPF3LCLBFRB2XR2HNLSFHFP5ANCNFSM4QBSHEUQ .

-- Thanks and Regards,

[image: Knowledge Lens Pvt. Ltd.] https://www.knowledgelens.com http://www.knowledgelens.com Biswajit Sahu Senior Tech. Lead Mobile: +919124392903

Our Expertise: Big Data | Artificial Intelligence | Internet of Things ||Our Expertise: Our Products: GLens | iLens | MLens |AiLens | SearchLens

M0hanraj27 commented 1 month ago

Hii., Is it python - Snap7 will works for acquiring real,int,dint,bool data from S7300 CP343-1 Lean module