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?
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:
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)
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.
I was able to get the two INTs to copy into the first two bytes by converting the results of the formula (({[.]Desired Pressure}/130.534)*4095)
into binary using this expression on a tag: (replace(stringFormat("%12s", toBinary({[.]CountFormula})), " ", "0"))
Then I did a little more magic to break the binary up in the two INTs. Then I convert the broken up binary back into a number to put into the each of the SINTs, but it seems that the number I am getting is out of range for the SINT..
Desired Pressure = User Input
Count Formula = formula from manual
toBinary = Converts value from CountFormula in Binary
ReverseBinary = Reverses order to have it line up with correct bits in PLC
Output1Binary/Output2Binary = The broken up binary for each SINT
fromBinary1/fromBinary2 = Converts the broken up binary into a number
The number I am getting on fromBinary1 is out of range for the SINT:
I am using the fromBinary() function so it should be converting it to the correct binary number.. I am just struggling to get it to convert that SINT within that range.
132 as a UInt8 is 10000100
132 as a SInt8 cannot be expressed because a Sint8 can only be 127 to -128
132 as a Sint16 is 00000000 10000100
The from Binary function is using 16 bit values which is why it's giving you 132. But the PLC is using an 8-bit SInt 8. If you want 10000100 as a SInt8 then it's value in decimal is -124