# Fullmo MovingCap CODE - micropython example. # original file name: check_IN1_from_neighbors_via_REFGO.py # id: check_IN1_from_neighbors.py oh 2026-03-11 import mcdrive as mc import mcnet import time refgo_port_str = ":10001" neighbor1_IN1_status = -1 # -1 = not available, 0 = IN1 low, 1 = IN1 high neighbor2_IN1_status = -1 neighbor1_connected = False neighbor2_connected = False ip_base = str(mc.ReadObject(0x5007, 1)) + "." + str(mc.ReadObject(0x5007, 2)) + "." + str(mc.ReadObject(0x5007, 3)) + "." my_ip = ip_base + str(mc.ReadObject(0x5007, 4)) neighbor1_end_ip = mc.ReadObject(0x340B, 0x9) neighbor1_ip = ip_base + str(neighbor1_end_ip) if neighbor1_end_ip > 0 else None neighbor2_end_ip = mc.ReadObject(0x340B, 0xA) neighbor2_ip = ip_base + str(neighbor2_end_ip) if neighbor2_end_ip > 0 else None print ("my_ip: " + my_ip) print ("neighbor1_ip: " + str(neighbor1_ip)) print ("neighbor2_ip: " + str(neighbor2_ip)) a def check_neighbor(mc_net_obj): result = -1 if mc_net_obj.is_connected(): print("checking object " + str(mc_net_obj)) # evaluate previous answer readout = mc_net_obj.read_until(b'\r\n') print("readout=" + str(readout)) if readout == b'TI1\r\n': readout = mc_net_obj.read_until(b'\r\n') print("readout=" + str(readout)) result = int(readout) else: result = -1 # not available # we can ignore the rest, e.g. the prompt ">" indicating "ready for next command" mc_net_obj.reset_input_buffer() mc_net_obj.write(b'TI1\r') return result # Connect to the neighbouring drive's REFGO TCP interfaces if neighbor1_ip is not None: neighbor1_refgo = mcnet.McNet(neighbor1_ip + refgo_port_str) if neighbor2_ip is not None: neighbor2_refgo = mcnet.McNet(neighbor2_ip + refgo_port_str) while True: # manual reconnect code (future versions of mcnet may handle this automatically) if neighbor1_ip is not None: if neighbor1_refgo.is_connected(): if not neighbor1_connected: print(neighbor1_ip + " connected") neighbor1_connected = True else: if neighbor1_connected: print(neighbor1_ip + " reconnect attempt") neighbor1_connected = False neighbor1_refgo.close() neighbor1_refgo.open(neighbor1_ip + refgo_port_str) else: print(neighbor1_ip + " waiting for connection...") if neighbor2_ip is not None: if neighbor2_refgo.is_connected(): if not neighbor2_connected: print(neighbor2_ip + " connected") neighbor2_connected = True else: if neighbor2_connected: print(neighbor2_ip + " reconnect attempt") neighbor2_connected = False neighbor2_refgo.close() neighbor2_refgo.open(neighbor2_ip + refgo_port_str) else: print(neighbor2_ip + " waiting for connection...") # main logic: how are you doing, neighbor? (i.e. what is your IN1 value?) if neighbor1_ip is not None: neighbor1_IN1_status = check_neighbor(neighbor1_refgo) if neighbor2_ip is not None: neighbor2_IN1_status = check_neighbor(neighbor2_refgo) print("neighbor1_IN1_status=" + str(neighbor1_IN1_status) + ", neighbor2_IN1_status=" + str(neighbor2_IN1_status)) time.sleep_ms(500)