Reading value of type time on S7 PLC

Hi,

I am currently working with a Simatic 2040 and a PLC.
Node-red is installed on the Simatic and I managed to retrieve values from it.
But I need to retrieve values of type Time but I didn't see in the node-red-contrib-s7 what was the syntax for it.

Is that feature implemented on the node module ?

Thanks.

Unfortunately, there's currently no specific datatype for date/time variables. The solution here is to read the memory area you want as a number (most probably as a DWORD), and then parse it in your flow.

Which model of PLC are you using? Maybe you can share a bit of your flow and PLC project so we can help you on parsing it

Hi,

I'm using a Siemens S7 PLC. In the project I have for example several times which are
Time_Of_Day type.
In my Node-red flow, I declared two PLC reading : one for periodic reading and the second for alarm reading. These time variable are in DB1, so I was thinking about doing something like DB1,DWORD(n bytes) where n bytes is the number of bytes to start reading as explained in the documentation.
I didn't test it yet because I encountered issues with the PLC : to resume DB are optimized blocks and I can't acces it directly through the node-red flow (it's require to develop our own DB with non-optimized block access, so we are working on it). But that's not the point of my topic.

As you suggested me to take the Time type variable as a DWORD I was wondering if it was possible to convert it as DWORD or do I have to change the Time_Of_Day type to DWORD type in the PLC project?

It's really complicated for me to change the PLC project as I am working in a company which is not really OK to do so. If it's not possible, maybe I should try using python snap7 library.

I share the following node-red flow :

[{"id":"deb43bae.942068","type":"tab","label":"Flow 1"},{"id":"bf5af5bb.011788","type":"s7 endpoint","z":"","address":"10.129.142.231","port":"102","rack":"0","slot":"1","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","cycletime":"10000","timeout":"1500","verbose":"default","name":"","vartable":[{"addr":"M01","name":"DistillationTemperature"},{"addr":"M02","name":"DistillationTemps"},{"addr":"M03","name":"TestVar"}]},{"id":"357536b.18b63ca","type":"serial-port","z":"","serialport":"/dev/ttyS0","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":false},{"id":"7d303c14.273924","type":"debug","z":"deb43bae.942068","name":"","active":true,"console":"false","complete":"payload","x":689.6666259765625,"y":299.44445610046387,"wires":[]},{"id":"f8b3f8d5.595128","type":"exec","z":"deb43bae.942068","command":"python /home/heptane/scripts/periodic.py","addpay":true,"append":"","useSpawn":true,"timer":"","name":"","x":577.9444274902344,"y":86.27777671813965,"wires":[[],[],[]]},{"id":"1a902f7b.2c2bc1","type":"s7 in","z":"deb43bae.942068","endpoint":"bf5af5bb.011788","mode":"all","variable":"","diff":false,"name":"Periodic","x":69,"y":66,"wires":[["f3691d36.09404"]]},{"id":"f3691d36.09404","type":"trigger","z":"deb43bae.942068","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":false,"units":"min","reset":"","name":"","x":198.33334350585938,"y":143.22221565246582,"wires":[["1119e083.efa10f"]]},{"id":"313a5900.3ba498","type":"s7 in","z":"deb43bae.942068","endpoint":"bf5af5bb.011788","mode":"all","variable":"","diff":false,"name":"Alarm","x":59,"y":243.99999809265137,"wires":[["415d7610.36b988"]]},{"id":"1119e083.efa10f","type":"json","z":"deb43bae.942068","name":"","x":339.11114501953125,"y":104.44443321228027,"wires":[["f8b3f8d5.595128"]]},{"id":"f44c48e8.c6f0a8","type":"exec","z":"deb43bae.942068","command":"python /home/heptane/scripts/alarm.py","addpay":true,"append":"","useSpawn":true,"timer":"","name":"","x":417.111083984375,"y":331.6666259765625,"wires":[["7d303c14.273924"],["7d303c14.273924"],[]]},{"id":"415d7610.36b988","type":"json","z":"deb43bae.942068","name":"","x":216.22220611572266,"y":253.88888931274414,"wires":[[]]},{"id":"1c1d0cc.53b53f3","type":"status","z":"deb43bae.942068","name":"","scope":["313a5900.3ba498","1a902f7b.2c2bc1"],"x":65,"y":336,"wires":[["d1550a86.664e08"]]},{"id":"a879e9b4.af72c8","type":"debug","z":"deb43bae.942068","name":"","active":true,"console":"false","complete":"payload","x":762.2500114440918,"y":382.7500057220459,"wires":[]},{"id":"d1550a86.664e08","type":"function","z":"deb43bae.942068","name":"","func":"msg.payload = msg.status;\nreturn msg;","outputs":1,"noerr":0,"x":213.5,"y":405,"wires":[["aa62953d.edce58"]]},{"id":"aa62953d.edce58","type":"json","z":"deb43bae.942068","name":"","x":348,"y":401,"wires":[["192a3e93.a1e041"]]},{"id":"192a3e93.a1e041","type":"exec","z":"deb43bae.942068","command":"python /home/heptane/scripts/keepalive.py","addpay":true,"append":"","useSpawn":true,"timer":"","name":"","x":575.5000076293945,"y":478.75000762939453,"wires":[["a879e9b4.af72c8"],["a879e9b4.af72c8"],[]]}]

Best regards!

Elisa,

if the PLC variable is typed as "Time", then you can read it with node-red-contrib-s7 as a double word, see image below (sorry for the creepy collage). The content in the DWORD is just the time value in ms.


The same for "Time_Of_Day" type: DWORD content in node red is to be interpreted as number of ms.
"Date" is a 16 bit word and counts the number of days starting from 1st Jan 1990.

The fancy "DTL" type is more complicated. I don't know how to read it by heart. You should search some siemens forum to understand how it works

1 Like

Hi,

Oh okay I didn't know I thought PLC will return an error if I tried to read a TOD as DWORD.
I'll check on Siemens forum.

Thanks a lot!

Roughly speaking, all data here is read from the PLC as raw bytes, and later parsed to the appropriate type. Therefore, you could in theory read any memory area of the PLC as any data type, and usually no error will be returned because of this (except in very specific cases).

Regarding the DTL type, as long as I remember, it's a sequence of 8 bytes [YY][YY][MM][DD][WW][hh][mm][ss], where WW is the day of week, and the rest is self explanatory :slight_smile: . But better double checking it