The bit order for the bool operation requires a swap operation from the OMRON data is due to the endianess of the OMRON PLC. The bool operation of buffer-parser reads each byte in turn and converts the individual byte into bits.
You can see this clearer if disable swap and add bytes(2 long) and 16bit(LE) and 16bit(BE)
Example:
- set CIO3900 to
21
== 0000 0000 0001 0101
- PLC bytes =
[0, 21]
- the byte[0] is 0
, byte[1] has 21
- read 16 bools -
[false,false,false,false,false,false,false,false,true,false,true,false,true,false,false,false]
- read 16bit(LE) -
[0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,0]
- read 16bit(BE) -
[1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0]
so if you do SWAP16 the bytes are swapped and the bools are shifted to [true,false,true,false,true,false,false,false,false,false,false,false,false,false,false,false]
but this means any additional operations you make in the buffer parser need to be LE operations 9as you have swapped the source data)
A future version of buffer parser may include a bools(le) and bools(be) but for now you have to be aware.
flow for above demo
[{"id":"2c8109e5.5ae2b6","type":"buffer-parser","z":"bec69dbd.8d622","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint16be","name":"uint16(be)","offset":0,"length":1,"offsetbit":16,"scale":"1","mask":""},{"type":"byte","name":"bytes","offset":0,"length":2,"offsetbit":16,"scale":"1","mask":""},{"type":"bool","name":"bools","offset":0,"length":16,"offsetbit":0,"scale":"1","mask":""},{"type":"16bitle","name":"16Bit(le)","offset":0,"length":1,"offsetbit":16,"scale":"1","mask":""},{"type":"16bitbe","name":"16Bit(be)","offset":0,"length":1,"offsetbit":16,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":1750,"y":340,"wires":[["dc071ef0.315a9"]]},{"id":"c33b1a2a7cca388f","type":"FINS Read","z":"bec69dbd.8d622","name":"","connection":"5aa6ee81481e6b24","addressType":"msg","address":"topic","countType":"msg","count":"payload","msgPropertyType":"msg","msgProperty":"payload","outputFormatType":"buffer","outputFormat":"","x":1590,"y":340,"wires":[["2c8109e5.5ae2b6"]]},{"id":"dc071ef0.315a9","type":"debug","z":"bec69dbd.8d622","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1930,"y":340,"wires":[]},{"id":"c7577284418fec10","type":"inject","z":"bec69dbd.8d622","name":"","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"CIO3900","payload":"1","payloadType":"num","x":1420,"y":340,"wires":[["c33b1a2a7cca388f"]]},{"id":"fb05808027067919","type":"inject","z":"bec69dbd.8d622","name":"","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"CIO3900","payload":"21","payloadType":"num","x":1770,"y":280,"wires":[["5e4486e6662c57af"]]},{"id":"5e4486e6662c57af","type":"FINS Write","z":"bec69dbd.8d622","name":"","connection":"5aa6ee81481e6b24","addressType":"msg","address":"topic","dataType":"msg","data":"payload","msgPropertyType":"msg","msgProperty":"payload","x":1930,"y":280,"wires":[[]]},{"id":"5aa6ee81481e6b24","type":"FINS Connection","name":"","host":"192.168.1.120","port":"9600","MODE":"CSCJ","ICF":"128","DNA":"0","DA1":"120","DA2":"0","SNA":"0","SA1":"36","SA2":"0"}]