Omron buffer parser byte swap

I'm reading 6 words of BOOLs with this setup:
image

I'm getting my data and reading it as I need to, however my question is about the Byte swapping, I don't understand why I'd need to and if I am even swapping my bits correctly. My access to the machine is very limited and while I've kept an eye some bits do look correct but others not so much so I'm wondering if I have it setup incorrectly and I'm not looking at the bytes within the word that I think I am.

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"}]

Thanks Steve, so Yes I do need to SWAP16 my bools because of (le) I am reading 6 words of bools down but the UI only gives option to select up to 3 SWAP's.
am I incorrect in thinking that I actually need 6 SWAP's or does specifying 1 SWAP16 apply to each address read in turn?

from the built in help...

Byte swap...
Swap permits 16 bit, 32 bit or 64 bit swap options. Swap is applied to the whole data before extracting the items specified.

Perhaps I should add ...

It is possible to swap up to 3 times. e.g. swap 16 then swap 32 then swap 64 (or whatever order you need to get the data into a sensible layout). Usually it is enough to swap once but some data is 32bit and 16bit swapped.

But the salient detail is "Swap is applied to the whole data before extracting the items specified"

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