Custom M code, with input check

More
30 Jun 2017 13:36 #95211 by HalaszAttila
HalaszAttila created the topic: Custom M code, with input check
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: http://linuxcnc.org/docs/html/gcode/m-code.html#mcode:m100-m199http://linuxcnc.org/docs/html/gcode/m-code.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.
More
01 Jul 2017 02:04 #95259 by Todd Zuercher
Todd Zuercher replied the 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
The following user(s) said Thank You: HalaszAttila
More
04 Jul 2017 11:47 #95353 by andypugh
andypugh replied the 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
#! 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
More
07 Jul 2017 21:04 #95486 by HalaszAttila
HalaszAttila replied the 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 :)
Time to create page: 0.076 seconds
Powered by Kunena Forum