gleasontech (Customer) asked a question.

still having trouble with a fault window, if sensor never gets found, I'm new to programming C++, my question is where to put the FAULTfatal flag if the timer goes to 60, the 3 second window has been exceeded, this code work if sensor found

still having trouble with a fault window, if sensor never gets found, I'm new to programming C++, my question is where to put the FAULTfatal flag if the timer goes to 60, then the 3 second window has been exceeded, this code work if sensor found,

  1. // **********************************************************************************
  2. // vacuum capture of sign sub routine- turn on vacuum and check for capture sign
  3. //
  4. int VACUUMcapture() {
  5. P1.writeDiscrete(HIGH,VACUUM); //vacuum generator solenoid 1=vacuum on / 0= vacuum off
  6. for (x = 0; x < 60; x ++) // fault timer 60*50mS = 3 second window or FAULTzone
  7. {
  8. VACUUMcaptureSIGN = P1.readDiscrete(VACUUMsignDETECT); //vacuum cup sign detection sensor 1=sign present / 0= not-sign present
  9. if (VACUUMcaptureSIGN == true ) { // exit loop on vacuum has captured sign sensor detected
  10. x = 0;
  11. break;
  12. return
  13. FAULTfatal = 1;
  14. }
  15. delay(50);
  16. // FAULTfatal = 1;
  17. }
  18. }
  19. // **********************************************************************************

 


  • FACTS_KevinC (AutomationDirect)

    1. // **********************************************************************************
    2. // vacuum capture of sign sub routine- turn on vacuum and check for capture sign
    3. //
    4. int VACUUMcapture()
    5. {
    6. P1.writeDiscrete(HIGH,VACUUM); //vacuum generator solenoid 1=vacuum on / 0= vacuum off
    7. for (x = 0; x < 60; x ++) // fault timer 60*50mS = 3 second window or FAULTzone
    8. {
    9. VACUUMcaptureSIGN = P1.readDiscrete(VACUUMsignDETECT); //vacuum cup sign
    10. detection sensor 1=sign present / 0= not-sign present
    11. if (VACUUMcaptureSIGN == true ) { // exit loop on vacuum has captured sign sensor detected
    12. //x = 0; //you don't need to set x to 0 here. The for loop will initilize it to 0 the next time it is run.
    13. //break; //remove the break statement. break will take you out of the for loop.
    14. FAULTfatal = 0; //it is good practice to set the flag to 0 in the event that vacuum was captured.
    15. return
    16. }
    17. delay(50);
    18. }
    19. FAULTfatal = 1;
    20. }
    21. // **********************************************************************************

    You would want to put the fault fatal flag outside of the for loop. You also want to remove the break statement. Break will exit the for loop and then restart it after incrementing the variable x.

     

    In the event that the vacuum sensor was detected you will want to just return which will exit the function. When the vacuum is undetected the for loop will execute fully and then the fault flag will be set.

     

    Let me know if any of the explanation was unclear.

     

    Thanks,

     

    Kevin

     

    Expand Post
    • gleasontech (Customer)

      I appreciate your help, I'm getting a error, it highlighting the return line

      1. //* *********************************************************************************************
      2. // **********************************************************************************
      3. // vacuum capture of sign sub routine- turn on vacuum and check for capture sign
      4. //
      5. int VACUUMcapture(){
      6. {
      7. P1.writeDiscrete(HIGH,VACUUM); //vacuum generator solenoid 1=vacuum on / 0= vacuum off
      8. for (x = 0; x < 60; x ++) // fault timer 60*50mS = 3 second window or FAULTzone
      9. {
      10. VACUUMcaptureSIGN = P1.readDiscrete(VACUUMsignDETECT); //vacuum cup sign detection sensor 1=sign present / 0= not-sign present
      11. if (VACUUMcaptureSIGN == true ) { // exit loop on vacuum has captured sign sensor detected
      12. //x = 0; //you don't need to set x to 0 here. The for loop will initilize it to 0 the next time it is run.
      13. //break; //remove the break statement. break will take you out of the for loop.
      14. FAULTfatal = 0; //it is good practice to set the flag to 0 in the event that vacuum was captured.
      15. return }
      16. }
      17. delay(50);
      18. }
      19. FAULTfatal = 1;
      20. }
      21. // **********************************************************************************

       

      exit status 1

      expected primary-expression before '}' token

      Expand Post
  • FACTS_KevinC (AutomationDirect)

    I forgot the ";" after return.

    also the function should be "void VACUUMcapture()" .

     

    It looks like you are storing the flag as a global variable so you don't need to return the value.

  • gleasontech (Customer)

    THANK-YOU very much for the HELP, it worked well and all the sub notes/ comment very helpful !