Invalid characters error when trying to use "IF" statement in GCode
- xph1l
- Topic Author
- Offline
- New Member
Less
More
- Posts: 5
- Thank you received: 0
05 Mar 2023 00:36 #265879
by xph1l
Invalid characters error when trying to use "IF" statement in GCode was created by xph1l
Hi,
My very first post on this forum. Also pretty much my first CNC build - wasn't easy to set everything up in LinuxCNC but I just LOVE it.
I'm using LinuxCNC v2.9.0-pre0 with QtPlasmaC v1.233.249.
The issue I'm having is that when trying to use "if/else/endif" or "while/endwhile" statements in GCode, the QtPlasmaC throws an error "Invalid characters, line has been commented out".
Quick look into the source (main branch) and I found that it is triggered in src/emc/usr_intf/qtplasmac/qtplasmac_gcode.py, in illegal_character() function.
The code that triggered this is:
This check was committed by:
My question is: was this behavior intentional, or was it an error? If intentional, then why?
My very first post on this forum. Also pretty much my first CNC build - wasn't easy to set everything up in LinuxCNC but I just LOVE it.
I'm using LinuxCNC v2.9.0-pre0 with QtPlasmaC v1.233.249.
The issue I'm having is that when trying to use "if/else/endif" or "while/endwhile" statements in GCode, the QtPlasmaC throws an error "Invalid characters, line has been commented out".
Quick look into the source (main branch) and I found that it is triggered in src/emc/usr_intf/qtplasmac/qtplasmac_gcode.py, in illegal_character() function.
The code that triggered this is:
elif line[0].isalpha():
# line starts with two alpha characters (this could be refined)
if line[1].isalpha(): return 1
This check was committed by:
commit 07f8e0af364e7c9594084e2c2b629f3bc45288bf
Author: Phillip Carter <phillcarter54@gmail.com>
Date: Wed Dec 8 14:22:01 2021 +1100
qtplasmac: gcode filter
fix cut recovery bug
add more illegal character checks
My question is: was this behavior intentional, or was it an error? If intentional, then why?
Please Log in or Create an account to join the conversation.
- phillc54
- Offline
- Platinum Member
Less
More
- Posts: 5702
- Thank you received: 2084
05 Mar 2023 00:38 #265880
by phillc54
Replied by phillc54 on topic Invalid characters error when trying to use "IF" statement in GCode
Can you post the gcode.
Please Log in or Create an account to join the conversation.
- xph1l
- Topic Author
- Offline
- New Member
Less
More
- Posts: 5
- Thank you received: 0
05 Mar 2023 00:46 #265881
by xph1l
Replied by xph1l on topic Invalid characters error when trying to use "IF" statement in GCode
Sure thing. The "if" statement at the end of pre-amble is the culprit.
; file name: mill_hook_small.tap
; date and time: Sat Mar 04 2023 09:09:11 PM
; postprocessor: LinuxCNC_PlasmaC_Mod_v1.scpost rev: 0.2
;
;begin pre-amble
G21 (units: metric)
G40 (cutter compensation: off)
G90 (distance mode: absolute)
M52 P1 (adaptive feed: on)
M65 P2 (enable THC)
M65 P3 (enable torch)
M68 E3 Q0 (velocity 100%)
G64 P0.254 Q0.025 (tracking tolerances: 0.254mm)
if [#5400 eq 0]
M30
endif
;end pre-amble
;
;begin material setup
T0 M6 (select plasma tool)
G43 H0 (apply tool offsets)
F#<_hal[plasmac.cut-feed-rate]>
#<holes> = 2 (over-cut for small holes)
#<oclength> = 3.5 (over-cut length)
;end material setup
G0 X12.8 Y16.488
M3 $0 S1 (plasma start)
M67 E3 Q100
G1 X9.901 Y19.387
M67 E3 Q60
G3 X9.901 Y19.387 I2.899 J-2.899
M67 E3 Q100
M5 $0 (plasma end)
Please Log in or Create an account to join the conversation.
- phillc54
- Offline
- Platinum Member
Less
More
- Posts: 5702
- Thank you received: 2084
05 Mar 2023 00:51 #265882
by phillc54
Replied by phillc54 on topic Invalid characters error when trying to use "IF" statement in GCode
You need to use o codes in that case.
linuxcnc.org/docs/html/gcode/o-code.html
e.g.
You can use names instead of numbers:
o<check_m30> instead of o100
linuxcnc.org/docs/html/gcode/o-code.html
e.g.
o100 if [#5400 eq 0]
M30
0100 endif
You can use names instead of numbers:
o<check_m30> instead of o100
Please Log in or Create an account to join the conversation.
- xph1l
- Topic Author
- Offline
- New Member
Less
More
- Posts: 5
- Thank you received: 0
05 Mar 2023 01:07 #265884
by xph1l
Replied by xph1l on topic Invalid characters error when trying to use "IF" statement in GCode
Awesome, it works! Thanks!
Sorry for bothering, but I've brushed over the o-codes page and haven't found the reason for having all conditionals under o-codes and not allowing to use IF as-is.
Maybe you know the reason on top of your head?
Sorry for bothering, but I've brushed over the o-codes page and haven't found the reason for having all conditionals under o-codes and not allowing to use IF as-is.
Maybe you know the reason on top of your head?
Please Log in or Create an account to join the conversation.
- phillc54
- Offline
- Platinum Member
Less
More
- Posts: 5702
- Thank you received: 2084
05 Mar 2023 01:10 #265885
by phillc54
Replied by phillc54 on topic Invalid characters error when trying to use "IF" statement in GCode
Personally I don't know. LinuxCNC follows the RS-274 gcode standards so it is probably part of that standard.
Please Log in or Create an account to join the conversation.
- xph1l
- Topic Author
- Offline
- New Member
Less
More
- Posts: 5
- Thank you received: 0
05 Mar 2023 01:13 #265886
by xph1l
Replied by xph1l on topic Invalid characters error when trying to use "IF" statement in GCode
Got it. Will read up on that. Thanks for the help!
Please Log in or Create an account to join the conversation.
- andypugh
- Away
- Moderator
Less
More
- Posts: 23159
- Thank you received: 4856
06 Mar 2023 23:53 #265992
by andypugh
It's also partly because the parser doesn't have a loop / conditional stack to keep track of which IF belongs to which ENDIF. So the numbered O-words mean that if the condition fails the parser just needs to scan through the G-code waiting for the matching O else or O endif.
Replied by andypugh on topic Invalid characters error when trying to use "IF" statement in GCode
It's partly because of the way G-code consists of single-character commands. The I of "If" is only valid after certain G-codes, but the "F" could be a feed rate command.Sorry for bothering, but I've brushed over the o-codes page and haven't found the reason for having all conditionals under o-codes and not allowing to use IF as-is.
It's also partly because the parser doesn't have a loop / conditional stack to keep track of which IF belongs to which ENDIF. So the numbered O-words mean that if the condition fails the parser just needs to scan through the G-code waiting for the matching O else or O endif.
The following user(s) said Thank You: phillc54
Please Log in or Create an account to join the conversation.
- xph1l
- Topic Author
- Offline
- New Member
Less
More
- Posts: 5
- Thank you received: 0
07 Mar 2023 22:43 #266081
by xph1l
Replied by xph1l on topic Invalid characters error when trying to use "IF" statement in GCode
Oh, it makes sense that O-words make parser less complicated. Thanks for the explanation!
Please Log in or Create an account to join the conversation.
Moderators: snowgoer540
Time to create page: 0.063 seconds