News:

  • June 10, 2026, 06:53:17 AM

Login with username, password and session length

Author Topic: Floats and ints and bitwise operators...oh my!  (Read 34919 times)

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6158
  • Yes Pinky, Do-more will control the world!
Floats and ints and bitwise operators...oh my!
« Reply #15 on: October 21, 2014, 11:42:51 AM »
Feature request:  Restore our ability when viewing numeric memory locations in ASCII mode in a Data View to specify how many registers (or characters) to show on a line (like DS5 behavior).
That's what STRINGs are for.  You get a lot more ASCII display capabilities using STRINGs.

Except when interacting with external servers, Mark. He's wanting to access something like Modbus memory as strings. It is a reasonable request.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Floats and ints and bitwise operators...oh my!
« Reply #16 on: October 21, 2014, 11:48:46 AM »
That's exactly right, BobO.  Externally accessible memory for names of stuff.  I could store it in a string type, but the only place it ever gets accessed is via Modbus so there'd be no point.  I'd leave the names in local HMI memory and never even transmit them to the PLC, except that a subset of them need to be visible from other HMI's.

Also, the total number of registers for all the strings I'd like to see simultaneously will often exceed 99, and will certainly exceed the number of lines visible on screen.
« Last Edit: October 21, 2014, 11:52:56 AM by Controls Guy »
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Floats and ints and bitwise operators...oh my!
« Reply #17 on: October 21, 2014, 10:57:54 PM »
Interestingly, Bernie,

R101 | R102 != R101:S | R102:S

If you do it the casted way, it does the bitwise OR you'd expect (at least if sent to an :S cast destination register).  If you do it without casting, 5.0 | 2.0 = 7.0.

I'm guessing that since OR wants integer arguments, if you don't explicitly cast them, it translates them to INT's by value, then does the bitwise OR.  Thus, 5.0 | 2.0   ->   5 | 2   ->   7   ->   7.0 (if assigned to a real register).

Hosties?
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

b_carlton

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 606
    • thePLCguy
Floats and ints and bitwise operators...oh my!
« Reply #18 on: October 21, 2014, 11:46:55 PM »
The help file does mention that floats are converted before a bitwise operation so that kind of blows the purpose. it's ok because they specifically warned against it.
An output is a PLC's way of getting its inputs to change.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Floats and ints and bitwise operators...oh my!
« Reply #19 on: October 22, 2014, 12:43:29 AM »
What is this "manual" you speak of?   Are you suggesting there's information I'm supposed to read first before just plunging ahead and doing stuff?   :D
« Last Edit: October 22, 2014, 09:55:48 AM by Controls Guy »
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6158
  • Yes Pinky, Do-more will control the world!
Floats and ints and bitwise operators...oh my!
« Reply #20 on: October 22, 2014, 09:28:50 AM »
There really isn't a right way to do a wrong thing. Bitwise operations are inherently integer, so we covert before the operation. Is that 100% what you wanted? Probably not, but it's more likely to produce a meaningful answer for the bulk of users than would leaving it float.

Since our cast operators are 'reinterpretors' rather than converters, you could cast the float to an integer, do the bitwise operation, output to a float cast to integer, then use as float. Haven't tried it, but that should work.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Floats and ints and bitwise operators...oh my!
« Reply #21 on: October 22, 2014, 09:53:33 AM »
Agreed, BobO.  I don't think anyone's contending that it should be any different than it is; we were assuming that it did bitwise ops on the bits as is, and that therefore the user simply shouldn't be using bit ops on floating point arguments.  Turns out you've cushioned it a little bit for the guys doing the stuff they're not supposed to be doing.  Any further discussion was just learning how it worked in detail (because it's interesting and to avoid using it for something it won't do, and even unanticipated behavior can be useful once you understand the rules).  No worries!
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6158
  • Yes Pinky, Do-more will control the world!
Floats and ints and bitwise operators...oh my!
« Reply #22 on: October 22, 2014, 10:39:01 AM »
Agreed, BobO.  I don't think anyone's contending that it should be any different than it is; we were assuming that it did bitwise ops on the bits as is, and that therefore the user simply shouldn't be using bit ops on floating point arguments.  Turns out you've cushioned it a little bit for the guys doing the stuff they're not supposed to be doing.  Any further discussion was just learning how it worked in detail (because it's interesting and to avoid using it for something it won't do, and even unanticipated behavior can be useful once you understand the rules).  No worries!

I got that. I was just trying to clarify how it worked and give you a glimpse inside our discussions. Virtually every debate/discussion we've seen on the forum has already happened here at Host. When we have an arbitrary choice of how to deal with an exception condition, we try to choose the way that takes the pointy stick away from the noob.

And what I described is the answer to this behavior:

Quote from: Controls Guy
R101 | R102 != R101:S | R102:S

"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Floats and ints and bitwise operators...oh my!
« Reply #23 on: October 22, 2014, 10:51:25 AM »
When we have an arbitrary choice of how to deal with an exception condition, we try to choose the way that takes the pointy stick away from the noob.

You're no fun -- pointy sticks are what chlorinate the gene pool!   :D
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6158
  • Yes Pinky, Do-more will control the world!
Re: Floats and ints and bitwise operators...oh my!
« Reply #24 on: October 22, 2014, 10:53:23 AM »
When we have an arbitrary choice of how to deal with an exception condition, we try to choose the way that takes the pointy stick away from the noob.

You're no fun -- pointy sticks are what chlorinate the gene pool!   :D

Ok...that got an actual LOL! ;D
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO