Waiting for a signal - mine not working

More
07 Mar 2013 20:29 #31021 by mariusl
Hi
I am using this piece of code to read a signal and then wait for it to change:

M100
#!/bin/sh
halcmd sets ladder_in 1
~/linuxcnc/nc_files/waitfor ladder_out 1
halcmd sets ladder_in	0

waitfor
#!/bin/bash

if [ $# != 2 ]; then
    echo usage: $0 SignalName DesiredValue
    exit 1
fi

signal=$1
value=$2

while :; do
    set -- $(halcmd -s show sig $signal)
    if [ x"$2" == x"$value" ]; then
        exit 0
    fi
    sleep 1
done

It looks like the code never enters the loop but I have no way of telling. It will exit and turn the signal of right away.

Regards
Marius


www.bluearccnc.com

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

More
07 Mar 2013 20:34 #31022 by BigJohnT
Why are you not using M66 to wait for the input?

John

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

More
07 Mar 2013 20:46 #31023 by mariusl
Hi John
This is just a small piece of code to test why the rest dont work. I have a number of tools and things on the machine that takes various times to open and close. The functions are called via M1xx codes. There are about 10 of them. These are also integrated with a complex ladder logic circuit.

I am using this piece of code (that I got from the wiki) as it seems to be convenient to do it that way. I will program the M codes into the post processor so the customer will not have to remember where to put what. The rest of the machine is already very complex to operate.

P.S. I have not used the M66 before so I cant comment on why not :blush:

Regards
Marius


www.bluearccnc.com

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

More
07 Mar 2013 21:10 #31026 by BigJohnT
In that case why not have the complete function in the M1xx code? Is ladder_in a signal or a pin?

John

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

More
07 Mar 2013 21:28 #31028 by mariusl
ladder_in is a signal. None of the pins are connected directly as they are shared with manual buttons on the vcp as well as some components. So all the manipulation happens on signals or ladder outputs (signals as well).

Regards
Marius


www.bluearccnc.com

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

More
07 Mar 2013 21:39 #31029 by mariusl
I tried to run the M100 in the terminal from the same location where both the files are and then I get an error that "waitfor cannot be found". Any ideas on this?

Regards
Marius


www.bluearccnc.com

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

More
07 Mar 2013 21:43 #31030 by BigJohnT
Yes use ./waitfor to execute a file that is not in the bin directory.

John

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

More
07 Mar 2013 22:11 #31032 by mariusl
I do just that and then this error comes up

bash: ./waitfor: /bin/bash^M: bad interpreter: No such file or directory

these are the permissions
-rwxrwxr-x 1 marius marius 257 2013-03-07 15:44 waitfor

Regards
Marius


www.bluearccnc.com

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

More
07 Mar 2013 22:51 #31034 by BigJohnT
I copied the waitfor text to an empty file and saved it as waitfor in the home directory. I opened a terminal and typed in chmod +x waitfor then ls to confirm the file is an executable then typed in ./waitfor and got the expected usage message.

Is the bin bash line the first line in the file? Have you opened the file on a windoze computer?

John

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

More
07 Mar 2013 23:02 #31035 by mariusl
I could have brought it over from a Windoze machine but I cannot remember any more. Anyway I did like you did and the thing is running in the terminal now. I will test it again on my simulator.

Regards
Marius


www.bluearccnc.com

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

Time to create page: 0.087 seconds
Powered by Kunena Forum