示例#1
0
def printerPrintheadCommand():
    valid_commands = {"jog": [], "home": ["axes"], "feedrate": ["factor"]}
    command, data, response = get_json_command_from_request(
        request, valid_commands)
    if response is not None:
        return response

    if not printer.is_operational() or (printer.is_printing()
                                        and command != "feedrate"):
        # do not jog when a print job is running or we don't have a connection
        return make_response(
            "Printer is not operational or currently printing", 409)

    valid_axes = ["x", "y", "z"]
    ##~~ jog command
    if command == "jog":
        # validate all jog instructions, make sure that the values are numbers
        validated_values = {}
        for axis in valid_axes:
            if axis in data:
                value = data[axis]
                if not isinstance(value, (int, float)):
                    return make_response(
                        "Not a number for axis %s: %r" % (axis, value), 400)
                validated_values[axis] = value

        absolute = "absolute" in data and data[
            "absolute"] in valid_boolean_trues
        speed = data.get("speed", None)

        # execute the jog commands
        printer.jog(validated_values, relative=not absolute, speed=speed)

    ##~~ home command
    elif command == "home":
        validated_values = []
        axes = data["axes"]
        for axis in axes:
            if not axis in valid_axes:
                return make_response("Invalid axis: %s" % axis, 400)
            validated_values.append(axis)

        # execute the home command
        printer.home(validated_values)

    elif command == "feedrate":
        factor = data["factor"]
        if not isinstance(factor, (int, float)):
            return make_response("Not a number for feed rate: %r" % factor,
                                 400)
        try:
            printer.feed_rate(factor)
        except ValueError as e:
            return make_response("Invalid value for feed rate: %s" % str(e),
                                 400)

    return NO_CONTENT
示例#2
0
def printerPrintheadCommand():
	valid_commands = {
		"jog": [],
		"home": ["axes"],
		"feedrate": ["factor"]
	}
	command, data, response = get_json_command_from_request(request, valid_commands)
	if response is not None:
		return response

	if not printer.is_operational() or (printer.is_printing() and command != "feedrate"):
		# do not jog when a print job is running or we don't have a connection
		return make_response("Printer is not operational or currently printing", 409)

	tags = {"source:api", "api:printer.printhead"}

	valid_axes = ["x", "y", "z"]
	##~~ jog command
	if command == "jog":
		# validate all jog instructions, make sure that the values are numbers
		validated_values = {}
		for axis in valid_axes:
			if axis in data:
				value = data[axis]
				if not isinstance(value, (int, long, float)):
					return make_response("Not a number for axis %s: %r" % (axis, value), 400)
				validated_values[axis] = value

		absolute = "absolute" in data and data["absolute"] in valid_boolean_trues
		speed = data.get("speed", None)

		# execute the jog commands
		printer.jog(validated_values, relative=not absolute, speed=speed, tags=tags)

	##~~ home command
	elif command == "home":
		validated_values = []
		axes = data["axes"]
		for axis in axes:
			if not axis in valid_axes:
				return make_response("Invalid axis: %s" % axis, 400)
			validated_values.append(axis)

		# execute the home command
		printer.home(validated_values, tags=tags)

	elif command == "feedrate":
		factor = data["factor"]
		if not isinstance(factor, (int, long, float)):
			return make_response("Not a number for feed rate: %r" % factor, 400)
		try:
			printer.feed_rate(factor, tags=tags)
		except ValueError as e:
			return make_response("Invalid value for feed rate: %s" % str(e), 400)

	return NO_CONTENT
示例#3
0
def printerPrintheadCommand():
    valid_commands = {"jog": [], "home": ["axes"], "feedrate": ["factor"]}
    command, data, response = get_json_command_from_request(request, valid_commands)
    if response is not None:
        return response

    if not printer.is_operational() or (printer.is_printing() and command != "feedrate"):
        # do not jog when a print job is running or we don't have a connection
        abort(409, description="Printer is not operational or currently printing")

    tags = {"source:api", "api:printer.printhead"}

    valid_axes = ["x", "y", "z"]
    ##~~ jog command
    if command == "jog":
        # validate all jog instructions, make sure that the values are numbers
        validated_values = {}
        for axis in valid_axes:
            if axis in data:
                value = data[axis]
                if not isinstance(value, (int, long, float)):
                    abort(400, description="axis value is invalid")
                validated_values[axis] = value

        absolute = "absolute" in data and data["absolute"] in valid_boolean_trues
        speed = data.get("speed", None)

        # execute the jog commands
        printer.jog(validated_values, relative=not absolute, speed=speed, tags=tags)

    ##~~ home command
    elif command == "home":
        validated_values = []
        axes = data["axes"]
        for axis in axes:
            if axis not in valid_axes:
                abort(400, description="axis is invalid")
            validated_values.append(axis)

        # execute the home command
        printer.home(validated_values, tags=tags)

    elif command == "feedrate":
        factor = data["factor"]
        if not isinstance(factor, (int, long, float)):
            abort(400, description="factor is invalid")
        try:
            printer.feed_rate(factor, tags=tags)
        except ValueError:
            abort(400, description="factor is invalid")

    return NO_CONTENT
示例#4
0
def printerPrintheadCommand(request=None):
    if not printer.isOperational() or printer.isPrinting():
        # do not jog when a print job is running or we don't have a connection
        return make_response(
            "Printer is not operational or currently printing", 409)

    valid_commands = {"jog": [], "home": ["axes"]}
    command, data, response = util.getJsonCommandFromRequest(
        request, valid_commands)
    print "command:", command, "data:", data, "response:", response
    if response is not None:
        return response

    valid_axes = ["x", "y", "z"]
    ##~~ jog command
    if command == "jog":
        # validate all jog instructions, make sure that the values are numbers
        validated_values = {}
        for axis in valid_axes:
            if axis in data:
                value = data[axis]
                if not isinstance(value, (int, long, float)):
                    return make_response(
                        "Not a number for axis %s: %r" % (axis, value), 400)
                validated_values[axis] = value

        # execute the jog commands
        for axis, value in validated_values.iteritems():
            printer.jog(axis, value)

    ##~~ home command
    elif command == "home":
        validated_values = []
        axes = data["axes"]
        for axis in axes:
            if not axis in valid_axes:
                return make_response("Invalid axis: %s" % axis, 400)
            validated_values.append(axis)

        # execute the home command
        printer.home(validated_values)

    return NO_CONTENT
示例#5
0
def printerPrintheadCommand():
	if not printer.isOperational() or printer.isPrinting():
		# do not jog when a print job is running or we don't have a connection
		return make_response("Printer is not operational or currently printing", 409)

	valid_commands = {
		"jog": [],
		"home": ["axes"]
	}
	command, data, response = util.getJsonCommandFromRequest(request, valid_commands)
	if response is not None:
		return response

	valid_axes = ["x", "y", "z"]
	##~~ jog command
	if command == "jog":
		# validate all jog instructions, make sure that the values are numbers
		validated_values = {}
		for axis in valid_axes:
			if axis in data:
				value = data[axis]
				if not isinstance(value, (int, long, float)):
					return make_response("Not a number for axis %s: %r" % (axis, value), 400)
				validated_values[axis] = value

		# execute the jog commands
		for axis, value in validated_values.iteritems():
			printer.jog(axis, value)

	##~~ home command
	elif command == "home":
		validated_values = []
		axes = data["axes"]
		for axis in axes:
			if not axis in valid_axes:
				return make_response("Invalid axis: %s" % axis, 400)
			validated_values.append(axis)

		# execute the home command
		printer.home(validated_values)

	return NO_CONTENT
示例#6
0
def printerPrintheadCommand():
	valid_commands = {
		"jog": [],
		"home": ["axes"],
		"feedrate": ["factor"],
		"position": ["x", "y"]
	}
	command, data, response = get_json_command_from_request(request, valid_commands)
	if response is not None:
		return response

	if not (printer.is_operational() or printer.is_locked()) or (printer.is_printing() and command != "feedrate"):
		# do not jog when a print job is running or we don't have a connection
		return make_response("Printer is not operational or currently printing", 409)

	valid_axes = ["x", "y", "z"]
	##~~ jog command
	if command == "jog":
		# validate all jog instructions, make sure that the values are numbers
		validated_values = {}
		for axis in valid_axes:
			if axis in data:
				value = data[axis]
				if not isinstance(value, (int, long, float)):
					return make_response("Not a number for axis %s: %r" % (axis, value), 400)
				validated_values[axis] = value

		# execute the jog commands
		for axis, value in validated_values.iteritems():
			printer.jog(axis, value)

	##~~ position command
	if command == "position":
		# validate all jog instructions, make sure that the values are numbers
		validated_values = {}
		
		x = data["x"]
		y = data["y"]
		if isinstance(x, (int, long, float)) and  isinstance(y, (int, long, float)) :
			printer.position(x, y)
		else:
			return make_response("Not a number for axis %s: %r" % (axis, value), 400)

	##~~ home command
	elif command == "home":
		validated_values = []
		axes = data["axes"]
		for axis in axes:
			if not axis in valid_axes:
				return make_response("Invalid axis: %s" % axis, 400)
			validated_values.append(axis)

		# execute the home command
		printer.home(validated_values)

	elif command == "feedrate":
		factor = data["factor"]
		if not isinstance(factor, (int, long, float)):
			return make_response("Not a number for feed rate: %r" % factor, 400)
		try:
			printer.feed_rate(factor)
		except ValueError as e:
			return make_response("Invalid value for feed rate: %s" % str(e), 400)

	return NO_CONTENT