News:

  • September 25, 2026, 10:07:52 AM

Login with username, password and session length

Author Topic: Editing of Constants in Instructions  (Read 11211 times)

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Editing of Constants in Instructions
« on: December 08, 2020, 07:23:35 AM »
Is it technically possible to edit a constant in an instruction without having to recompile/download. For example: MOVE 1 to V0. Have the ability to change from 1 to another integer without compiling/downloading.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3847
    • Host Engineering
Re: Editing of Constants in Instructions
« Reply #1 on: December 08, 2020, 10:55:57 AM »
Use a variable for the Source, e.g. V100.  On first scan code block, move 1 to V100.  Then use a Data View or HMI to "adjust" the  "constant" Source to whatever value you need.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3847
    • Host Engineering
Re: Editing of Constants in Instructions
« Reply #2 on: December 08, 2020, 10:58:08 AM »
I especially like using Symbolic Constants (i.e. named constants) for these kind of "variables".

For example, use "InitialWidget" for the constant 1.  Then your code in $tFirstScan that does
MOVE InitialWidget CurrentWidget // V100 has the Nickname CurrentWidget
makes more sense than
MOVE 1 V100

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3626
  • Darth Ladder
Re: Editing of Constants in Instructions
« Reply #3 on: December 08, 2020, 11:10:55 AM »
Yeah, I love the Symbolic Constants too.    Would like to have boolean ones, so I can use a configuration constant in a contact.

Currently I set an integer one to 1 or 0 and in ladder do

STRE MyConfigConstant 1 or STRE MyConfigConstant 0

But it would be nice to just use the constant in an NO or NC contact.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Re: Editing of Constants in Instructions
« Reply #4 on: December 08, 2020, 12:51:25 PM »
I've yet to use a symbolic constant. I'll look into this.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6176
  • Yes Pinky, Do-more will control the world!
Re: Editing of Constants in Instructions
« Reply #5 on: December 08, 2020, 12:54:20 PM »
I've yet to use a symbolic constant. I'll look into this.

They are very useful, but don't allow for changing without an edit and download.
"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: 3626
  • Darth Ladder
Re: Editing of Constants in Instructions
« Reply #6 on: December 08, 2020, 01:10:59 PM »
I've yet to use a symbolic constant. I'll look into this.

They're awesome!  If you have a number that doesn't need to change at runtime, especially if you want to guarantee that it cannot, using them protects against that.

They also make the code way more readable and maintainable.   If you change the value of a constant between two projects, you just go to the table and change the value.   Even if you use literal constants all the various Host software packages will let you do a search and replace, but that's a lot more work plus you have to be careful to change only the instances of '4' that represent this particular constant.   Change one of the other 4's unintentionally and you've broken something you now have to troubleshoot later.   Use a data register, and you can change it only one place, but at the risk that something might step on it at runtime.
« Last Edit: December 08, 2020, 01:14:02 PM 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: 3626
  • Darth Ladder
Re: Editing of Constants in Instructions
« Reply #7 on: December 08, 2020, 01:15:37 PM »
Back in the old TI5x0 / 5x5 days, we used to have K-Memory!   :D

(and yes, I agree, Symbolic Constants is a much better idea!)
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

ATU

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 2126
  • YKPAIHA
    • ATU, Inc.
Re: Editing of Constants in Instructions
« Reply #8 on: December 09, 2020, 12:15:24 PM »
They are great. I use them a lot for communications to store my static MODBUS  addresses.