Help Pushing Binary Into tag bits

I am working on a device that is hooked up to our PLC through ethernet/IP and an EDS file. The device works by taking the pressure you want and converting it to binary (through an formula in the manual). Once you have the binary value, you need to input the value into two different tags bits to get the desired output.
I have everything set up to get the number switched into binary but now I don’t know how to input that into the tag bits.. any ideas?

Need “toBinary” value above to be insert into tag bits like picture below:

Let me know if there is anything more I can clarify to help.

Share the details. This looks like basic shift/mask operations.

Which details are you looking for me to share? I’d be happy to share anything you’d need me to.

How did you compute the binary? And know what bits to target?

(Share the manual, perhaps.)

1 Like

There should be no need to write to individual bits in the PLC if you're writing what amounts to a value.

Yes, I'm going on a limb here but... Is this calculation right? It's looks like Byte 1 is supposed to be the integer and byte 2 is the decimal? If so, you are missing bit 5 on Byte1.

Also if so:
Option 1: make two integer expressions and write them separately to each SINT:

floor({[.]Desired Pressure)

({[.]Desired Pressure)-floor({[.]Desired Pressure))*10

Option 2: Write the full calculated integer to a UINT on the PLC and COPy it to Reg1:O and let the PLC handle the distribution.
({[.]Desired Pressure)-floor({[.]Desired Pressure))*2560 + floor({[.]Desired Pressure)

Here is the equation from the manual as well as the portion that points out what goes to what bit:

I can get you the full manual if you wanted to read through it as well.

Tell us what brand and model of PLC it is. Don't be embarrassed about it!

Probably this: https://content2.smcetech.com/pdf/manuals/IN19856.pdf

Assuming that the toBinary conversion is correct, then in the Tag valueChanged event you can use code similar to the following:

revBin = int(bin(currentValue.value)[2:][::-1].ljust(16,'0'),2)
byte2 = revBin & 0xFF
byte1 = revBin >> 8 & 0xFF

system.tag.writeAsync(['paths to each byte'],[byte1,byte2])

I am using an Allen Bradley CompactLogix 5069-L0306ERM

Yes, that is the full manual, thanks!

Rather than trying to write individual bits from Ignition I'd just write the integer value across into a PLC temp tag first and then have the PLC logic assign the bitwise logic into your final tag.

Concur. Just arrange to copy an INT into the first two bytes. The manual implies the high bits are ignored. Use Ignition's linear tag scaling to do the conversion to 0-4095 for you, and enable the clamping option.