Author Topic: Correct Usage of #defineLocal, i-TRiLOGi V7  (Read 12524 times)

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Correct Usage of #defineLocal, i-TRiLOGi V7
« on: October 22, 2014, 10:39:08 AM »
OK, you added a new "keyword", #defineLocal.  How do you use it?
  • The text "#defineLocal" is highlighted by the syntax highlighter.
  • Clicking on #defineLocal" does not bring up any "keyword helps"
  • #defineLocal" is not in the list of "keyword helps"
  • The TL7ReferenceAddendum.pdf mentions the #defineLocal, but gives no hint or example of how to use it.
Ok.  So I'm taking guesses.  I wrote the following custom function (one of a series of tests):


#defineLocal ILocal %[1]%

For ILocal = 1 to 10
   print #1 ILocal
next
[/color]

I wrote ladder logic that could invoke the custom function (I know about the compiler optimization for orphaned functions).

If I run the "Compile Only" option, the code compiles without complaint (no syntax error).

If I comment out the #defineLocal line, the code fails to compile (as it should).  This suggests that my usage of the #defineLocal is pretty close to what the compiler expects.

If I click on the "Run (All I/O Reset) menu, the simulator does not run and no error messages are presented.  The presence of #defineLocal breaks the simulator!

OK.  So how was this #defineLocal supposed to be used?

Gary D.
« Last Edit: October 22, 2014, 10:44:11 AM by garysdickinson »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Correct Usage of #defineLocal, i-TRiLOGi V7
« Reply #1 on: October 22, 2014, 10:56:59 AM »
I copy the comments in the sample program "definelocal.pc6" which should be in the "usr\samples" folder. A copy is attached.


Starting from i-TRiLOGI version 6.46 build 03, besides using the #Define table you can also define
label names that only has local scope by using the #defineLocal   labelname = expression.

        E.g.   #defineLocal  RoomTemperature = DM[100]

You can then freely use the label name "RoomTemperature" within this custom function in place of
DM[100] so that the program is more readable.

The #defineLocal keyword is useful if you only want the labels to be valid in the current function.
It could make it easier to create a library function that you can re-use in other applications
without exporting and importing the #Define table.

Note:
------
1) The compiler will first process any label names defined using the #defineLocal before it processes
   the #Define table. So if a label name that is defined by the #definelocal label will be
   preprocessed first.

2) Unlike the #Define table the program does not conduct a check on whether you have
   duplicated #defineLocal on the same label, or whether a label so defined is a reserved keyword.
   So the programmer must exercise greater care when using #defineLocal to avoid ending up with
   hard-to-debug compilation errors.

« Last Edit: October 22, 2014, 10:58:53 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Correct Usage of #defineLocal, i-TRiLOGi V7
« Reply #2 on: October 22, 2014, 12:03:59 PM »
Thanks for the hint on #defineLocal syntax.

I was able to use something like this to create a variable that was local to a custom function with V7:

    #defineLocal ILocal = %[1]

Please look at the issue of the compiler, not complaining about incorrect syntax for #defineLocal and the Simulator crashing without an error message for a future release.  These behaviors are sort of rude.


Thanks,

Gary D.
« Last Edit: October 22, 2014, 12:05:21 PM by garysdickinson »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Correct Usage of #defineLocal, i-TRiLOGi V7
« Reply #3 on: October 22, 2014, 12:36:30 PM »
Thank you for the reminder. We will look into what causes the compiler to fail when wrong syntax is used for #definelocal statement.
« Last Edit: October 22, 2014, 12:36:37 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS