I'm trying to create a nice Node-RED Dashboard visualization for my Codesys programm. Codesys runs on a rasperry pi, also node-RED.
So, I have a MODBUS TCP connection from Node-RED to codesys and I want to show some data on the dashboard.
My problem is, how to deliver a TOD datatype (time of day - it's a 4 BYTE value) to the dashboard (into a time picker). The TOD data type looks in Codesys like "#TOD12:00:00". If i convert it to a DWORD (also 4 bytes), I get "43200000". I think this is milliseconds from 00:00:00.
To send/read it over modbus, I have to split it to 2 WORD data types (Codesys).
In Node-RED i get the 2 modbus registers and convert them again in a 4 byte value. But I don't get the right value. It is merged in a wrong sequence.
I use a function, which I found here in this forum. This merges the 4-Byte Array (raw-data from the modbus node) to a 4-byte UINT value. But, as I mentioned, in a wrong sequence, so I get a wrong value.
If I split TOD#12:00:00 (> DWORD= 43200000) in Codesys in 4 Bytes I get:
If i look at the raw data byte array, received from node-red, I get:
The function to merge is:
// Create new Buffer based on array bytes
const buf = Buffer.from(msg.payload.buffer);
// Represent these bytes as 32-bit unsigned int
const value = buf.readUInt32LE();
// save the value
msg.payload = value;
The value I get from the function: 2466381870.
Would you please help me to find the correct way to transmit/merge the right values?
In a further step, I also want to send data from the node-red time picker to codesys (with modbus), so I also need the way back...
Thanks very much und please excuse my bad english!