Problem with custom M code

More
20 Feb 2025 18:39 - 20 Feb 2025 18:43 #322100 by Leo90
Problem with custom M code was created by Leo90
Hi all. I need help with my custom M code I've started to write. I ran into a problem right at the beginning with an "if" statement. My M code should be M105 P100 and it seems the "P" value isn't transfered into the M code. 
​​​
#!/bin/bash

operand="$1"

if [[ "$operand" == 100 ]]; then
    halcmd setp lcec.0.EL2008.dout-0 true
    echo "ok"
else
    halcmd setp lcec.0.EL2008.dout-1 true
    exit 1
fi

exit 0
The M code always outputs "else" condition so "operand" isn't 100 as expected. 

I also wrote a similar M code with "case" and there the P value is recognised by bash. 

What did I do wrong here?
Last edit: 20 Feb 2025 18:43 by Leo90.

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

  • Aciera
  • Aciera's Avatar
  • Away
  • Administrator
  • Administrator
More
20 Feb 2025 20:05 #322104 by Aciera
Replied by Aciera on topic Problem with custom M code
Problem is that $1 contains a float which bash can't handle, so try:
if [[ ${operand%\.*} -eq 100 ]]; then
The following user(s) said Thank You: Leo90

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

More
21 Feb 2025 22:46 #322243 by Leo90
Replied by Leo90 on topic Problem with custom M code
@Aciera thank you very much. It worked flawlessly. I knew I can count on you guys :)
The following user(s) said Thank You: tommylight

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

Time to create page: 0.050 seconds
Powered by Kunena Forum