Run python script automaticly after halui on linuxcnc startup

More
3 years 1 month ago #280935 by Donno
I have a python script that controls a panel but have to start it manually in terminal on linuxcnc startup, how can this be done automatically after halui is loaded ?

Please Log in to join the conversation.

More
3 years 1 month ago #280937 by zz912
You can set HAL pin of your script in postgui.hal. This can run it.

Please Log in to join the conversation.

More
3 years 1 month ago #280943 by Donno

Please Log in to join the conversation.

More
3 years 1 month ago #280944 by Donno
Code:
#SET INI File #    [DISPLAY] #    INCREMENTS = 0.1 mm, .1mm, 10mm #    USER_COMMAND_FILE = axis_hal_jog_speed.py import time import serial import hal import sys import linuxcnc import threading import atexit import os linux_stat_flood = "" linux_stat_spindle_enable = "" linux_stat_spindle_direction = "" linux_axisui_jog_increment = 0 Panel_Value_array = [] HALComponentReady = False time_var = 1 Xjoint_num = 0 Zjoint_num = 2 ser = serial.Serial('/dev/ttyUSB0', 500000, timeout=0.050) s = linuxcnc.stat() c = linuxcnc.command() def my_func():     # Dummy Function     print('Dummy') def LinuxCNCEvent(serial_port):     global h     global s     global linux_stat_flood     global linux_stat_spindle_enable     global linux_stat_spindle_direction     global linux_axisui_jog_increment     global time_var     s.poll()          if not hal.get_value("halui.estop.is-activated") and hal.get_value("halui.machine.on") and not hal.get_value("halui.machine.is-on"):         LinuxSW(0,"EVENT")         time.sleep(0.2)         LinuxSW(1,"EVENT")         time.sleep(0.2)          if linux_axisui_jog_increment != h['Incremental']:         print("Linux_Event Jog_Increment "+str(round(h['Incremental'],1)))         IncCont(round(h['Incremental'],1),"EVENT_UI")                   if linux_stat_flood == "":         linux_stat_flood = hal.get_value("halui.flood.is-on")     else:         if linux_stat_flood != hal.get_value("halui.flood.is-on"):             if hal.get_value("halui.flood.is-on"):                 serial_port.write("SET l_csw 1".encode('utf-8'))             else:                 serial_port.write("SET l_csw 0".encode('utf-8'))                             linux_stat_flood = hal.get_value("halui.flood.is-on")             print("Linux_Event Flood "+str(hal.get_value("halui.flood.is-on")))             time.sleep(time_var)                  if linux_stat_spindle_enable == "" or linux_stat_spindle_direction == "":         linux_stat_spindle_enable = s.spindle[0]["enabled"]         if s.spindle[0]["enabled"] == 0:             linux_stat_spindle_direction = s.spindle[0]["direction"]             serial_port.write("SET l_dir 0".encode('utf-8'))             time.sleep(time_var)         if s.spindle[0]["enabled"] == 1:             linux_stat_spindle_direction = s.spindle[0]["direction"]             if s.spindle[0]["direction"] == -1:                 serial_port.write("SET l_dir 2".encode('utf-8'))                                 time.sleep(time_var)             if s.spindle[0]["direction"] == 1:                 serial_port.write("SET l_dir 1".encode('utf-8'))                                  time.sleep(time_var)                       print("LinuxCNC_Event SPINDLE_ENABLE "+str(s.spindle[0]["enabled"]) )         print("LinuxCNC_Event SPINDLE_DIRECTION "+str(s.spindle[0]["direction"]))     else:         if linux_stat_spindle_enable != s.spindle[0]["enabled"] or linux_stat_spindle_direction != s.spindle[0]["direction"]:             linux_stat_spindle_enable = s.spindle[0]["enabled"]             if s.spindle[0]["enabled"] == 0:                 linux_stat_spindle_direction = s.spindle[0]["direction"]                 serial_port.write("SET l_dir 0".encode('utf-8'))                 time.sleep(time_var)             if s.spindle[0]["enabled"] == 1:                 linux_stat_spindle_direction = s.spindle[0]["direction"]                 if s.spindle[0]["direction"] == -1:                     serial_port.write("SET l_dir 2".encode('utf-8'))                                     time.sleep(time_var)                 if s.spindle[0]["direction"] == 1:                     serial_port.write("SET l_dir 1".encode('utf-8'))                                      time.sleep(time_var)                           print("LinuxCNC_Event SPINDLE_ENABLE "+str(s.spindle[0]["enabled"]) )             print("LinuxCNC_Event SPINDLE_DIRECTION "+str(s.spindle[0]["direction"])) def LinuxSW(Value = 0,State = "INIT"):     global h     if State == "INIT":         print('-',end="")         h.newpin("LinuxSW",hal.HAL_BIT,hal.HAL_IN)         h.newpin("LinuxSW_NOT",hal.HAL_BIT,hal.HAL_IN)     if State == "EVENT":         h["LinuxSW"] = Value         h["LinuxSW_NOT"] = not Value     if State == "SET":         h["LinuxSW"] = Value         h["LinuxSW_NOT"] = not Value         #net ConnectPowerON  halui.machine.on => DonnoPanel.LinuxSW         hal.new_sig("ConnectPowerON",hal.HAL_BIT)         hal.connect('DonnoPanel.LinuxSW',"ConnectPowerON")         hal.connect('halui.machine.on',"ConnectPowerON")         #net ConnectPowerOFF  halui.machine.off => DonnoPanel.LinuxSW_NOT         hal.new_sig("ConnectPowerOFF",hal.HAL_BIT)         hal.connect('DonnoPanel.LinuxSW_NOT',"ConnectPowerOFF")            hal.connect('halui.machine.off',"ConnectPowerOFF")                  print('-',end="") def MH1(Value = 0,State = "INIT"):     global c     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 1:                 print('Event MH1')             os.system ("axis-remote /home/donno/linuxcnc/nc_files/MH1.ngc")     if State == "SET":         print('-',end="")      def MH2(Value = 0,State = "INIT"):     global c     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 1:                 print('Event MH2')             os.system ("axis-remote /home/donno/linuxcnc/nc_files/MH2.ngc")     if State == "SET":         print('-',end="")             def FH1(Value = 0,State = "INIT"):     global c     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 1:                 print('Event FH1')             os.system ("axis-remote /home/donno/linuxcnc/nc_files/FH1.ngc")     if State == "SET":         print('-',end="")             def FH2(Value = 0,State = "INIT"):     global c     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 1:                 print('Event FH2')             os.system ("axis-remote /home/donno/linuxcnc/nc_files/FH2.ngc")     if State == "SET":         print('-',end="")   def IncCont(Value = 0,State = "INIT"):     Value = float(Value)     global Panel_Value_array     global linux_axisui_jog_increment     global c     global time_var     global ser     if State == "INIT":         print('-',end="")         h.newpin("Incremental",hal.HAL_FLOAT,hal.HAL_IN)         h.newpin("Incremental-menu-value",hal.HAL_U32,hal.HAL_IN)         h.newpin("Incremental-menu-set",hal.HAL_BIT, hal.HAL_IN)         h.newpin("Feed_scale",hal.HAL_FLOAT,hal.HAL_IN)         h.newpin("Rapid_scale",hal.HAL_FLOAT,hal.HAL_IN)         h.newpin("SpindleOver_scale",hal.HAL_FLOAT,hal.HAL_IN)         h.newpin("MaxVel_scale",hal.HAL_FLOAT,hal.HAL_IN)         h.newpin("JogSpeed",hal.HAL_FLOAT,hal.HAL_IN)     if State == "EVENT_UI":         for index, item in enumerate(Panel_Value_array):             if Panel_Value_array[index][0] == "IncCont":                 if Value == 0:                     ser.write("SET l_inc 1".encode('utf-8'))                     Panel_Value_array[index][2] = Panel_Value_array[index][1]                     Panel_Value_array[index][1] = 0                     h['Incremental'] = Panel_Value_array[index][1]                     linux_axisui_jog_increment = h['Incremental']                     time.sleep(time_var)                       print('Continua all off')                                 elif Value == 0.1:                     ser.write("SET l_p1 1".encode('utf-8'))                     Panel_Value_array[index][2] = Panel_Value_array[index][1]                     Panel_Value_array[index][1] = 0.1                     h['Incremental'] = 0.1                     linux_axisui_jog_increment = h['Incremental']                     time.sleep(time_var)                     print('Increment 0.1')                                 elif Value == 1:                     ser.write("SET l_1p 1".encode('utf-8'))                     Panel_Value_array[index][2] = float(Panel_Value_array[index][1])                     Panel_Value_array[index][1] = float(1)                     h['Incremental'] = 1                     linux_axisui_jog_increment = h['Incremental']                     time.sleep(time_var)                     print('Increment 1')                                 elif Value == 10:                                     ser.write("SET l_10p 1".encode('utf-8'))                     Panel_Value_array[index][2] = Panel_Value_array[index][1]                     Panel_Value_array[index][1] = 10                     h['Incremental'] = 10                     linux_axisui_jog_increment = h['Incremental']                     time.sleep(time_var)                     print('Increment 10')                                print('IncCont event_ui '+str(Panel_Value_array[index][1]))                      if State == "EVENT":         for index, item in enumerate(Panel_Value_array):             if Panel_Value_array[index][0] == "IncCont":                 if Value == 1 and Panel_Value_array[index][1] > 0:                     h['Incremental-menu-value'] = 0                     h['Incremental-menu-set'] = 1                     print('Continua all off')                 elif Value == 1 and Panel_Value_array[index][1] == 0:                     if Panel_Value_array[index][2] == 0.1:                         h['Incremental-menu-value'] = 1                         h['Incremental-menu-set'] = 1                     if Panel_Value_array[index][2] == 1:                         h['Incremental-menu-value'] = 2                         h['Incremental-menu-set'] = 1                     if Panel_Value_array[index][2] == 10:                         h['Incremental-menu-value'] = 3                         h['Incremental-menu-set'] = 1                     print('Increment previos setting which = '+str(Panel_Value_array[index][2]))                 elif Value == 10:                     h['Incremental-menu-value'] = 1                     h['Incremental-menu-set'] = 1                     print('Increment 0.1')                 elif Value == 100:                     h['Incremental-menu-value'] = 2                     h['Incremental-menu-set'] = 1                     print('Increment 1')                 elif Value == 1000:                     h['Incremental-menu-value'] = 3                     h['Incremental-menu-set'] = 1                     print('Increment 10')                 print('IncCont event '+str(Panel_Value_array[index][1]))                      if State == "SET":         #net IncrementalSelection  axisui.jog.increment => DonnoPanel.Incremental         hal.new_sig("IncrementalSelection",hal.HAL_FLOAT)         hal.connect('DonnoPanel.Incremental',"IncrementalSelection")         hal.connect('axisui.jog.increment',"IncrementalSelection")         #Trigger Event to change menu         hal.new_sig("IncrementalSelectionMenu",hal.HAL_BIT)         hal.connect('DonnoPanel.Incremental-menu-set',"IncrementalSelectionMenu")         hal.connect('axisui.jog.increment-menu.set',"IncrementalSelectionMenu")         #Value to change menu         hal.new_sig("IncrementalMenuValue",hal.HAL_U32)         hal.connect('DonnoPanel.Incremental-menu-value',"IncrementalMenuValue")         hal.connect('axisui.jog.increment-menu.value',"IncrementalMenuValue")             #Feed Scale         hal.new_sig("FeedScaleSignal",hal.HAL_FLOAT)         hal.connect('DonnoPanel.Feed_scale',"FeedScaleSignal")         hal.connect('halui.feed-override.scale',"FeedScaleSignal")         #Rapid_scale         hal.new_sig("RapidScaleSignal",hal.HAL_FLOAT)         hal.connect('DonnoPanel.Rapid_scale',"RapidScaleSignal")         hal.connect('halui.rapid-override.scale',"RapidScaleSignal")           #SpindleOver_scale         hal.new_sig("SpindleOverScaleSignal",hal.HAL_FLOAT)         hal.connect('DonnoPanel.SpindleOver_scale',"SpindleOverScaleSignal")         hal.connect('halui.spindle.0.override.scale',"SpindleOverScaleSignal")         #MaxVel_scale         hal.new_sig("MaxVelScaleSignal",hal.HAL_FLOAT)         hal.connect('DonnoPanel.MaxVel_scale',"MaxVelScaleSignal")         hal.connect('halui.max-velocity.scale',"MaxVelScaleSignal")                  #JogSpeed         hal.new_sig("JogSpeedSignal",hal.HAL_FLOAT)         hal.connect('DonnoPanel.JogSpeed',"JogSpeedSignal")         hal.connect('axisui.jog.speed',"JogSpeedSignal")           for index, item in enumerate(Panel_Value_array):             if Panel_Value_array[index][0] == "IncCont":                 ser.write("SET l_inc 1".encode('utf-8'))                 Panel_Value_array[index][1] = float(0)                 Panel_Value_array[index][2] = float(1)                 h['Inremental'] = float(0)                 linux_axisui_jog_increment = 0                 time.sleep(time_var)                 print('-',end="")                                   def IP1(Value = 0,State = "INIT"):     Value = int(Value)     global Panel_Value_array     global time_var     global ser         if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 1:             print('Event p1')             IncCont(10,"EVENT")     if State == "SET":         print('-',end="")                  def I1P(Value = 0,State = "INIT"):     Value = int(Value)     global Panel_Value_array     global time_var     global ser          if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 1:             print('Event 1p')             IncCont(100,"EVENT")     if State == "SET":         print('-',end="") def I10P(Value = 0,State = "INIT"):     Value = int(Value)     global Panel_Value_array     global time_var     global ser          if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 1:                 print('Event p10')             IncCont(1000,"EVENT")     if State == "SET":         print('-',end="") def PX(Value = 0,State = "INIT"):     global c     global s     global Xjoint_num     global Panel_Value_array     if State == "INIT":         print('-',end="")     if State == "EVENT":         for index, item in enumerate(Panel_Value_array):             if Panel_Value_array[index][0] == "IncCont":                     if Value == 1:                     if Panel_Value_array[index][1] == 0:                         SpeedSec = hal.get_value("axisui.jog.speed")/60                         print(str(hal.get_value("axisui.jog.speed"))+"mm/min : "+str(SpeedSec)+"mm/sec")                         c.jog(linuxcnc.JOG_CONTINUOUS,False,Xjoint_num,SpeedSec)                         print('Event PX GO')                                        if Value == 0:                     if Panel_Value_array[index][1] == 0:                         c.jog(linuxcnc.JOG_STOP, False, Xjoint_num)                         print('Event PX GO STOP')                     else:                         SpeedSec = hal.get_value("axisui.jog.speed")/60                         print(str(hal.get_value("axisui.jog.speed"))+"mm/min : "+str(SpeedSec)+"mm/sec")                         c.jog(linuxcnc.JOG_INCREMENT,False,Xjoint_num,SpeedSec,Panel_Value_array[index][1])                         print('Event PX I'+str(Panel_Value_array[index][1]))                                      if State == "SET":         print('-',end="") def MX(Value = 0,State = "INIT"):     global c     global s     global Xjoint_num     global Panel_Value_array     if State == "INIT":         print('-',end="")     if State == "EVENT":         for index, item in enumerate(Panel_Value_array):             if Panel_Value_array[index][0] == "IncCont":                     if Value == 1:                     if Panel_Value_array[index][1] == 0:                         SpeedSec = hal.get_value("axisui.jog.speed")/60 * -1                         print(str(hal.get_value("axisui.jog.speed"))+"mm/min : "+str(SpeedSec)+"mm/sec")                         c.jog(linuxcnc.JOG_CONTINUOUS,False,Xjoint_num,SpeedSec)                         print('Event MX GO')                                        if Value == 0:                     if Panel_Value_array[index][1] == 0:                         c.jog(linuxcnc.JOG_STOP, False, Xjoint_num)                         print('Event PX GO STOP')                     else:                         SpeedSec = hal.get_value("axisui.jog.speed")/60                         print(str(hal.get_value("axisui.jog.speed"))+"mm/min : "+str(SpeedSec)+"mm/sec")                         c.jog(linuxcnc.JOG_INCREMENT,False,Xjoint_num,SpeedSec,Panel_Value_array[index][1]*-1)                         print('Event MX I'+str(Panel_Value_array[index][1]))                                      if State == "SET":         print('-',end="") def PZ(Value = 0,State = "INIT"):     global c     global s     global Zjoint_num     global Panel_Value_array     if State == "INIT":         print('-',end="")     if State == "EVENT":         for index, item in enumerate(Panel_Value_array):             if Panel_Value_array[index][0] == "IncCont":                     if Value == 1:                     if Panel_Value_array[index][1] == 0:                         SpeedSec = hal.get_value("axisui.jog.speed")/60                         print(str(hal.get_value("axisui.jog.speed"))+"mm/min : "+str(SpeedSec)+"mm/sec")                         c.jog(linuxcnc.JOG_CONTINUOUS,False,Zjoint_num,SpeedSec)                         print('Event PZ GO')                                        if Value == 0:                     if Panel_Value_array[index][1] == 0:                         c.jog(linuxcnc.JOG_STOP, False, Zjoint_num)                         print('Event PZ GO STOP')                     else:                         SpeedSec = hal.get_value("axisui.jog.speed")/60                         print(str(hal.get_value("axisui.jog.speed"))+"mm/min : "+str(SpeedSec)+"mm/sec")                         c.jog(linuxcnc.JOG_INCREMENT,False,Zjoint_num,SpeedSec,Panel_Value_array[index][1])                         print('Event PZ I'+str(Panel_Value_array[index][1]))                                      if State == "SET":         print('-',end="") def MZ(Value = 0,State = "INIT"):     global c     global s     global Zjoint_num     global Panel_Value_array     if State == "INIT":         print('-',end="")     if State == "EVENT":         for index, item in enumerate(Panel_Value_array):             if Panel_Value_array[index][0] == "IncCont":                     if Value == 1:                     if Panel_Value_array[index][1] == 0:                         SpeedSec = hal.get_value("axisui.jog.speed")/60 * -1                         print(str(hal.get_value("axisui.jog.speed"))+"mm/min : "+str(SpeedSec)+"mm/sec")                         c.jog(linuxcnc.JOG_CONTINUOUS,False,Zjoint_num,SpeedSec)                         print('Event MZ GO')                                        if Value == 0:                     if Panel_Value_array[index][1] == 0:                         c.jog(linuxcnc.JOG_STOP, False, Zjoint_num)                         print('Event PZ GO STOP')                     else:                         SpeedSec = hal.get_value("axisui.jog.speed")/60                         print(str(hal.get_value("axisui.jog.speed"))+"mm/min : "+str(SpeedSec)+"mm/sec")                         c.jog(linuxcnc.JOG_INCREMENT,False,Zjoint_num,SpeedSec,Panel_Value_array[index][1]*-1)                         print('Event MZ I'+str(Panel_Value_array[index][1]))                                      if State == "SET":         print('-',end="") def Home(Value = 0,State = "INIT"):     global c     global s     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 0:             print(str(s.joints))             for i in range(s.joints-1,-1,-1):                 print("Home Joint" + str(i),end="")                 c.home(i)                 while not hal.get_value("halui.joint."+str(i)+".is-homed"):                     if hal.get_value("axisui.error") == 1:                         print('Event HOME ABORT')                         break                     time.sleep(0.5)                 time.sleep(1)                 print("*")             print('Event HOME')     if State == "SET":         print('-',end="") def Play(Value = 0,State = "INIT"):     global c     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 0:             c.mode(linuxcnc.MODE_AUTO)             c.auto(linuxcnc.AUTO_RUN, 0)                if State == "SET":         print('-',end="")          def Step(Value = 0,State = "INIT"):     global c     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 0:             c.auto(linuxcnc.AUTO_STEP)     if State == "SET":         print('-',end="") def Pause(Value = 0,State = "INIT"):     global c     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 0:             if hal.get_value("halui.program.is-running"):                 c.auto(linuxcnc.AUTO_PAUSE)             elif hal.get_value("halui.program.is-paused"):                 c.auto(linuxcnc.AUTO_RESUME)     if State == "SET":         print('-',end="") def Stop(Value = 0,State = "INIT"):     global c     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 0:             c.abort()     if State == "SET":         print('-',end="") def UserDeF0(Value = 0,State = "INIT"):     global c     if State == "INIT":         h.newpin("ERRORCLEAR",hal.HAL_BIT,hal.HAL_IN)         h.newpin("Tool_OK",hal.HAL_BIT,hal.HAL_IN)         print('-',end="")     if State == "EVENT":         if Value == 0:             h['ERRORCLEAR'] = 1             h['Tool_OK'] = 1             time.sleep(0.5)             h['ERRORCLEAR'] = 0             h['Tool_OK'] = 0                  if State == "SET":         print('-',end="")         #ERRORPIN         hal.new_sig("ERRORCLEARSignal",hal.HAL_BIT)         hal.connect('DonnoPanel.ERRORCLEAR',"ERRORCLEARSignal")         hal.connect('axisui.notifications-clear',"ERRORCLEARSignal")           hal.new_sig("Click_Tool_Change_OK",hal.HAL_BIT)         hal.connect('DonnoPanel.Tool_OK',"Click_Tool_Change_OK")         hal.connect('hal_manualtoolchange.change_button',"Click_Tool_Change_OK")          def Xaxis(Value = 0,State = "INIT"):     global c     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 0:             c.mode(linuxcnc.MODE_MDI)             c.mdi("G92 X0")             c.mode(linuxcnc.MODE_MANUAL)     if State == "SET":         print('-',end="")          def Zaxis(Value = 0,State = "INIT"):     global c     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 0:             c.mode(linuxcnc.MODE_MDI)             c.mdi("G92 Z0")             c.mode(linuxcnc.MODE_MANUAL)     if State == "SET":         print('-',end="")          def FeedP(Value = 0,State = "INIT"):     global c     global h     if State == "INIT":         h.newpin("Feed_Positive",hal.HAL_BIT,hal.HAL_IN)         print('-',end="")     if State == "EVENT":         if Value == 0:             for index, item in enumerate(Panel_Value_array):                 if Panel_Value_array[index][0] == "IncCont":                         if Panel_Value_array[index][1] == 0.1:                             h['Feed_scale'] = 0.01                             h['Feed_Positive'] = 1                             time.sleep(0.5)                             h['Feed_Positive'] = 0                                                     if Panel_Value_array[index][1] == 1:                             h['Feed_scale'] = 0.1                             h['Feed_Positive'] = 1                             time.sleep(0.5)                             h['Feed_Positive'] = 0                                                  if Panel_Value_array[index][1] == 10:                             h['Feed_scale'] = 1                             h['Feed_Positive'] = 1                             time.sleep(0.5)                             h['Feed_Positive'] = 0                                                   if State == "SET":         print('-',end="")         #Feed Scale         hal.new_sig("FeedP",hal.HAL_BIT)         hal.connect('DonnoPanel.Feed_Positive',"FeedP")         hal.connect('halui.feed-override.increase',"FeedP")            def FeedM(Value = 0,State = "INIT"):     global c     global h     if State == "INIT":         h.newpin("Feed_Negative",hal.HAL_BIT,hal.HAL_IN)         print('-',end="")     if State == "EVENT":         if Value == 0:             for index, item in enumerate(Panel_Value_array):                 if Panel_Value_array[index][0] == "IncCont":                         if Panel_Value_array[index][1] == 0.1:                             h['Feed_scale'] = 0.01                             h['Feed_Negative'] = 1                             time.sleep(0.5)                             h['Feed_Negative'] = 0                                                     if Panel_Value_array[index][1] == 1:                             h['Feed_scale'] = 0.1                             h['Feed_Negative'] = 1                             time.sleep(0.5)                             h['Feed_Negative'] = 0                                                  if Panel_Value_array[index][1] == 10:                             h['Feed_scale'] = 1                             h['Feed_Negative'] = 1                             time.sleep(0.5)                             h['Feed_Negative'] = 0                                                   if State == "SET":         print('-',end="")         #Feed Scale         hal.new_sig("FeedN",hal.HAL_BIT)         hal.connect('DonnoPanel.Feed_Negative',"FeedN")         hal.connect('halui.feed-override.decrease',"FeedN")                def RapidP(Value = 0,State = "INIT"):     global c     global h     if State == "INIT":         h.newpin("Rapid_Positive",hal.HAL_BIT,hal.HAL_IN)         print('-',end="")     if State == "EVENT":         if Value == 0:             for index, item in enumerate(Panel_Value_array):                 if Panel_Value_array[index][0] == "IncCont":                         if Panel_Value_array[index][1] == 0.1:                             h['Rapid_scale'] = 0.01                             h['Rapid_Positive'] = 1                             time.sleep(0.5)                             h['Rapid_Positive'] = 0                                                     if Panel_Value_array[index][1] == 1:                             h['Rapid_scale'] = 0.1                             h['Rapid_Positive'] = 1                             time.sleep(0.5)                             h['Rapid_Positive'] = 0                                                  if Panel_Value_array[index][1] == 10:                             h['Rapid_scale'] = 1                             h['Rapid_Positive'] = 1                             time.sleep(0.5)                             h['Rapid_Positive'] = 0                                                   if State == "SET":         print('-',end="")         #Feed Scale         hal.new_sig("RapidP",hal.HAL_BIT)         hal.connect('DonnoPanel.Rapid_Positive',"RapidP")         hal.connect('halui.rapid-override.increase',"RapidP") def RapidM(Value = 0,State = "INIT"):     global c     global h     if State == "INIT":         h.newpin("Rapid_Negative",hal.HAL_BIT,hal.HAL_IN)         print('-',end="")     if State == "EVENT":         if Value == 0:             for index, item in enumerate(Panel_Value_array):                 if Panel_Value_array[index][0] == "IncCont":                         if Panel_Value_array[index][1] == 0.1:                             h['Rapid_scale'] = 0.01                             h['Rapid_Negative'] = 1                             time.sleep(0.5)                             h['Rapid_Negative'] = 0                                                     if Panel_Value_array[index][1] == 1:                             h['Rapid_scale'] = 0.1                             h['Rapid_Negative'] = 1                             time.sleep(0.5)                             h['Rapid_Negative'] = 0                                                  if Panel_Value_array[index][1] == 10:                             h['Rapid_scale'] = 1                             h['Rapid_Negative'] = 1                             time.sleep(0.5)                             h['Rapid_Negative'] = 0                                                   if State == "SET":         print('-',end="")         #Feed Scale         hal.new_sig("RapidN",hal.HAL_BIT)         hal.connect('DonnoPanel.Rapid_Negative',"RapidN")         hal.connect('halui.rapid-override.decrease',"RapidN") def SpindleOverP(Value = 0,State = "INIT"):     global c     global h     if State == "INIT":         h.newpin("SpindleOver_Positive",hal.HAL_BIT,hal.HAL_IN)         print('-',end="")     if State == "EVENT":         if Value == 0:             for index, item in enumerate(Panel_Value_array):                 if Panel_Value_array[index][0] == "IncCont":                         if Panel_Value_array[index][1] == 0.1:                             h['SpindleOver_scale'] = 0.01                             h['SpindleOver_Positive'] = 1                             time.sleep(0.5)                             h['SpindleOver_Positive'] = 0                                                     if Panel_Value_array[index][1] == 1:                             h['SpindleOver_scale'] = 0.1                             h['SpindleOver_Positive'] = 1                             time.sleep(0.5)                             h['SpindleOver_Positive'] = 0                                                  if Panel_Value_array[index][1] == 10:                             h['SpindleOver_scale'] = 1                             h['SpindleOver_Positive'] = 1                             time.sleep(0.5)                             h['SpindleOver_Positive'] = 0                                                   if State == "SET":         print('-',end="")         #Feed Scale         hal.new_sig("SpindleOverP",hal.HAL_BIT)         hal.connect('DonnoPanel.SpindleOver_Positive',"SpindleOverP")         hal.connect('halui.spindle.0.override.increase',"SpindleOverP") def SpindleOverM(Value = 0,State = "INIT"):     global c     global h     if State == "INIT":         h.newpin("SpindleOver_Negative",hal.HAL_BIT,hal.HAL_IN)         print('-',end="")     if State == "EVENT":         if Value == 0:             for index, item in enumerate(Panel_Value_array):                 if Panel_Value_array[index][0] == "IncCont":                         if Panel_Value_array[index][1] == 0.1:                             h['SpindleOver_scale'] = 0.01                             h['SpindleOver_Negative'] = 1                             time.sleep(0.5)                             h['SpindleOver_Negative'] = 0                                                     if Panel_Value_array[index][1] == 1:                             h['SpindleOver_scale'] = 0.1                             h['SpindleOver_Negative'] = 1                             time.sleep(0.5)                             h['SpindleOver_Negative'] = 0                                                  if Panel_Value_array[index][1] == 10:                             h['SpindleOver_scale'] = 1                             h['SpindleOver_Negative'] = 1                             time.sleep(0.5)                             h['SpindleOver_Negative'] = 0                                                   if State == "SET":         print('-',end="")         #Feed Scale         hal.new_sig("SpindleOverN",hal.HAL_BIT)         hal.connect('DonnoPanel.SpindleOver_Negative',"SpindleOverN")         hal.connect('halui.spindle.0.override.decrease',"SpindleOverN") def MaxVelP(Value = 0,State = "INIT"):     global c     global h     if State == "INIT":         h.newpin("MaxVel_Positive",hal.HAL_BIT,hal.HAL_IN)         print('-',end="")     if State == "EVENT":         if Value == 0:             for index, item in enumerate(Panel_Value_array):                 if Panel_Value_array[index][0] == "IncCont":                         if Panel_Value_array[index][1] == 0.1:                             h['MaxVel_scale'] = 1/60                             h['MaxVel_Positive'] = 1                             time.sleep(0.5)                             h['MaxVel_Positive'] = 0                                                     if Panel_Value_array[index][1] == 1:                             h['MaxVel_scale'] = 10/60                             h['MaxVel_Positive'] = 1                             time.sleep(0.5)                             h['MaxVel_Positive'] = 0                                                  if Panel_Value_array[index][1] == 10:                             h['MaxVel_scale'] = 100/60                             h['MaxVel_Positive'] = 1                             time.sleep(0.5)                             h['MaxVel_Positive'] = 0                                                   if State == "SET":         print('-',end="")         #Feed Scale         hal.new_sig("MaxVelP",hal.HAL_BIT)         hal.connect('DonnoPanel.MaxVel_Positive',"MaxVelP")         hal.connect('halui.max-velocity.increase',"MaxVelP") def MaxVelM(Value = 0,State = "INIT"):     global c     global h     if State == "INIT":         h.newpin("MaxVel_Negative",hal.HAL_BIT,hal.HAL_IN)         print('-',end="")     if State == "EVENT":         if Value == 0:             for index, item in enumerate(Panel_Value_array):                 if Panel_Value_array[index][0] == "IncCont":                         if Panel_Value_array[index][1] == 0.1:                             h['MaxVel_scale'] = 1/60                             h['MaxVel_Negative'] = 1                             time.sleep(0.5)                             h['MaxVel_Negative'] = 0                                                     if Panel_Value_array[index][1] == 1:                             h['MaxVel_scale'] = 10/60                             h['MaxVel_Negative'] = 1                             time.sleep(0.5)                             h['MaxVel_Negative'] = 0                                                  if Panel_Value_array[index][1] == 10:                             h['MaxVel_scale'] = 100/60                             h['MaxVel_Negative'] = 1                             time.sleep(0.5)                             h['MaxVel_Negative'] = 0                                                   if State == "SET":         print('-',end="")         #Feed Scale         hal.new_sig("MaxVelN",hal.HAL_BIT)         hal.connect('DonnoPanel.MaxVel_Negative',"MaxVelN")         hal.connect('halui.max-velocity.decrease',"MaxVelN") def JogSpeedP(Value = 0,State = "INIT"):     global c     global h     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 0:             for index, item in enumerate(Panel_Value_array):                 if Panel_Value_array[index][0] == "IncCont":                         if Panel_Value_array[index][1] == 0.1:                             h['JogSpeed'] = h['JogSpeed'] + 1                                                    if Panel_Value_array[index][1] == 1:                             h['JogSpeed'] = h['JogSpeed'] + 10                                                if Panel_Value_array[index][1] == 10:                             h['JogSpeed'] = h['JogSpeed'] + 100                                         if State == "SET":         print('-',end="")   def JogSpeedM(Value = 0,State = "INIT"):     global c     global h     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 0:             for index, item in enumerate(Panel_Value_array):                 if Panel_Value_array[index][0] == "IncCont":                         if Panel_Value_array[index][1] == 0.1:                             h['JogSpeed'] = h['JogSpeed'] - 1                                                    if Panel_Value_array[index][1] == 1:                             h['JogSpeed'] = h['JogSpeed'] - 10                                                if Panel_Value_array[index][1] == 10:                             h['JogSpeed'] = h['JogSpeed'] - 100                                         if State == "SET":         print('-',end="") def CoolSW(Value = 0,State = "INIT"):     global h     if State == "INIT":         print('-',end="")         h.newpin("CoolSW",hal.HAL_BIT,hal.HAL_IN)         h.newpin("CoolSW_NOT",hal.HAL_BIT,hal.HAL_IN)     if State == "EVENT":         if Value == 0:             if hal.get_value("halui.flood.is-on"):                         h["CoolSW"] = 0                 h["CoolSW_NOT"] = 1             else:                 h["CoolSW"] = 1                 h["CoolSW_NOT"] = 0                 if State == "SET":         hal.new_sig("CoolantSW",hal.HAL_BIT)         hal.connect('DonnoPanel.CoolSW',"CoolantSW")         hal.connect('halui.flood.on',"CoolantSW")         #NOT         hal.new_sig("CoolantSW_NOT",hal.HAL_BIT)         hal.connect('DonnoPanel.CoolSW_NOT',"CoolantSW_NOT")            hal.connect('halui.flood.off',"CoolantSW_NOT")                  print('-',end="")         def SpCW(Value = 0,State = "INIT"):     global h     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 0:                   c.spindle(linuxcnc.SPINDLE_FORWARD, 1)              if State == "SET":                 print('-',end="") def SpCCW(Value = 0,State = "INIT"):     global h     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 0:                     c.spindle(linuxcnc.SPINDLE_REVERSE, 1)              if State == "SET":                 print('-',end="") def SpSW(Value = 0,State = "INIT"):     global h     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 0:             if hal.get_value("spindle.0.on"):                 c.spindle(linuxcnc.SPINDLE_OFF)             else:                 c.spindle(linuxcnc.SPINDLE_FORWARD, 1)     if State == "SET":                 print('-',end="") def Spinc(Value = 0,State = "INIT"):     global h     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 0:             c.spindle(linuxcnc.SPINDLE_INCREASE, 0)                        if State == "SET":                 print('-',end="") def Spdec(Value = 0,State = "INIT"):     global h     if State == "INIT":         print('-',end="")     if State == "EVENT":         if Value == 0:             c.spindle(linuxcnc.SPINDLE_DECREASE, 0)                        if State == "SET":                 print('-',end="") def SerialEvent(serial_port,cmd):     global c     global HALComponentReady     global Panel_Value_array     SerialCount = 0     serial_port.write(cmd.encode('utf-8'))     print(cmd,end="")     while 1:         while serial_port.in_waiting:              if cmd  == "ALL":                  line = ser.readline()                  line = line.decode().strip()                  values = line.split('\n')                  Var = values[0].split(' ')                  Panel_Value_array.append(SerialCount)                  Panel_Value_array[SerialCount] = list()                  Panel_Value_array[SerialCount].append(Var[0])                  Panel_Value_array[SerialCount].append(Var[1])                  Panel_Value_array[SerialCount].append(Var[1])                  #Value_array.append(Var[1])                  try:                      my_func = eval(Var[0])                      my_func()                                      except Exception as e:                     print("*", end = "")                         SerialCount = SerialCount + 1                  if SerialCount == 40:                      print("")                      print("SET",end="")                      cmd  = ""                      time.sleep(1)                      h.ready()                      for index, item in enumerate(Panel_Value_array):                          try:                              my_func = eval(Panel_Value_array[index][0]+"("+Panel_Value_array[index][1]+",'SET')")                              my_func()                          except Exception as e:                              print("*", end="")                      HALComponentReady = True                      print(Panel_Value_array)              else:                  data = serial_port.readline().decode('utf-8').replace("\n", "").strip()                  if data.startswith("EVENT"):                      EventData = data.split(' ')                      for index, item in enumerate(Panel_Value_array):                          if Panel_Value_array[index][0] == EventData[1]:                             eval(Panel_Value_array[index][0]+"("+EventData[2]+",'EVENT')")                             print("EVENT" + EventData[1] +":"+EventData[2])                                      if data.startswith("SET"):                      print(data) try:     h = hal.component("DonnoPanel")     thread = threading.Thread(target=SerialEvent, args=(ser,"ALL"))     thread.start()     FirstRun = True     while True:         if HALComponentReady:             if FirstRun == True:                 print('Loading LinuxCNC Event')                 LinuxCNCEvent(ser)                 print('Panel Ready !')                 FirstRun = False             else:                 LinuxCNCEvent(ser)                 #c.jog(linuxcnc.JOG_INCREMENT, 0, 1,100, 100) except hal.error as e:     print("Error working with signal: {}".format(str(e)))     ser.close()     print("Close")       

My script

Please Log in to join the conversation.

More
3 years 1 month ago #280975 by zz912
I don't know if it will work, but it might.
Code:
# Add in postgui.hal #    setp DonnoPanel.ready 1 h = hal.component("DonnoPanel") h.newpin("ready",hal.HAL_BIT,hal.HAL_IN) while not h["ready"] == 1:    time.sleep(0.5) (Here do what you need)

Please Log in to join the conversation.

More
3 years 1 month ago #280976 by cmorley
in your post_gui hal file try:

loadusr python3 myfile.py

Please Log in to join the conversation.

More
3 years 1 month ago #280981 by cakeslob
are you running this as an axis usercommand file? I dont know what you are doing but you should still be able to connect to halui pins from a usercommand file

Please Log in to join the conversation.

More
3 years 1 month ago #281016 by Donno
I could not use loadusr python3 myfile.py as linuxcnc through error, i think it is because i have delay Functions in my code.

I started linuxcnc and my script in /home/linuxcnc/.config/autostart <- created two desktop entry so it runs on startup

On my code i had to run it in terminal so my exec=xfce4-terminal -e "myfile.py"

I delay script by 10sec so linuxcnc axis gui can load correctly !

Please Log in to join the conversation.

More
3 years 1 month ago #281031 by cmorley
you didn't mention the acrual error so it's hard to know why loadusr python3 failed.
If it is because halui was not loaded yet, there is away to test for that.

Anyways glad u figured something out.

Please Log in to join the conversation.

Time to create page: 0.093 seconds
Powered by Kunena Forum