Custom M code, with input check
- HalaszAttila
- Offline
- Premium Member
Less
More
- Posts: 143
- Thank you received: 5
30 Jun 2017 13:36 #95211
by HalaszAttila
Custom M code, with input check was created by HalaszAttila
Hello,
i want to write custom M code file (M100), which is waiting for digital input signal from mesa 7i77 card.
I think i see somewhere an example in past, but i cant find now.
Can someone please help how to write this program?
I write many M codes based on this manual: linuxcnc.org/docs/html/gcode/m-code.html...html#mcode:m100-m199
But just with digital outputs (halcmd setp ... TRUE/FALSE), not with cycle which continuously reading/waiting for input.
I don know how to read / get the status of digital input.
I want something like this:
Best regards,
Attila.
i want to write custom M code file (M100), which is waiting for digital input signal from mesa 7i77 card.
I think i see somewhere an example in past, but i cant find now.
Can someone please help how to write this program?
I write many M codes based on this manual: linuxcnc.org/docs/html/gcode/m-code.html...html#mcode:m100-m199
But just with digital outputs (halcmd setp ... TRUE/FALSE), not with cycle which continuously reading/waiting for input.
I don know how to read / get the status of digital input.
I want something like this:
cnt = 0;
setp outPin = TRUE; // Turn on hidraulic valve;
while(in != TRUE) { // Waiting on sensor.
sleep(0.1);
cnt++;
if(cnt > 100) {
timeoutErrorPIN = TRUE; // This pin will generate ESTOP!
exit();
}
}
exit();
Best regards,
Attila.
Please Log in or Create an account to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
Less
More
- Posts: 5007
- Thank you received: 1441
01 Jul 2017 02:04 #95259
by Todd Zuercher
Replied by Todd Zuercher on topic Custom M code, with input check
Depending what exactly you are trying to do this might actually be simpler with just a simple o-sub anc an M66.
linuxcnc.org/docs/html/gcode/m-code.html#mcode:m66
linuxcnc.org/docs/html/gcode/m-code.html#mcode:m66
The following user(s) said Thank You: HalaszAttila
Please Log in or Create an account to join the conversation.
04 Jul 2017 11:47 #95353
by andypugh
Replied by andypugh on topic Custom M code, with input check
I am not an expert with bash, and am not currently at a Linux machine, but something a bit like this ought to work.
stackoverflow.com/questions/12321469/ret...command-with-timeout
stackoverflow.com/questions/12321469/ret...command-with-timeout
#! bin/bash
NEXT_WAIT_TIME=0
COMMAND_STATUS=1
until [ $COMMAND_STATUS -eq 0 || $NEXT_WAIT_TIME -eq 4 ]; do
halcmd getp hm2_5i25.0.7i77.0.0.input-00-not
COMMAND_STATUS=$?
sleep $NEXT_WAIT_TIME
let NEXT_WAIT_TIME=NEXT_WAIT_TIME+1
done
The following user(s) said Thank You: HalaszAttila
Please Log in or Create an account to join the conversation.
- HalaszAttila
- Offline
- Premium Member
Less
More
- Posts: 143
- Thank you received: 5
07 Jul 2017 21:04 #95486
by HalaszAttila
Replied by HalaszAttila on topic Custom M code, with input check
Thanks for quick replay,
After a little modification, the code works.
Now a can use input pins, in M codes
After a little modification, the code works.
Now a can use input pins, in M codes
Please Log in or Create an account to join the conversation.
08 Feb 2018 11:51 #105563
by anfänger
Replied by anfänger on topic Custom M code, with input check
Can you post your working Code? I'm trying something similar.
Thanks Patrick
Thanks Patrick
Please Log in or Create an account to join the conversation.
- HalaszAttila
- Offline
- Premium Member
Less
More
- Posts: 143
- Thank you received: 5
20 Feb 2018 09:06 #106221
by HalaszAttila
Replied by HalaszAttila on topic Custom M code, with input check
Hello,
sorry for late post. Here is the working code:
#!/bin/bash
A=0
CNT=0
until [ "$A" = TRUE ]; do
A=$(halcmd getp hm2_5i25.0.7i77.0.0.input-27)
sleep 0.5
let CNT=CNT+1
if [ "$CNT" = 10 ]; then
halcmd sets spindleGearChangeTimeoutAlarm TRUE
sleep 0.1
halcmd sets spindleGearChangeTimeoutAlarm FALSE
exit 0
fi
done
exit 0
sorry for late post. Here is the working code:
#!/bin/bash
A=0
CNT=0
until [ "$A" = TRUE ]; do
A=$(halcmd getp hm2_5i25.0.7i77.0.0.input-27)
sleep 0.5
let CNT=CNT+1
if [ "$CNT" = 10 ]; then
halcmd sets spindleGearChangeTimeoutAlarm TRUE
sleep 0.1
halcmd sets spindleGearChangeTimeoutAlarm FALSE
exit 0
fi
done
exit 0
The following user(s) said Thank You: anfänger
Please Log in or Create an account to join the conversation.
20 Feb 2018 17:49 #106242
by anfänger
Replied by anfänger on topic Custom M code, with input check
Thanks!
Please Log in or Create an account to join the conversation.
Time to create page: 0.083 seconds