mathiask88 / node-snap7

node.js wrapper for snap7
MIT License
162 stars 59 forks source link

Siemens PLC S7-1500 Address #47

Closed stony17 closed 5 years ago

stony17 commented 5 years ago

Unfortunately, I have no experience with the Siemens PLC. How can I query the address DB501, D20 or DB501,X.24.0 with this program. And can I give a listener to an address.

Best Regards, stony

Johanneslueke commented 5 years ago

To Read from PLC is quite simple. I assume you have established a working connection.

From the instance of the client you can invoke the method:

`S7Client.DBRead(dbNumber, start, size[, callback])`

The first parameter describes Number of the DB. In your case your DB's name is DB501 so the Number you must provide is 501. The next parameter describes from where within the DB you want to begin reading. It is an offset relative to the beginning of the memory block a DB represents. The Parameter size describes how many bytes you want to read.

To cite the documentation:

This is a lean function of ReadArea() to read PLC DB. It simply internally calls ReadArea() with area = S7Client.S7AreaDB and wordLen = s7client.S7WLByte.

The optional callback parameter will be executed after read If callback is not set the function is blocking and returns a buffer object on success or false on error. If callback is set the function is non-blocking and an error and result argument is given to the callback.

As far as i know you can not put any listener on it which checks for changes. You need to pull in an Intervall of your choice and have to compare your previous read with current one for any changes.

To read any particular value you need to know its offset within the DB and its type. The offset describes where the value starts in the bytearray you recieve and the type describes how many bytes are allowed to be read.