Quote from
erwan on 19 February 2025, 17:52
Here is a starting approach, but I don't know how to code the offset.
I also don't know how to make this code run in a loop on SimCNC.
I have always executed Python code based on a G-code command.
For example, if M6 is called in the G-code, then the Python script M6.py is executed.
# Define physical inputs on the CSMIO/IP-S
input_start = 10 # Input number for start
input_pause = 11 # Input number for pause
input_offset = 12 # Input number for X+20 offset
# Function to read inputs and take action accordingly
def check_buttons():
mod_IP = d.getModule(ModuleType.IP, 0) # Connect to CSMIO/IP-S
if mod_IP.getDigitalIO(IOPortDir.InputPort, input_start) == DIOPinVal.PinSet:
print("Button 1 pressed: Machine started")
d.enableMachine(True) # Enable the machine
if mod_IP.getDigitalIO(IOPortDir.InputPort, input_pause) == DIOPinVal.PinSet:
print("Button 2 pressed: Machine paused")
d.enableMachine(False) # Disable the machine
if mod_IP.getDigitalIO(IOPortDir.InputPort, input_offset) == DIOPinVal.PinSet:
print("Button 3 pressed: Offset X+20")
d.execCode("G92 X+20") # Send G92 X+20 to the controller
# Main loop (if needed, adjust based on your setup)
while True:
check_buttons()
time.sleep(0.1) # Small delay to prevent spamming
Here is a starting approach, but I don't know how to code the offset.
I also don't know how to make this code run in a loop on SimCNC.
I have always executed Python code based on a G-code command.
For example, if M6 is called in the G-code, then the Python script M6.py is executed.
# Define physical inputs on the CSMIO/IP-S
input_start = 10 # Input number for start
input_pause = 11 # Input number for pause
input_offset = 12 # Input number for X+20 offset
# Function to read inputs and take action accordingly
def check_buttons():
mod_IP = d.getModule(ModuleType.IP, 0) # Connect to CSMIO/IP-S
if mod_IP.getDigitalIO(IOPortDir.InputPort, input_start) == DIOPinVal.PinSet:
print("Button 1 pressed: Machine started")
d.enableMachine(True) # Enable the machine
if mod_IP.getDigitalIO(IOPortDir.InputPort, input_pause) == DIOPinVal.PinSet:
print("Button 2 pressed: Machine paused")
d.enableMachine(False) # Disable the machine
if mod_IP.getDigitalIO(IOPortDir.InputPort, input_offset) == DIOPinVal.PinSet:
print("Button 3 pressed: Offset X+20")
d.execCode("G92 X+20") # Send G92 X+20 to the controller
# Main loop (if needed, adjust based on your setup)
while True:
check_buttons()
time.sleep(0.1) # Small delay to prevent spamming