Custom M code, with input check

More
9 years 4 months ago #95211 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:
Code:
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 to join the conversation.

More
9 years 3 months ago #95259 by Todd Zuercher
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

Please Log in to join the conversation.

More
9 years 3 months ago #95353 by andypugh
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
Code:
#! 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

Please Log in to join the conversation.

More
9 years 3 months ago #95486 by HalaszAttila
Thanks for quick replay,
After a little modification, the code works.
Now a can use input pins, in M codes :)

Please Log in to join the conversation.

More
8 years 8 months ago #105563 by anfänger
Can you post your working Code? I'm trying something similar.

Thanks Patrick

Please Log in to join the conversation.

More
8 years 8 months ago #106221 by HalaszAttila
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

Please Log in to join the conversation.

More
8 years 8 months ago #106242 by anfänger
Thanks!

Please Log in to join the conversation.

Time to create page: 3.150 seconds
Powered by Kunena Forum