OMRON FINS - How to write REAL values

Hi everyone, I'm new to the forum (and node-red too). I hope to insert the topic correctly.
I am trying to communicate with an OMRON CJ2M PLC, via FINS protocol (node-red-contrib-omron-fins).
I can read and write 16-bit channels without any problem.
I was also able to read the channels declared in REAL, converting the buffer out of the READ with the node suggesting the help (node-red-contrib-buffer-parser).

The problem is writing a REAL value to the PLC. How can I do?
The write block always write the first PLC channel, i need a conversion tool that take in input a float number (or an array of elements) and get out an array of INT16 to write to PLC.
Example: Input:7.5 Output:[0,16624]

Thanks in advance.

Hi and welcome,

As you rightly suspect, you will need to convert your values to integer array in order to write to the PLC (its a FINS thing).

So while I could add huge complexity to the FINS Write node (by adding support for int, int32, float, double, signed, unsigned, strings, a mixture of them all, etc, etc, blah blah), I much prefer the KISS approach (Keep it Simple).

So that leaves the user with the burden of converting values to write to PLC when they are not 16bit integers.

Fortunately, this is not too difficult to do

High level...

  1. Send the data you wish to write through a function node
  2. using nodejs Buffer functions, write your data to a buffer
  3. send the buffer out of the function --> buffer-parser
  4. use the buffer-parser to convert buffer to 16 bit array then send that into the FINS write node.

Simple example...

  • write a float (32 bit) value -100.99 to D20000
    AND
  • write a float (32 bit) value -12.34 to D20002

[{"id":"216abf6c.e7c7e","type":"buffer-parser","z":"1d8afe0.1bf0302","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint16be","name":"item1","offset":0,"length":4,"offsetbit":0,"mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"output","multipleResult":true,"setTopic":true,"x":570,"y":520,"wires":[["63059527.68a91c"]]},{"id":"901f5b03.fcf848","type":"function","z":"1d8afe0.1bf0302","name":"float array to buffer","func":"var buf = Buffer(8);\nbuf.writeFloatBE(msg.payload[0],0);\nbuf.writeFloatBE(msg.payload[1],4);\nmsg.payload = buf;\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":520,"wires":[["d14234bf.a99168","216abf6c.e7c7e"]]},{"id":"63059527.68a91c","type":"debug","z":"1d8afe0.1bf0302","name":"to Integer Array","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":640,"y":560,"wires":[]},{"id":"8af4a38f.50993","type":"inject","z":"1d8afe0.1bf0302","name":"[-100.99,12.34]","topic":"","payload":"[-100.99,12.34]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":"7","x":160,"y":520,"wires":[["901f5b03.fcf848","5181c007.b8a35"]]},{"id":"d14234bf.a99168","type":"debug","z":"1d8afe0.1bf0302","name":"as a buffer","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":390,"y":560,"wires":[]},{"id":"5181c007.b8a35","type":"debug","z":"1d8afe0.1bf0302","name":"float data","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":160,"y":560,"wires":[]}]

NOTE...

be aware of the big endian / little endian of your data and adjust the function and buffer-parser to suit.

1 Like

Really thanks Steve! It works! Have a nice day

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.