# This script shows an example to integrate an extruder with RoboDK # We need to add this script to the RoboDK project ot trigger sending the E value (Extruder parameter) # This script meant to work when we are running 3D printing with the driver ("Run on robot" option) # Send the E_Value over Ethernet (ASCII numbers) EXTRUDER_IP = '192.168.1.15' # The IP of the extruder EXTRUDER_PORT = 100 # The same port as used by the Extruder server E_Value = None # ilośc extrudera from robolink import * # API to communicate with RoboDK from robodk import * # basic matrix operations # Start RoboDK API RDK = Robolink() # Sprawdź, czy uruchamiamy ten program w innym programie i przekazujemy argumenty # dla Extrudera - ilośc podawanego filamentu import sys if len(sys.argv) > 1: E_Value = float(sys.argv[1]) code = 'G1 E ' + str(E_Value) # If no value is provided, display a message to turn the extruder ON or OFF if E_Value is None: print('Note: This macro can be called as Extruder(0) to turn it ON or Extruder(-1) to turn it OFF') entry = mbox('Turn Extruder ON or OFF', ('On', '1'), ('Off', '-1')) if not entry: quit() E_Value = int(entry) #print(message) wyskakujące okno #RDK.ShowMessage(code, popup=True) # dla celów testowych ustaw na True dla wyskakujących okienek, ustaw na false lub skomentuj, aby uniknąć blokowania #Opcjonalnie zignoruj wysyłanie polecenia, jeśli pracujemy w trybie symulacji # STOP przestań, jeśli jesteśmy w trybie symulacji #if RDK.RunMode() == RUNMODE_SIMULATE: # quit() # Implement socket communication to send the E_Value over Ethernet/socket import socket BUFFER_SIZE = 1024 # Build the byte array to send bytes2send = bytes(code +'\0', 'ascii') #bytes2send = bytes('G1 E' + str(E_Value) + '\0', 'ascii') print("Sending: " + str(bytes2send)) print("Connecting to %s:%i" % (EXTRUDER_IP, EXTRUDER_PORT)) # Connect to the extruder and send byte array s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((EXTRUDER_IP, EXTRUDER_PORT)) s.send(bytes2send) # Read response: #bytes_recv = s.recv(BUFFER_SIZE) #str_recv = bytes_recv.decode('ascii') s.close() #print("Response: " + str_recv) # >>>>>>>>>>pętla>>>>>>>>>>>>>>>>>>>> #while True: #bytes_recv = s.recv(BUFFER_SIZE) #str_recv = bytes_recv.decode('ascii') #if "helo" in str_recv: #s.send(bytes('OK','ascii')) #s.close() #print("Odpowidź: " + str_recv) # return True #else: #bytes2send = bytes('blad','ascii') #s.send(bytes('blad','ascii')) #s.close() #return False #return False