- Posts: 27
- Thank you received: 0
Reading value of pin in g code
- Radek
- Offline
- Junior Member
-
Less
More
9 years 7 months ago - 9 years 7 months ago #89991
by Radek
Reading value of pin in g code was created by Radek
Hi, I want to make if loop and don't know how to write it properly. The task is: if state of coil1 (in classicladder) is 1 then make something. Coil1 is assigned to pin P01.
I tried with:
or simple
I got this error:
I tried with:
Code:
o100 if [M66 P01 L3 Q999999]
...
o100 endif
Code:
o100 if [P01 = 1](funny creating ;) )
I got this error:
Unknown word where unary operation could be
Last edit: 9 years 7 months ago by Radek.
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
-
Less
More
- Posts: 19899
- Thank you received: 4655
9 years 7 months ago #90122
by andypugh
Replied by andypugh on topic Reading value of pin in g code
There are a number of issues here.
Firstly, to check for equality in G-code you have to use "EQ"
O100 IF [#124 EQ 100]
Do Stuff
O100 ENDIF
linuxcnc.org/docs/2.7/html/gcode/overvie...ode:binary-operators
It is possible to read HAL pins in G-code, but the feature needs to be turned-on.
linuxcnc.org/docs/2.7/html/remap/remap.h...i_file_configuration
I wouldn't recommend doing that in this case, though. The problem is that the values are read at preview-time, not at run-time. This could cause unexpected results.
Much better to "net" the classicladder pin to one of the G-code digital input pins and use M66 to read it.
linuxcnc.org/docs/2.7/html/gcode/m-code.html#mcode:m66
Firstly, to check for equality in G-code you have to use "EQ"
O100 IF [#124 EQ 100]
Do Stuff
O100 ENDIF
linuxcnc.org/docs/2.7/html/gcode/overvie...ode:binary-operators
It is possible to read HAL pins in G-code, but the feature needs to be turned-on.
linuxcnc.org/docs/2.7/html/remap/remap.h...i_file_configuration
I wouldn't recommend doing that in this case, though. The problem is that the values are read at preview-time, not at run-time. This could cause unexpected results.
Much better to "net" the classicladder pin to one of the G-code digital input pins and use M66 to read it.
linuxcnc.org/docs/2.7/html/gcode/m-code.html#mcode:m66
Please Log in or Create an account to join the conversation.
- Radek
- Offline
- Junior Member
-
Less
More
- Posts: 27
- Thank you received: 0
9 years 7 months ago - 9 years 7 months ago #90173
by Radek
Replied by Radek on topic Reading value of pin in g code
I knew this comands, but i can't use it properly. While loop is working well.
My unfortunately bad ideas ....
also try with GOTO.. here is one of my bad codes..
and there is an error:
My unfortunately bad ideas ....
Code:
o100 if [M66 P1 L3 Q99999999]
Code:
#1 = M66 P1 L3 Q99999999
o100 if [#1 EQ 1]
also try with GOTO.. here is one of my bad codes..
Code:
M66 P01 L3 Q99999999 N100 GOTO 110
M66 P02 L3 Q99999999 N120 GOTO 130
M66 P03 L3 Q99999999 N140 GOTO 150
bad character n used
Last edit: 9 years 7 months ago by Radek.
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
-
Less
More
- Posts: 19899
- Thank you received: 4655
9 years 7 months ago #90177
by andypugh
The key is the phrase "The current value of the input is stored in parameter #5399"
Though normally you don't need to check the value as you use it in a "wait for state" mode and just need to check for timeout.
Replied by andypugh on topic Reading value of pin in g code
Radek wrote: I knew this comands, but i can't use it properly.
The key is the phrase "The current value of the input is stored in parameter #5399"
Code:
M66 P1 L0
o100 if [#5399 EQ 1]
Though normally you don't need to check the value as you use it in a "wait for state" mode and just need to check for timeout.
The following user(s) said Thank You: Radek
Please Log in or Create an account to join the conversation.
- Radek
- Offline
- Junior Member
-
Less
More
- Posts: 27
- Thank you received: 0
9 years 7 months ago - 9 years 7 months ago #90179
by Radek
Replied by Radek on topic Reading value of pin in g code
Ok, but now i want to back to 1st line of programme. What command should i use? GOTO ?
Ok... shit happens.. it's not working
Ok... shit happens.. it's not working
Code:
M66 P11 L0
o100 if [#5399 EQ 1]
Do stuff
o100 endif
M66 P12 L0
o110 if [#5399 EQ 1]
Do stuff
o110 endif
M66 P13 L0
o120 if [#5399 EQ 1]
Do stuff
o120 endif
Last edit: 9 years 7 months ago by Radek.
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
-
Less
More
- Posts: 19899
- Thank you received: 4655
9 years 7 months ago #90201
by andypugh
Do you want it to run for ever?
There is no GOTO in G-code:
linuxcnc.org/docs/2.7/html/gcode/o-code.html
Replied by andypugh on topic Reading value of pin in g code
Radek wrote: Ok, but now i want to back to 1st line of programme. What command should i use? GOTO ?
Do you want it to run for ever?
Code:
O500 WHILE [1 EQ 1]
Do Stuff
O500 ENDWHILE
There is no GOTO in G-code:
linuxcnc.org/docs/2.7/html/gcode/o-code.html
Please Log in or Create an account to join the conversation.
Time to create page: 0.726 seconds