I have data coming from PLC to R30iB by group inputs of 16 bits.
There may be negative numbers sent.
In the fanuc the group inputs and the registers where the GI's are copied are unsigned integers.
What is the best way to get signed integers in my register?
Signed integer 16 bit
-
Plc_User -
January 24, 2017 at 3:47 PM -
Thread is marked as Resolved.
-
-
To make it easy, i will explain in byte.
Max value of unsigned byte would be 256
Signed byte would be 128 (A)
If you send the value of 129.. (B)First determine if value is greater than A
If B > A
A-B = -1
Else
A = AIf you send the value of 256
128 - 256 = -128You would have to asign the value of -128 to a register..
You can run this in a background program or just as subprogram just before you need the value.
-
I have data coming from PLC to R30iB by group inputs of 16 bits.
There may be negative numbers sent.
In the fanuc the group inputs and the registers where the GI's are copied are unsigned integers.
What is the best way to get signed integers in my register?I'll try to remeber the solution I found before. You would have to do something like if it's greater than a caertain number, then subtract something. I'll let you know if I can find it again.
What i normally do, is add 1k on the PLC then subtract 1k when it comes into the robot.
-
Meanwhile I found this on the forum :
Send signed integer to GI, and get the signed result in a robot register by a single instruction line:
R[1]=(GI[1]-(GI[1] DIV 32768)*65536)
The example is for 16-bit signed integer.
For other n-bit length, modify the constants, which are 2^(n-1) and 2^nThis is the link : https://www.robot-forum.com/robotforum/fan…83655/#msg83655
I tried it and seems ok.
Are there other persons already the same, or comparable? -
Are there other persons already the same, or comparable?
Did not understand that. -
That's how you'll have to do it with group inputs. The other alternative is to message it directly to a register.
Sent from my VS985 4G using Tapatalk
-
Meanwhile I found this on the forum :Send signed integer to GI, and get the signed result in a robot register by a single instruction line:
R[1]=(GI[1]-(GI[1] DIV 32768)*65536)
The example is for 16-bit signed integer.
For other n-bit length, modify the constants, which are 2^(n-1) and 2^nThis is the link : https://www.robot-forum.com/robotforum/fan…83655/#msg83655
I tried it and seems ok.
Are there other persons already the same, or comparable?Yep, that's what it was. If I know my number will be in a certain range I just make sure it's always positive from the Plc to the robot, but if that's not an option, what you posted is exactly the process i used.