Author Topic: Component Constant "Zero"  (Read 7577 times)

Offline spittet

  • PLUS+1 Guru
  • *****
  • Posts: 118
  • Karma: +6/-1
Component Constant "Zero"
« on: May 12, 2020, 09:19:21 PM »
Hi,

I came across this a few times. I find it useful that there is the "Zero" component in the "Constant" library. But, a lot of time, when I use this "Zero" component to set a parameter of a function block, I get a compile error saying that this parameter is not the correct data type (ex : the function block require a S16 value).

To get it to compile, I need to delete my "Zero" component and use a typed 3-char constant with the value of 0. So, this is a small waste of time.

I think the "Zero" component should be able to be used "as is" in such a case. No matter the needed datatype, the "Zero" component should be able to be used anywhere.

Sam

Offline Tor

  • Administrator
  • PLUS+1 Guru
  • *
  • Posts: 296
  • Karma: +28/-1
Re: Component Constant "Zero"
« Reply #1 on: May 14, 2020, 10:23:12 AM »
Hi Sam,

Thanks for pointing this out. I don't use the "Zero" constant that much so I didn't know about this issue.
The reason is that the constant "Zero" is set to the data type "U8" in the background, otherwise you would have a "undefined" value when you compiled.
The same problem will occur if you use the "Digit Autotype" constant. If you put the value to zero, the data type will be set to "U8", and you will get the same issue as a "Zero" constant on a input that needs a "S8/S16/S32".

We usually recommend to use the typed constants, but using the auto typed ones is a bit faster. But be careful, otherwise you might have to change a lot of constants after a compile.

« Last Edit: May 14, 2020, 10:26:44 AM by Tor »
Best regards,
Tor
PLUS+1® SW PAE Team

Offline FluidPowerTom

  • PLUS+1 Guru
  • *****
  • Posts: 363
  • Karma: +33/-0
Re: Component Constant "Zero"
« Reply #2 on: May 14, 2020, 05:54:07 PM »
Honestly, I never use the autotyped stuff.  I create enough problems on my own doing math and causing wrap-around that I'd rather not have other potential issues in the mix.

My opinion is that the autotyped stuff shouldn't even be in there.  I know that the desire is to have a programming platform that is approached by an electrical technician, but the fact is if someone doesn't understand data types (and thus binary) then they probably learn if they're going to be programming microcontrollers for a living.

« Last Edit: May 14, 2020, 05:58:34 PM by FluidPowerTom »
Controls Engineer
Hydra-Power Systems

Offline spittet

  • PLUS+1 Guru
  • *****
  • Posts: 118
  • Karma: +6/-1
Re: Component Constant "Zero"
« Reply #3 on: May 15, 2020, 05:13:39 AM »
I second FluidPowerTom suggestion about removing AutoType and Zero constants and use only Typed constant.

I see an advantage that it will also force user to choose wisely the type of each constant and this may yield in better/more efficient programming in a generic way.


On my side, I'll try to use Typed constant a lot more so that this problem with the Zero constant doesn't happen anymore.

Have a good day!