584,865 active members*
4,840 visitors online*
Register for free
Login
Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2011
    Posts
    261

    Possible to do IF-OR-THEN on Fanuc 0i or 31i?

    I am writing a macro tutorial for my trainees and am testing syntax on my machines with a Fanuc 0i-TD control.

    The following syntaxes failed. Can you see anything wrong with these statements?

    IF[[#105NE1]OR[#105NE2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)

    IF[[#105GE1]OR[#105LE2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)

    IF[[#105GT1]OR[#105LT2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)

    IF[[#105NE101]OR[#105NE202]OR[#105NE303]]THEN#3000=1(BAD TOOL/OFFSET NUMBER. MUST BE 0101, 0202, OR 0303)

    IF[[#105NE101.]OR[#105NE202.]OR[#105NE303.]]THEN#3000=1(BAD TOOL/OFFSET NUMBER. MUST BE 0101, 0202, OR 0303)

    The issue is that even when the logic is true and no alarm should generate, the alarm still appears. For example, in the first example I set #105=1.000 but the alarm still appeared.

    For comparison, the following syntax worked as expected
    IF[[#105EQ1]OR[#105EQ2]OR[#105EQ3]OR[#105EQ4]OR[#105EQ5]]GOTO1123
    #3000=1(INVALID TAB NUMBER. MUST BE 1,2,3,4,OR 5)
    N1123

    IF[#26EQ#0]THEN#3000=1(ERROR: Z LOCATION MISSING IN G101 LINE)

    IF[[#105GT1000]AND[#500LE2000]]THEN#600=202

    IF[[#105EQ101]OR[#105EQ202]OR[#105EQ303]]GOTO110
    #3000=1(BAD TOOL/OFFSET NUMBER. MUST BE 0101, 0202, OR 0303)
    N110

    Based on what worked or failed, it seems as if I cannot use IF/OR/THEN but I can use IF/AND/THEN. Can anyone confirm this or is there a parameter setting or syntax error im not seeing?

    Thanks in advance
    CNC Product Manager / Training Consultant

  2. #2
    Join Date
    Aug 2009
    Posts
    684

    Re: Possible to do IF-OR-THEN on Fanuc 0i or 31i?

    Quote Originally Posted by MCImes View Post
    I am writing a macro tutorial for my trainees and am testing syntax on my machines with a Fanuc 0i-TD control.

    The following syntaxes failed. Can you see anything wrong with these statements?

    IF[[#105NE1]OR[#105NE2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)

    IF[[#105GE1]OR[#105LE2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)

    IF[[#105GT1]OR[#105LT2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)

    IF[[#105NE101]OR[#105NE202]OR[#105NE303]]THEN#3000=1(BAD TOOL/OFFSET NUMBER. MUST BE 0101, 0202, OR 0303)

    IF[[#105NE101.]OR[#105NE202.]OR[#105NE303.]]THEN#3000=1(BAD TOOL/OFFSET NUMBER. MUST BE 0101, 0202, OR 0303)

    The issue is that even when the logic is true and no alarm should generate, the alarm still appears. For example, in the first example I set #105=1.000 but the alarm still appeared.

    For comparison, the following syntax worked as expected
    IF[[#105EQ1]OR[#105EQ2]OR[#105EQ3]OR[#105EQ4]OR[#105EQ5]]GOTO1123
    #3000=1(INVALID TAB NUMBER. MUST BE 1,2,3,4,OR 5)
    N1123

    IF[#26EQ#0]THEN#3000=1(ERROR: Z LOCATION MISSING IN G101 LINE)

    IF[[#105GT1000]AND[#500LE2000]]THEN#600=202

    IF[[#105EQ101]OR[#105EQ202]OR[#105EQ303]]GOTO110
    #3000=1(BAD TOOL/OFFSET NUMBER. MUST BE 0101, 0202, OR 0303)
    N110

    Based on what worked or failed, it seems as if I cannot use IF/OR/THEN but I can use IF/AND/THEN. Can anyone confirm this or is there a parameter setting or syntax error im not seeing?

    Thanks in advance
    In the first statement one of the conditions will be true even if #105 is set to 1 or 2 so it will always generate an alarm. I assume the same applies to the other faulty statements. In the case of the first statement you would use AND instead of OR.

    DP

  3. #3
    Join Date
    Feb 2011
    Posts
    353

    Re: Possible to do IF-OR-THEN on Fanuc 0i or 31i?

    is there more of the macro then what is here ?
    the reason i ask is because the first 3 statements have #105 at 1 or 2 but the last 2 statements have it at 101,202,303


    IF[[#105NE1]OR[#105NE2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)--------this seems ok as it is not equal to 1,2 then alarm

    IF[[#105GE1]OR[#105LE2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)-------this one is less than or equal to 1 and 2 then alarm it should alarm out with a 1 or a 2

    IF[[#105GT1]OR[#105LT2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)------this one there is a conflict in the statements-- 1st has to be greater then 1 where as statement 2 must be less then 2 so it can not be a 1 or a 2

    IF[[#105NE101]OR[#105NE202]OR[#105NE303]]THEN#3000=1(BAD TOOL/OFFSET NUMBER. MUST BE 0101, 0202, OR 0303)

    IF[[#105NE101.]OR[#105NE202.]OR[#105NE303.]]THEN#3000=1(BAD TOOL/OFFSET NUMBER. MUST BE 0101, 0202, OR 0303)

  4. #4
    Join Date
    Jan 2016
    Posts
    13

    Re: Possible to do IF-OR-THEN on Fanuc 0i or 31i?

    Quote Originally Posted by MCImes View Post
    I am writing a macro tutorial for my trainees and am testing syntax on my machines with a Fanuc 0i-TD control.

    The following syntaxes failed. Can you see anything wrong with these statements?

    IF[[#105NE1]OR[#105NE2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)


    The issue is that even when the logic is true and no alarm should generate, the alarm still appears. For example, in the first example I set #105=1.000 but the alarm still appeared.
    #105=1.0 but #105 does not = 2 I would think that would cause the alarm.

  5. #5
    Join Date
    Oct 2016
    Posts
    23

    Re: Possible to do IF-OR-THEN on Fanuc 0i or 31i?

    The OR statement will process the THEN command if either of the conditions are true.

    So if #105=1,

    IF[[#105NE1]OR[#105NE2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)

    Is going to run the #3000 error, since #105 is not equal to 2. Likewise, if #105=2, it's still going to error because #105 is not equal to 1. If #105 is anything else, both statements are true and it will still process the error call.

  6. #6
    Join Date
    Sep 2018
    Posts
    10

    Re: Possible to do IF-OR-THEN on Fanuc 0i or 31i?

    IF[[#105LT1]OR[#105GT2]]THEN#3000=5

    If #105 is greater than 2, or less than 1, set #3000 to 5.

    For your code to work, perhaps try replacing the OR with an AND.

  7. #7
    Join Date
    Jan 2019
    Posts
    2

    Re: Possible to do IF-OR-THEN on Fanuc 0i or 31i?

    Quote Originally Posted by MCImes View Post
    I am writing a macro tutorial for my trainees and am testing syntax on my machines with a Fanuc 0i-TD control.

    The following syntaxes failed. Can you see anything wrong with these statements?

    IF[[#105NE1]OR[#105NE2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)

    IF[[#105GE1]OR[#105LE2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)

    IF[[#105GT1]OR[#105LT2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)

    IF[[#105NE101]OR[#105NE202]OR[#105NE303]]THEN#3000=1(BAD TOOL/OFFSET NUMBER. MUST BE 0101, 0202, OR 0303)

    IF[[#105NE101.]OR[#105NE202.]OR[#105NE303.]]THEN#3000=1(BAD TOOL/OFFSET NUMBER. MUST BE 0101, 0202, OR 0303)

    The issue is that even when the logic is true and no alarm should generate, the alarm still appears. For example, in the first example I set #105=1.000 but the alarm still appeared.

    For comparison, the following syntax worked as expected
    IF[[#105EQ1]OR[#105EQ2]OR[#105EQ3]OR[#105EQ4]OR[#105EQ5]]GOTO1123
    #3000=1(INVALID TAB NUMBER. MUST BE 1,2,3,4,OR 5)
    N1123

    IF[#26EQ#0]THEN#3000=1(ERROR: Z LOCATION MISSING IN G101 LINE)

    IF[[#105GT1000]AND[#500LE2000]]THEN#600=202

    IF[[#105EQ101]OR[#105EQ202]OR[#105EQ303]]GOTO110
    #3000=1(BAD TOOL/OFFSET NUMBER. MUST BE 0101, 0202, OR 0303)
    N110

    Based on what worked or failed, it seems as if I cannot use IF/OR/THEN but I can use IF/AND/THEN. Can anyone confirm this or is there a parameter setting or syntax error im not seeing?

    Thanks in advance
    I'll try to break down all.


    IF[[#105NE1]OR[#105NE2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)

    Replace "OR" with "AND".

    IF[[#105GE1]OR[#105LE2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)

    No need for that one. What you're saying (spelling it out works wonders!) is "if x is 1 or above, or if x is 2 or below, then ERROR. But if you want this type of code, you can use:

    IF [[#105LT1] OR [#105GT2] OR [FIX[#105]NE#105] THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)

    Reason for "OR [FIX[#105]NE#105]" is I assume you want an integer, not "1.009"? Good thing about this way of coding is you can make it accept numbers 1...10, for example.

    IF[[#105GT1]OR[#105LT2]]THEN#3000=5(INVALID TAB NUMBER. MUST BE 1 OR 2)

    Same reasoning applies. Check above examples.

    IF[[#105NE101]OR[#105NE202]OR[#105NE303]]THEN#3000=1(BAD TOOL/OFFSET NUMBER. MUST BE 0101, 0202, OR 0303)

    Again, just replace OR with AND and you're fine.

    IF[[#105NE101.]OR[#105NE202.]OR[#105NE303.]]THEN#3000=1(BAD TOOL/OFFSET NUMBER. MUST BE 0101, 0202, OR 0303)

    Redundant.

    I may have left out a "[" or something, just scribbling in Chrome. And it seems most is already answered by others, hah. Plus the question is two months old. Oh well.

    Good luck!

  8. #8
    Join Date
    Feb 2006
    Posts
    1792

    Re: Possible to do IF-OR-THEN on Fanuc 0i or 31i?

    It is two years old thread.

Similar Threads

  1. Replies: 5
    Last Post: 04-20-2019, 02:31 PM
  2. Replies: 12
    Last Post: 12-26-2016, 10:31 PM
  3. Replies: 8
    Last Post: 09-25-2014, 02:58 PM
  4. Replies: 0
    Last Post: 01-28-2014, 04:41 AM
  5. Replies: 5
    Last Post: 03-09-2011, 04:11 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •