Thread: Wrong use of OR function?

10262020, 09:48 AM #1
Wrong use of OR function?
Hi to all,
before execution of a third line of the subprogram O7015 an alarm appears  PS0004 INVALID BREAK POINT OF WORDS. I really don't know where is the problem.
Maybe a wrong use of OR function.
I tried also:
IF[#600EQ2OR3]THEN[#654=44.2]
and the same alarm appears.
AND function is working well.
The controller is DOOSAN Fanuc i Series
Maybe someone knows how to solve this problem?
Thanks
Tomaz
%
O3840 ( MAIN PROGRAM )
#600=1
#601=4
#602=40.
#603=100.
#604=2.5
#605=39.
#608=1500
#609=0.2
#607=1.
#606=2.
M98P7015
M53
G28 U0.
G30 W0.
...
...
%
O7015 ( SUBPROGRAM )
IF[[#600EQ1]AND[#602EQ38.]]THEN[#654=37.9]
IF[[#600EQ1]AND[#602EQ40.]]THEN[#654=39.9]
IF[[#600EQ2]OR[#600EQ3]]THEN[#654=44.2]
IF[#600EQ3]THEN[#654=44.2]
IF[[#600EQ4]AND[#602EQ38.]]THEN[#654=45.9]
IF[[#600EQ4]AND[#602EQ40.]]THEN[#654=47.9]
IF[[#601EQ1]OR[#601EQ4]OR[#601EQ5]]THEN[#650=36.9]
IF[[#601EQ2]OR[#601EQ3]]THEN[#650=46.9]AND[#656=2]
IF[#601EQ1]THEN[#651=108.]AND[#655=42.785]AND[#656=2]AND[#660=31.25]
IF[#601EQ2]THEN[#651=110.]AND[#660=31.75]
IF[#601EQ3]THEN[#651=79.]AND[#660=9.5]
IF[#601EQ4]THEN[#651=82.]AND[#655=29.785]AND[#656=2]AND[#660=25.]
IF[#601EQ5]THEN[#651=52.]AND[#655=14.285]AND[#656=1]AND[#660=8.]
#652=[#65118.]
#653=[#651[#650+6.1]]
#657=#652/#656
IF[#656EQ1]THEN[#658=2]
IF[#656EQ2]THEN[#658=1]
#659=8
#661=65.
IF[#601EQ5]THEN[#661=60.]
IF[[#600NE1]OR[#600NE2]OR[#600NE3]OR[#600NE4]]GOTO1001
IF[[#601NE1]OR[#601NE2]OR[#601NE3]OR[#601NE4]OR[#601NE5]]GOTO1002
IF[[#602NE38.]OR[#602NE40.]]GOTO1003
IF[#605GT#654]GOTO1004
M99


10262020, 12:04 PM #2
Your "THEN" condition does not have to be in brackets. Example:
IF [#24 EQ #0] THEN #24=#5041
Not sure if that's your problem. Another note  if you put spaces between everything like in my example, it makes it much easier to spot the inevitable missing brackets or punctuation.

10262020, 12:53 PM #3
Ah, speaking of brackets, pretty sure I see your problem. The IF statement should not be in brackets. It should read:
IF [#600 EQ 2] OR [#600 EQ 3] THEN #654=44.2


10262020, 05:22 PM #4
Hello Tomaz,
I see no problem with the syntax of your following Block.
IF[[#600EQ2]OR[#600EQ3]]THEN[#654=44.2]
The "[#600EQ2]OR[#600EQ3]" statement does have to be enclosed in square brackets, as you want to prioritize the two statements within to form the one condition. Normally, enclosing something like #654=44.2 in brackets wouldn't cause an issue and I doubt that is the issue, but the brackets in the above example of THEN[#654=44.2] are not required.
In terms of syntax, there is no difference between the use of "OR" or "AND". Accordingly, if you were to have an issue with IF[[#600EQ2]OR[#600EQ3]]THEN[#654=44.2], then you would also have issues with the two Blocks preceding it:
IF[[#600EQ1]AND[#602EQ38.]]THEN[#654=37.9]
IF[[#600EQ1]AND[#602EQ40.]]THEN[#654=39.9]
How are you sure that the error relates to that third Block. Unless you have parameters set so that you can step through the Macro Statements in Single Block mode, the error may be further ahead. At a quick glance, you're more likely to have an issue with the following Block
IF[[#601EQ2]OR[#601EQ3]]THEN[#650=46.9]AND[#656=2]
as a Logical Operation ([#650=46.9]AND[#656=2]) is being attempted as a result of a Conditional statement.
Although you show 3 leading zeros in "PS0004", generally they are irrelevant and the error number equates to P/S4. In a Fanuc control, error P/S4 relates to Address Not Found.
Regards,
BillLast edited by angelw; 10272020 at 06:30 AM.


10272020, 04:35 AM #5
Thank you boosted and Bill,
You're both right, the square brackets after THEN are not required, but in my example is nothing wrong if they are. That is not a problem.
I will review your tips and let you know how it went.
Tomaz


10272020, 06:28 AM #6
Hello Tomaz,
I've had time to look at your code again, and your first three blocks are not the issue, the problem starts with the following block:
IF[[#601EQ2]OR[#601EQ3]]THEN[#650=46.9]AND[#656=2]
If you were to delete that block, the error would be raised by the next block that has similar syntax after the THEN reserved word as the above example.
OR and AND are logical operands and can't be used to execute a group mathematical function as you're attempting to do in the above example. To get your basic logic to work, you could do something like the following:
IF[[#601EQ2]OR[#601EQ3]]THEN #650=46.9
IF[[#601EQ2]OR[#601EQ3]]THEN #656=2
or
IF[[#601EQ2]OR[#601EQ3]]THEN #650=46.9
IF[#650=46.9]THEN #656=2
Regards,
Bill

boosted liked this post

10272020, 07:12 AM #7
Thank you Bill,
You're right, AND or OR after THEN cannot work. I thought the error was in the third block, because the cursor stopped on the second block.
Bottom is the revisioned subprogram (slightly longer):
%
O7015
( PODPROGRAM ZA IZRACUN DIMENZIJ )
( NE SPREMINJAJ )
IF[#600EQ1]AND[#602EQ38.]THEN#654=37.9
IF[#600EQ1]AND[#602EQ40.]THEN#654=39.9
IF[#600EQ2]OR[#600EQ3]THEN#654=44.2
IF[#600EQ4]AND[#602EQ38.]THEN#654=45.9
IF[#600EQ4]AND[#602EQ40.]THEN#654=47.9
IF[#601EQ1]OR[#601EQ4]OR[#601EQ5]THEN#650=36.9
IF[#601EQ2]OR[#601EQ3]THEN#650=46.9
IF[#601EQ2]OR[#601EQ3]THEN#656=2
IF[#601EQ1]THEN#660=31.25
IF[#601EQ1]THEN#656=2
IF[#601EQ1]THEN#655=42.785
IF[#601EQ1]THEN#651=108.
IF[#601EQ2]THEN#651=110.
IF[#601EQ2]THEN#660=31.75
IF[#601EQ3]THEN#660=9.5
IF[#601EQ3]THEN#651=79.
IF[#601EQ4]THEN#651=82.
IF[#601EQ4]THEN#655=29.785
IF[#601EQ4]THEN#656=2
IF[#601EQ4]THEN#660=25.
IF[#601EQ5]THEN#651=52.
IF[#601EQ5]THEN#655=14.285
IF[#601EQ5]THEN#656=1
IF[#601EQ5]THEN#660=8.
#652=[#65118.]
#653=[#651[#650+6.1]]
#657=#652/#656
IF[#656EQ1]THEN[#658=2]
IF[#656EQ2]THEN[#658=1]
#659=8
#661=65.
IF[#601EQ5]THEN[#661=60.]
( VARNOSTNI STAVKI )
IF[#600NE1]OR[#600NE2]OR[#600NE3]OR[#600NE4]GOTO1001
IF[#601NE1]OR[#601NE2]OR[#601NE3]OR[#601NE4]OR[#601NE5]GOTO1002
IF[#602NE38.]OR[#602NE40.]GOTO1003
IF[#605GT#654]GOTO1004
M99
N1001
#3000=1( SAMO STIRJE TIPI PUS  1 2 3 ALI 4 )
N1002
#3000=2( DEFINIRAJ PRAVO SKUPINO ABCDE  1 2 3 4 ALI 5 )
N1003
#3000=3( SAMO PREMERA 38 ALI 40 )
N1004
#3000=4( SVEDER JE VECJI OD NOTRANJEGA PREMERA )
M99
%
Now I have other alarm: PS1137 IF STATEMENT FORMAT ERROR.
I have noticed that if I delete the first eight blocks the subprogram works.
I will try to delete the blocks individually and then I will inform you of the results.
Regards
Tomaz

10272020, 08:49 AM #8
Hello Tomaz,
The alarm will continue to be raised as you delete individual blocks until you have deleted all eight; accordingly, you may be none the wiser at the end of that exercise. For your program to work with the first eight blocks included, you have to set parameter bit 6006.0 to "1". This allows Logical Operations (AND, OR etc.) to be used in conditional statements.
Also, you can only have 26 characters, including spaces, as the Message in the Alarm System Variable block (#3000). An error won't be raised, only the message will be truncated to 26 characters long.
Regards,
Bill

boosted liked this post

10272020, 09:44 AM #9
Hello Bill,
I changed #6006.0 to 1, please check the image below.
The error still persists…
Updated subprogram:
%
O7015
( PODPROGRAM ZA IZRACUN DIMENZIJ )
( NE SPREMINJAJ )
IF[#600EQ1]AND[#602EQ38.]THEN#654=37.9
IF[#600EQ1]AND[#602EQ40.]THEN#654=39.9
IF[#600EQ2]OR[#600EQ3]THEN#654=44.2
IF[#600EQ4]AND[#602EQ38.]THEN#654=45.9
IF[#600EQ4]AND[#602EQ40.]THEN#654=47.9
IF[#601EQ1]OR[#601EQ4]OR[#601EQ5]THEN#650=36.9
IF[#601EQ2]OR[#601EQ3]THEN#650=46.9
IF[#601EQ2]OR[#601EQ3]THEN#656=2
IF[#601EQ1]THEN#660=31.25
IF[#601EQ1]THEN#656=2
IF[#601EQ1]THEN#655=42.785
IF[#601EQ1]THEN#651=108.
IF[#601EQ2]THEN#651=110.
IF[#601EQ2]THEN#660=31.75
IF[#601EQ3]THEN#660=9.5
IF[#601EQ3]THEN#651=79.
IF[#601EQ4]THEN#651=82.
IF[#601EQ4]THEN#655=29.785
IF[#601EQ4]THEN#656=2
IF[#601EQ4]THEN#660=25.
IF[#601EQ5]THEN#651=52.
IF[#601EQ5]THEN#655=14.285
IF[#601EQ5]THEN#656=1
IF[#601EQ5]THEN#660=8.
#652=[#65118.]
#653=[#651[#650+6.1]]
#657=#652/#656
IF[#656EQ1]THEN#658=2
IF[#656EQ2]THEN#658=1
#659=8
#661=65.
IF[#601EQ5]THEN#661=60.
( VARNOSTNI STAVKI )
IF[#600NE1]OR[#600NE2]OR[#600NE3]OR[#600NE4]GOTO1001
IF[#601NE1]OR[#601NE2]OR[#601NE3]OR[#601NE4]OR[#601NE5]GOTO1002
IF[#602NE38.]OR[#602NE40.]GOTO1003
IF[#605GT#654]GOTO1004
M99
N1001
#3000=1( SAMO STIRJE TIPI PUS  1 2 3 ALI 4 )
N1002
#3000=2( DEFINIRAJ PRAVO SKUPINO ABCDE  1 2 3 4 ALI 5 )
N1003
#3000=3( SAMO PREMERA 38 ALI 40 )
N1004
#3000=4( SVEDER JE VECJI OD NOTRANJEGA PREMERA )
M99
%
Something else must be wrong.
Tomorrow I will try a simple program with a few blocks only. With AND and OR functions.
Regards
Tomaz


10272020, 03:54 PM #10
Hello Tomaz,
That is definitely the correct parameter bit, see the following picture:
I just noticed that you don't have the two expressions being ANDed and ORed enclosed in brackets; wright the above as follows:
IF[[#600EQ1]AND[#602EQ38.]]THEN#654=37.9
IF[[#600EQ1]AND[#602EQ40.]]THEN#654=39.9
IF[[#600EQ2]OR[#600EQ3]]THEN#654=44.2
IF[[#600EQ4]AND[#602EQ38.]]THEN#654=45.9
IF[[#600EQ4]AND[#602EQ40.]]THEN#654=47.9
IF[[#601EQ1]OR[#601EQ4]OR[#601EQ5]]THEN#650=36.9
IF[[#601EQ2]OR[#601EQ3]]THEN#650=46.9
IF[[#601EQ2]OR[#601EQ3]]THEN#656=2
You will have to do the same with the following blocks towards the end of the program.
( VARNOSTNI STAVKI )
IF[#600NE1]OR[#600NE2]OR[#600NE3]OR[#600NE4]GOTO1001
IF[#601NE1]OR[#601NE2]OR[#601NE3]OR[#601NE4]OR[#601NE5]GOTO1002
IF[#602NE38.]OR[#602NE40.]GOTO1003
Regards,
Bill

Tomaz liked this post

10272020, 07:13 PM #11

10282020, 03:28 AM #12
Hello Bill,
Thank you for your support.
Today I'm busy with other jobs. Tomorrow I will continue with this thread.
Regards
Tomaz

10282020, 04:00 AM #13
Today I found that the program works in this version.
I find strange that the program at
IF[[#600NE1]OR[#600NE2]OR[#600NE3]OR[#600NE4]]GOTO1001
jump to N1001  alarm
despite the parameter #600=1
As i sad I will check tomorrow.
Regards
Tomaz
%
O7000
( PODPROGRAM ZA IZRACUN DIMENZIJ )
( NE SPREMINJAJ )
IF[[#600EQ1]AND[#602EQ38.]]THEN#654=37.9
IF[[#600EQ1]AND[#602EQ40.]]THEN#654=39.9
IF[[#600EQ2]OR[#600EQ3]]THEN#654=44.2
IF[[#600EQ4]AND[#602EQ38.]]THEN#654=45.9
IF[[#600EQ4]AND[#602EQ40.]]THEN#654=47.9
IF[[#601EQ1]OR[#601EQ4]OR[#601EQ5]]THEN#650=36.9
IF[[#601EQ2]OR[#601EQ3]]THEN#650=46.9
IF[[#601EQ2]OR[#601EQ3]]THEN#656=2
IF[#601EQ1]THEN#660=31.25
IF[#601EQ1]THEN#656=2
IF[#601EQ1]THEN#655=42.785
IF[#601EQ1]THEN#651=108.
IF[#601EQ2]THEN#651=110.
IF[#601EQ2]THEN#660=31.75
IF[#601EQ3]THEN#660=9.5
IF[#601EQ3]THEN#651=79.
IF[#601EQ4]THEN#651=82.
IF[#601EQ4]THEN#655=29.785
IF[#601EQ4]THEN#656=2
IF[#601EQ4]THEN#660=25.
IF[#601EQ5]THEN#651=52.
IF[#601EQ5]THEN#655=14.285
IF[#601EQ5]THEN#656=1
IF[#601EQ5]THEN#660=8.
#652=[#65118.]
#653=[#651[#650+6.1]]
#657=#652/#656
IF[#656EQ1]THEN#658=2
IF[#656EQ2]THEN#658=1
#659=8
#661=65.
IF[#601EQ5]THEN#661=60.
( VARNOSTNI STAVKI )
IF[[#600NE1]OR[#600NE2]OR[#600NE3]OR[#600NE4]]GOTO1001
IF[[#601NE1]OR[#601NE2]OR[#601NE3]OR[#601NE4]OR[#601NE5]]GOTO1002
IF[[#602NE38.]OR[#602NE40.]]GOTO1003
IF[#605GT#654]GOTO1004
M99
N1001
#3000=1( SAMO STIRJE TIPI PUS  1 2 3 ALI 4 )
N1002
#3000=2( DEFINIRAJ PRAVO SKUPINO ABCDE  1 2 3 4 ALI 5 )
N1003
#3000=3( SAMO PREMERA 38 ALI 40 )
N1004
#3000=4( SVEDER JE VECJI OD NOTRANJEGA PREMERA )
M99
%

10282020, 04:35 AM #14
Hello Tomaz,
Its quite logical actually. If, as you say, #600=1, then that being the case, #600 can't equal 2, 3 or 4, because its equal to 1. Therefore, in your above conditional statement, if #600 doesn't equal ANY of the numbers 1 trough to 4, the conditional statement will test True and execute the GOTO command. In your above conditional statement #600 doesn't equal 2,3 or 4 and any of those will trigger the conditional statement to test True.
If you wanted the logic of the conditional statement to test True only when #600 is not equal to 1,2,3 and 4, then you have to AND all of the components of the conditional statement as in the following example:
IF[[#600NE1]AND[#600NE2]AND[#600NE3]AND[#600NE4]]GOTO1001
In this example, the conditional statement will test true when #600 has a value other than 1,2,3 or 4, and will branch to block number N1001. If #600 equals any of the numbers in the specified set, for example #600=1, then the conditional statement will test False and the program will advance to the next block.
Regards,
Bill

10282020, 06:38 AM #15
Hello boosted,
By the OP's program listed in his Post#13, it appears that the only change made to have the program work, is the addition of brackets around the statements being ANDed, or ORed.
IF[[#600EQ1]AND[#602EQ38.]]THEN#654=37.9, and so on.
Its well documented that the syntax for an IF conditional statement is in the following form:
IF[conditional statement]THEN
In the above, THEN can be replaced by some other action such as GOTO, or a mathematical algorithm, but the syntax of the conditional statement to the left of the action, should be as shown.
In the OP's code example F[[#600EQ1]AND[#602EQ38.]]THEN#654=37.9, the single condition that will result in the statement testing True is the ANDing of two conditions that must also be True. Accordingly, these two conditions form the one conditional statement and therefore, should be in the form of:
IF[conditional statement]THEN
with all the Sub Set conditions making up the Conditional Statement, contained within the brackets.
Regards,
BillLast edited by angelw; 10282020 at 05:14 PM.

10282020, 09:41 AM #16
Hello Bill,
I recognized the error:
IF[[#600NE1]OR[#600NE2]OR[#600NE3]OR[#600NE4]]GOTO1001
[ false true true true ]= true
If any value inside of brackets and using OR function, is false, then the conditional statement is true
As you suggested, the right solution is:
IF[[#600NE1]AND[#600NE2]AND[#600NE3]AND[#600NE4]]GOTO1001
The same mistake I made in the next two blocks:
IF[[#601NE1]OR[#601NE2]OR[#601NE3]OR[#601NE4]OR[#601NE5]]GOTO1002
IF[[#602NE38.]OR[#602NE40.]]GOTO1003
The only accepted entry values for #601 are 1,2,3,4 and 5. For #602 are 38. and 40. If other values are inserted then the machine goes to error.
The right function is AND:
IF[[#601NE1]AND[#601NE2]AND[#601NE3]AND[#601NE4]AND[#601NE5]]GOTO1002
IF[[#602NE38.]AND[#602NE40.]]GOTO1003
Tomorrow I will check the whole program.
Regards
Tomaz
Bookmarks