Skip to content

Commit 095f7f0

Browse files
committed
qtvcp -qt_action: add autoprobe touchoff to ACTION
thanks to Jim for the code
1 parent d7eff7f commit 095f7f0

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

lib/python/qtvcp/qt_action.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
INFO = Info()
2121
STATUS = Status()
2222
PATH = Path()
23-
TOUCHPLATE_SUBPROGRAM = os.path.abspath(os.path.join(
23+
TOUCHOFF_SUBPROGRAM = os.path.abspath(os.path.join(
2424
os.path.dirname(__file__), 'lib/touchoff_subprogram.py'))
2525

2626

@@ -763,8 +763,7 @@ def SET_TEMPARARY_MESSAGE(self, msg):
763763
STATUS.emit('error', STATUS.TEMPARARY_MESSAGE, msg)
764764

765765
def TOUCHPLATE_TOUCHOFF(self, search_vel, probe_vel, max_probe,
766-
z_offset, retract_distance, z_safe_travel, rtn_method=None, error_rtn = None):
767-
766+
z_offset, retract_distance, z_safe_travel, rtn_method=None, error_rtn=None):
768767
# if not none will be called with returned data
769768
self._touchoff_return = rtn_method
770769
self._touchoff_error_return = error_rtn
@@ -777,7 +776,7 @@ def TOUCHPLATE_TOUCHOFF(self, search_vel, probe_vel, max_probe,
777776
self.proc.readyReadStandardOutput.connect(self.read_stdout)
778777
self.proc.readyReadStandardError.connect(self.read_stderror)
779778
self.proc.finished.connect(self.touchoff_finished)
780-
self.proc.start('python3 {}'.format(TOUCHPLATE_SUBPROGRAM))
779+
self.proc.start('python3 {}'.format(TOUCHOFF_SUBPROGRAM))
781780
# probe
782781
string_to_send = "touchoff${}${}${}${}${}${}\n".format(str(search_vel),
783782
str(probe_vel),
@@ -791,6 +790,25 @@ def TOUCHPLATE_TOUCHOFF(self, search_vel, probe_vel, max_probe,
791790
self.proc.writeData(bytes(string_to_send, 'utf-8'))
792791
return 1
793792

793+
def AUTO_HEIGHT(self, string_to_send, rtn_method=None, error_rtn=None):
794+
# if not None, return with returned data
795+
self._touchoff_return = rtn_method
796+
self._touchoff_error_return = error_rtn
797+
798+
if self.proc is not None:
799+
return 0
800+
self.proc = QProcess()
801+
self.proc.setReadChannel(QProcess.StandardOutput)
802+
self.proc.started.connect(self.touchoff_started)
803+
self.proc.readyReadStandardOutput.connect(self.read_stdout)
804+
self.proc.readyReadStandardError.connect(self.read_stderror)
805+
self.proc.finished.connect(self.touchoff_finished)
806+
self.proc.start('python3 {}'.format(TOUCHOFF_SUBPROGRAM))
807+
# block polling here, the sub program will poll now
808+
STATUS.block_error_polling()
809+
self.proc.writeData(bytes(string_to_send, 'utf-8'))
810+
return 1
811+
794812
def ADD_WIDGET_TO_TAB(self, widgetTo, widget,name):
795813
try:
796814
if isinstance(widgetTo, QTabWidget):
@@ -990,18 +1008,18 @@ def parse_line(self, line):
9901008
if "COMPLETE" in line:
9911009
# did we get a return method to send return data to?
9921010
if self._touchoff_return is None:
993-
self.SET_DISPLAY_MESSAGE("Touchplate touchoff routine returned successfully")
1011+
self.SET_DISPLAY_MESSAGE("Touchoff routine returned successfully")
9941012
else:
9951013
# strip ugly text
996-
s = line[line.find('COMPLETE ')+9:]
1014+
s = line[line.find('COMPLETE')+9:]
9971015
self._touchoff_return(s)
9981016

9991017
# This also gets error text sent from logging of ACTION library in the subprogram
10001018
elif "ERROR" in line:
10011019
# remove preceding text 'ERROR'
10021020
s = line[line.find('ERROR')+6:]
10031021
s = s[s.find(']')+1:]
1004-
if self._touchoff_return is None:
1022+
if self._touchoff_error_return is None:
10051023
self.SET_ERROR_MESSAGE(s)
10061024
else:
10071025
self._touchoff_error_return(s)
@@ -1010,10 +1028,10 @@ def parse_line(self, line):
10101028
LOG.debug(line[line.find('DEBUG')+6:])
10111029

10121030
def touchoff_started(self):
1013-
LOG.debug("Touchplate touchOff subprogram started with PID {}\n".format(self.proc.processId()))
1031+
LOG.debug("TouchOff subprogram started with PID {}\n".format(self.proc.processId()))
10141032

10151033
def touchoff_finished(self, exitCode, exitStatus):
1016-
LOG.debug("Touchplate touchoff Process finished - exitCode {} exitStatus {}".format(exitCode, exitStatus))
1034+
LOG.debug("Touchoff Process finished - exitCode {} exitStatus {}".format(exitCode, exitStatus))
10171035
self.proc = None
10181036
STATUS.unblock_error_polling()
10191037
# clean up return method variable

0 commit comments

Comments
 (0)