Reformat Temperature for Closed Source Firmware (Xinkebot, ChiTu)

I'm trying to re-parse the GCode recieved from my closed source ChiTu board to better interact with Octoprint.

Unfortunately I receive T: and T0: for my single extruder head, but the set temp only reports correctly for T: and octoprint likes to use T0:

Here's an example of a received line - Temp is set to 100C and is currently 100C
Recv: ok T:100 /100 B:20 /0 T0:100 /0 T1:-50 /0 @:21 B@:0

Notice T: reports set temp correctly but T0: does not (I know this is my boards fault)
Recv: ok T:100 /100 B:20 /0 T0:100 /0 T1:-50 /0 @:21 B@:0

My plan was to parse out "T0:" by re.sub to "T2:", and then re.sub "T:" to "T0:" but I haven't ever coded python and I'm looking for some help.

Here's my code so far:

# coding=utf-8

import octoprint.plugin
import re

class XinkebotTemperatureFixPlugin(octoprint.plugin.OctoPrintPlugin):
	def process_gcode_received(self, comm_instance, line, *args, **kwargs):
		if re.match("T:", line):
			fix = re.sub("T0:", "T2:", line)
			fix2 = re.sub("T:", "T0:", fix)
			return fix2
		return line

__plugin_name__ = "Xinkebot Temperature Fix"
def __plugin_load__():
	global __plugin_implementation__
	__plugin_implementation__ = XinkebotTemperatureFixPlugin()

	global __plugin_hooks__
	__plugin_hooks__ = {
		"octoprint.comm.protocol.gcode.received": __plugin_implementation__.process_gcode_received
	}

I can see that my plugin is loaded, but as far as I can tell, nothing is happening at all.

Please!?!?! and thank you for anyone that can shed some light on this

Could you please post your code formated as code (use the < / > sign in the editor header).
Posting as normal text destroys all the indents and some characters are interpreted as markdown formatings.

1 Like

I think I got it. Sorry, I’m a noob

1 Like

Here's my working code. I didn't change much.

I had to fix some tabs/spaces and I changed my if statement

This is designed to make the set temp appear correctly on the graph for the Xinkebot Orca 2 Cygnus with the single extruder head

Soon I'll post a plugin that combines both the broken wait and temp responses in one plugin. That should pretty well cover anyone running single extrusion.

# coding=utf-8

import octoprint.plugin
import re

class XinkebotTempPlugin(octoprint.plugin.OctoPrintPlugin):
	def process_gcode_received(self, comm_instance, line, *args, **kwargs):
		if "T:" in line and "T0:" in line:
			fix = re.sub("T0:", "T2:", line)
			fix2 = re.sub("T:", "T0:", fix)
			#self._logger.info(fix2)
			return fix2
		return line

__plugin_name__ = "Xinkebot Temp Plugin"
__plugin_description__ = "A fix for Xinkebot broken temperature response code for single extrusion"
__plugin_version__ = "1.0.0"
__plugin_author__ = "Max Ramos"
def __plugin_load__():
	global __plugin_implementation__
	__plugin_implementation__ = XinkebotTempPlugin()
		
	global __plugin_hooks__
	__plugin_hooks__ = {
		"octoprint.comm.protocol.gcode.received": __plugin_implementation__.process_gcode_received
	}

1 Like