adccommunitymod (AutomationDirect) asked a question.

CALL / RETURN construct in CLICK programming

Created Date: December 21,2017

Created By: CLIQUE_NEWT

**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****

While I 've been active in CLICK programming for the better part of 6+ years, I have never fully understood how to implement the CALL / RETURN directives in its programming. In classical computer languages, I 've done this many times, "calling " assembler routines into BASIC, PASCAL, or "C ", to name a few. The CALL description in the HELP section is, in my opinion, extremely inadequate & woefully unclear. IF someone could write just a few lines of real code, maybe having a trivial main program CALL a SUBROUTINE1 to turn on a light, that would be enuf to show the construct. In experimental code that I entered, I could never get the RETURN directive to appear in a coil.


  • adccommunitymod (AutomationDirect)

    Created Date: December 21,2017

    Created by: CLIQUE_NEWT

    While I 've been active in CLICK programming for the better part of 6+ years, I have never fully understood how to implement the CALL / RETURN directives in its programming. In classical computer languages, I 've done this many times, "calling " assembler routines into BASIC, PASCAL, or "C ", to name a few. The CALL description in the HELP section is, in my opinion, extremely inadequate & woefully unclear. IF someone could write just a few lines of real code, maybe having a trivial main program CALL a SUBROUTINE1 to turn on a light, that would be enuf to show the construct. In experimental code that I entered, I could never get the RETURN directive to appear in a coil.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: December 21,2017

    Created by: kewakl

    The return is just the 'end ' of the subroutine. It returns NOTHING!

    This sample will use the subroutine to toggle C2 every time C1 is true.

    Hardware proof is that Y1 will mirror C2.

    Main Program

    .

    . C1 Call

    .------]

    Toggle Subroutine

    .

    . C2 C2

    .------]/

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: December 21,2017

    Created by: CLIQUE_NEWT

    YEs, I know that the RETURN doesn't "return " anything. It is merely a directive to alert the processor that the end of the subroutine has come. It's sort of like a conditional "end " statement for this code module. But, that's not my problem. In trying to fully understand the construct as it applies to the CLICK, I wrote a very similar short program. I have two problems. The first one is WHERE does this subroutine physically reside? In other words, do I put these few lines of code AFTER the traditional END statement of the main program, OR is it a separate ladder program, which is named "subroutine1 "? The 2nd question is that when I created my own test program, and tried to place the RETURN directive at the end of the code block, I couldn't get it to write in the coil field. I went to "INSTRUCTION> PROGRAM CONTROL ". While the word RETURN was shown in the list, it was grayed out, so that when I pressed on it, it would not register in the coil field.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: December 21,2017

    Created by: CLIQUE_NEWT

    I typed the trivial program that you outlined above into the editor. After the END directive, I typed the exact line of code as above. Then I positioned the cursor over the (NOP) on the rung below that. I went up to the top Tool Bar, selected "Instruction ", and then "Program Control ". While the word RETURN appears in the list, it is grayed out. Pressing the cursor on it, does not activate it at the identified coil. And, of course, when I tried to compile the short program, an error window popped open alerting me of syntax errors, so it would not compile.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: December 21,2017

    Created by: kewakl

    I have two problems. The first one is WHERE does this subroutine physically reside?

    In other words, do I put these few lines of code AFTER the traditional END statement of the main program, OR is it a separate ladder program, which is named "subroutine1 "?

    It is a separate 'ladder. ' -- specifically a subroutine.

    The 2nd question is that when I created my own test program, and tried to place the RETURN directive at the end of the code block, I couldn't get it to write in the coil field. I went to "INSTRUCTION> PROGRAM CONTROL ". While the word RETURN was shown in the list, it was grayed out, so that when I pressed on it, it would not register in the coil field.

    Before I go here, I have to ask. Have you created the subroutine? Please excuse the following long text if you have already created the subroutine.

    In the 'Navigation ' panel right-click on 'subroutine Program ' select 'Add New Subroutine Program Ctrl+U '

    You should see a New Subroutine Program naming dialog. After selecting a name and clicking OK , you should see a Subroutine Program - Quick Guide message.

    The new subroutine should now be visible (note the different background color)

    Your 'subroutine ' code goes here. The Return instruction goes here also. It will go in the coil column.

    You may have code after the Return, just note that it will not be scanned/evaluated.

    EDIT- fixed Ctrl+U reference

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: December 21,2017

    Created by: kewakl

    I typed the trivial program that you outlined above into the editor. After the END directive, I typed the exact line of code as above. Then I positioned the cursor over the (NOP) on the rung below that. I went up to the top Tool Bar, selected "Instruction ", and then "Program Control ". While the word RETURN appears in the list, it is grayed out. Pressing the cursor on it, does not activate it at the identified coil. And, of course, when I tried to compile the short program, an error window popped open alerting me of syntax errors, so it would not compile.

    Thus, it seems to confirm my suspicion that you have not created the subroutine using the instructions in my last post.

    Hope that this helps.

    That sample WAS trivial. just as you asked.

    I reread some of your posts. It seems that you are more menu-oriented than I am, so do the following menu items:

    Program.Add New Subroutine Program Ctrl+U.

    Then, the remainder of the previously posted instructions will apply.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: December 22,2017

    Created by: kewakl

    This may be more helpful than text.

  • adccommunitymod (AutomationDirect)

    Created Date: December 22,2017

    Created by: CLIQUE_NEWT

    OK! I see one of my problems now. First of all, I DID FOLLOW your instructions about CREATING a SUBROUTINE. I got the green screen & typed in the 2 lines of code. When I pressed the "R " key in the bottom rung coil area, the box opened with 3 "R's ", one of which is the RETURN directive. putting the cursor on it, transferred the RETURN to the coil. Then I created another New Project, calling it, CALL_RETURN.ckp. I entered the code for the main program, and saved it. Then I attempted to compile & download to my CLICK, but I got another Syntax error alert. Since this CLICK setup is here at home, I can play around to my heart's content. What I didn't realise is that the sybroutine is a standalone ladder with its own file name. That is NOT made clear in the A-D HELP section. I think there are several topics in the HELP section that could be more fully explained.

    While I won't dwell on it now, there is another point of CLICK programming that I believe needs more clarification. It is regarding the initial conditions of the COUNTER function. IF you go to the ADDRESS PICKER for the Counters, you can set them to be retentive, or not, etc. I have experimented with a Counter in a trivial program to see how setting these initial conditions changes the operation, and I haven't found any explicit differences. I 've addressed this topic with A-D Tech people, but the responses I received were also less than clearly explanatory. I dropped the subject.

    So, for the time being, THANK YOU for your help this evening.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: December 22,2017

    Created by: CLIQUE_NEWT

    THANKS for the zip file. Would you believe that when I unzipped it through WINDOWS EXPLORER, & clicked on the ".ckp " file, I got an error message stating that this was created w/ ver. 2.1 of the CLICK editor, and that I should go to the A-D website to download the latest version. Well, as it happens, I have ver 1.4, ver 2.1 AND ver 2.20 on this PC presently. It's like there's a serious large dark cloud hanging over my head on this little exercise!!!! ADIOS!!!

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: December 22,2017

    Created by: kewakl

    You 're welcome!

10 of 13