multiple functions in one sequence page (calling)


Recommended Posts

I'm unable to call a specific function from inside a sequence page from a control button.  

I would prefer to organize my functions that are related in a single sequence page.  What am I doing wrong?2024-04-0815_41_48-DAQFactory-autothicknessrev12-LampControl.ctl_.png.82d986f1dec8bbd5598eb60e1cfa8bb0.png

2024-04-08 15_40_34-DAQFactory - autothicknessrev12 - Lamp Control.ctl.png

2024-04-08 15_42_06-Button Component.png

Link to comment
Share on other sites

There are two errors:

1) the primary error is that you are mixing C/C++ syntax with DAQFactory.  DAQFactory only uses {} for denoting a static array.  It is not used for blocks like it is in C.  So, you want something like:

function LampToggle(Light)
   // code
endfunction

function LampCurrentMonitor()
   // more code
endfunction

2) while you can put multiple functions in a single sequence, the first function MUST have the same name as sequence.  Actually it doesn't, but the name you provide for the sequence is the one the first function gets.  So if the code you posted (with the changes mentioned above for endfunction) was in a sequence called myFunctions, you would be able to call LampCurrentMonitor() fine, but LampToggle() would not work.  It would be named myFunctions() as far as DAQFactory is concerned because that is what you named the sequence.

Link to comment
Share on other sites

Thanks, I resolved by splitting those functions into separate sequences.

So now I have a helper sequence:

function LampCheck()

   while (1)
      
      //--------------------
      
      // check the lamp current pin
      LampCurrent()


      // check the lamp power pin
      LampPower()
      
      //--------------------
      // now process the results

            // GPIO 1                  GPIO 2
      if (lampCurrent[0] == 0 && lampPower[0]) == 0)
      
         ? "Power not available/disconnected"
         v.lampStates.AddValue(-1)
         
      elseif (lampCurrent[0] == 0 && lampPower[0]) > 435)
      
         ? "Power available, lamp not connected"
         v.lampStates.AddValue(-2)
         
      elseif (lampCurrent[0] > 205 && lampCurrent[0] < 270 && lampPower[0]) > 435)
      
         ? "Power available, lamp off"
         v.lampStates.AddValue(0)
         
      elseif (lampCurrent[0] > 270 && lampPower[0]) > 435)
      
         ? "Power available, lamp on (flashing)"
         v.lampStates.AddValue(1)
         
      else
      
         ? "Other combinations wouldn’t be valid"     
         v.lampStates.AddValue(-3)
         
      endif
      
      ? v.lampStates[0]
      
      //--------------------
      // critical delay!
      
      delay(0.3)  // execute 3 times a second
      
   
   endwhile

 

This needs to run a couple times a second once started, parallel to the calling sequence.  I understand this is a call for (pun) the BeginSeq() command.

So here's a sample caller sequence:

 

beginseq(LampCheck)

? "started sequence"
Delay(.8)
? "delayed 0.8 seconds"
Delay(1.4)
? "delayed 1.4 more seconds"

endseq(LampCheck)

 

Yet when I start this caller sequence, it is getting stuck in the LampCheck.  The two sequences aren't running concurrently.

Link to comment
Share on other sites

I'm assuming you called your sequence "LampCheck" too.

I'm not sure and would need more detail on your application and what exactly makes you think it is failing.  I made a simple equivalent sample (release 19.1) that I've attached here that shows it working as expected, both in 19.1 and 20.2.

sequenceCaller.ctl

Link to comment
Share on other sites

Your release is ancient (by software standards).  Like over 13 years old.  As such I can't really address any issues with it.  You really should upgrade, at least to 19.1, probably to 20.2, especially if you are creating a new document.  There is no charge for the upgrade to the newer release.

Link to comment
Share on other sites

Wait, I think I got it fixed.  If I simply remove the function name (LampCheck) at the top of the LampCheck sequence, and then call the sequence from the button, then I see the two sequences running concurrently. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.