# OMRON FINS - How to write REAL values

**URL:** <https://discourse.nodered.org/t/omron-fins-how-to-write-real-values/31942>\
**Category:** Industrial\
**Created:** [24 August 2020 10:23 UTC](https://discourse.nodered.org/t/omron-fins-how-to-write-real-values/31942 "2020-08-24T10:23:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![federicobozzeda](https://avatars.discourse-cdn.com/v4/letter/f/ed655f/32.png) [@federicobozzeda](https://discourse.nodered.org/u/federicobozzeda)\
**Post date:** [24 August 2020 10:23 UTC](https://discourse.nodered.org/t/omron-fins-how-to-write-real-values/31942/1 "2020-08-24T10:23:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [24 August 2020 11:36 UTC](https://discourse.nodered.org/t/omron-fins-how-to-write-real-values/31942/2 "2020-08-24T11:36:43Z")

</div>

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](https://nodejs.org/api/buffer.html) 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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/6/e653fc4a4ef6e1565d9c5a9a88993f0a662a067d.png)

```auto
[{"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.

---

<div class="post-metadata">

**Author:** ![federicobozzeda](https://avatars.discourse-cdn.com/v4/letter/f/ed655f/32.png) [@federicobozzeda](https://discourse.nodered.org/u/federicobozzeda)\
**Post date:** [24 August 2020 12:12 UTC](https://discourse.nodered.org/t/omron-fins-how-to-write-real-values/31942/3 "2020-08-24T12:12:42Z")

</div>

Really thanks Steve! It works! Have a nice day

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 September 2020 12:12 UTC](https://discourse.nodered.org/t/omron-fins-how-to-write-real-values/31942/4 "2020-09-07T12:12:43Z")

</div>

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