Reading value of pin in g code

More
21 Mar 2017 09:57 - 21 Mar 2017 09:59 #89991 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:
o100 if [M66 P01 L3 Q999999]
...
o100 endif
or simple
o100 if [P01 = 1](funny creating ;) )

I got this error:

Unknown word where unary operation could be

Last edit: 21 Mar 2017 09:59 by Radek.

Please Log in or Create an account to join the conversation.

More
23 Mar 2017 15:28 #90122 by andypugh
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

Please Log in or Create an account to join the conversation.

More
24 Mar 2017 07:51 - 24 Mar 2017 08:33 #90173 by Radek
I knew this comands, but i can't use it properly. While loop is working well.
My unfortunately bad ideas ....
o100 if [M66 P1 L3 Q99999999]
#1 = M66 P1 L3 Q99999999
o100 if [#1 EQ 1]

also try with GOTO.. here is one of my bad codes..
M66 P01 L3 Q99999999 N100 GOTO 110
M66 P02 L3 Q99999999 N120 GOTO 130
M66 P03 L3 Q99999999 N140 GOTO 150 
and there is an error:

bad character n used

Last edit: 24 Mar 2017 08:33 by Radek.

Please Log in or Create an account to join the conversation.

More
24 Mar 2017 09:05 #90177 by andypugh

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"
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.

More
24 Mar 2017 09:28 - 24 Mar 2017 11:54 #90179 by Radek
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
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: 24 Mar 2017 11:54 by Radek.

Please Log in or Create an account to join the conversation.

More
24 Mar 2017 13:08 #90201 by andypugh

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?
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.

More
24 Mar 2017 13:12 #90204 by Radek
I got while loop, but i need also if but it doesn't work.. are there any mistakes in my code ?

Please Log in or Create an account to join the conversation.

More
24 Mar 2017 13:16 #90206 by andypugh

I got while loop, but i need also if but it doesn't work.. are there any mistakes in my code ?


Well, the command "Do Stuff" if it is literally in the code won't help.

By default there are only 4 digital input pins, so your P11, P12, P13 are likely to cause trouble.

Please Log in or Create an account to join the conversation.

More
24 Mar 2017 13:30 #90209 by Radek

I got while loop, but i need also if but it doesn't work.. are there any mistakes in my code ?


Well, the command "Do Stuff" if it is literally in the code won't help.

By default there are only 4 digital input pins, so your P11, P12, P13 are likely to cause trouble.


this is my code... While is working properly, but if not. Why? I want also to back to the 1st line of programme after endif.
Attachments:

Please Log in or Create an account to join the conversation.

More
24 Mar 2017 14:03 #90210 by andypugh
What error message do you get?

Please Log in or Create an account to join the conversation.

Time to create page: 0.225 seconds
Powered by Kunena Forum