Custom M code, with input check

More
30 Jun 2017 13:36 #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:
	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.

More
01 Jul 2017 02:04 #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
The following user(s) said Thank You: HalaszAttila

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

More
04 Jul 2017 11:47 #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
#! 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.

More
07 Jul 2017 21:04 #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 or Create an account to join the conversation.

More
08 Feb 2018 11:51 #105563 by anfänger
Can you post your working Code? I'm trying something similar.

Thanks Patrick

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

More
20 Feb 2018 09:06 #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
The following user(s) said Thank You: anfänger

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

More
20 Feb 2018 17:49 #106242 by anfänger
Thanks!

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

Time to create page: 0.131 seconds
Powered by Kunena Forum