plcpeople / nodeS7

Node.JS library for communication to Siemens S7 PLCs
MIT License
356 stars 120 forks source link

Implement new DT, DTZ, DTL, DTLZ types #96

Closed gfcittolin closed 4 years ago

gfcittolin commented 4 years ago

This implements 4 new types: DT, DTZ, DTL, and DTLZ. They all read/write javascript's Date format, and handle the conversion for reading/writing internally, replacing the need of user code to handle them

The DT type is the well-known DATE_AND_TIME type of S7-300/400 PLCs, a 8-byte-wide field with BCD-encoded parts

The DTZ type is the same as the DT, but it expects that the timestamp is in UTC in the PLC (usually NOT the case)

The DTL type is the one seen on newer S7-1200/1500 PLCs, is 12-byte long and encodes the timestamp differently than the older DATE_AND_TIME

The DTLZ type is also the same as the DTL, but expecting the timestamp in UTC in the PLC

Note that a javascript's Date is always in UTC, and this can cause some confusion to someone not used to that (or even to these ones) :)

Had this code laying around since long time ago, but never had the time to properly implement and test it. This has been also requested on node-red-contrib-s7#55, and the needed changes there are also ready for shipping.

@plcpeople what do you think?

plcpeople commented 4 years ago

Thank you for this, it looks well implemented and it's good to have this functionality.

gfcittolin commented 4 years ago

Thanks! :)