Example #1
0
def get_connection_options():
	"""
	Retrieves the available ports, baudrates, prefered port and baudrate for connecting to the printer.

<<<<<<< HEAD
	Returned ``dict`` has the following structure::
=======
from octoprint.comm.protocol import State as ProtocolState, Protocol
from octoprint.comm.protocol.reprap import RepRapProtocol
from octoprint.comm.transport.serialTransport import SerialTransport

from octoprint.plugin import plugin_manager, ProgressPlugin
>>>>>>> foosel/commRefactoring

	    ports: <list of available serial ports>
	    baudrates: <list of available baudrates>
	    portPreference: <configured default serial port>
	    baudratePreference: <configured default baudrate>
	    autoconnect: <whether autoconnect upon server startup is enabled or not>

	Returns:
	    (dict): A dictionary holding the connection options in the structure specified above
	"""
	return {
		"ports": comm.serialList(),
		"baudrates": comm.baudrateList(),
		"portPreference": settings().get(["serial", "port"]),
		"baudratePreference": settings().getInt(["serial", "baudrate"]),
		"autoconnect": settings().getBoolean(["serial", "autoconnect"])
	}
Example #2
0
def getConnectionOptions():
    """
	 Retrieves the available ports, baudrates, prefered port and baudrate for connecting to the printer.
	"""
    return {
        "ports": comm.serialList(),
        "baudrates": comm.baudrateList(),
        "portPreference": settings().get(["serial", "port"]),
        "baudratePreference": settings().getInt(["serial", "baudrate"])
    }
Example #3
0
def getConnectionOptions():
	"""
	 Retrieves the available ports, baudrates, prefered port and baudrate for connecting to the printer.
	"""
	return {
		"ports": comm.serialList(),
		"baudrates": comm.baudrateList(),
		"portPreference": settings().get(["serial", "port"]),
		"baudratePreference": settings().getInt(["serial", "baudrate"])
	}
	def serial_factory(self, comm_instance, port, baudrate, read_timeout, *args, **kwargs):
		"""
		This is basically the default serial factory, just with a weird open/open/close sequence applied

		Performs

			OPEN Parity.ODD
			OPEN Parity.NONE
			CLOSE Parity.ODD
			USE Parity.NONE

		See https://github.com/foosel/OctoPrint/issues/2271#issuecomment-352662485
		"""
		import serial
		from octoprint.events import Events, eventManager

		if port is None or port == 'AUTO':
			# no known port, try auto detection
			comm_instance._changeState(comm_instance.STATE_DETECT_SERIAL)

			port = comm_instance._detect_port()
			if port is None:
				comm_instance._errorValue = 'Failed to autodetect serial port, please set it manually.'
				comm_instance._changeState(comm_instance.STATE_ERROR)
				eventManager().fire(Events.ERROR, {"error": comm_instance.getErrorString()})
				comm_instance._log("Failed to autodetect serial port, please set it manually.")
				return None

		# Do not try to handle the Virtual Printer with this plugin
		# solves Issue 2 https://github.com/OctoPrint/OctoPrint-MalyanConnectionFix/issues/2
		if port == "VIRTUAL":
			comm_instance._log("Bypassing Malyan/Monoprice Connection Fix Plugin when using Virtual Printer")
			return None

		# connect to regular serial port
		comm_instance._log("Connecting to: %s" % port)
		comm_instance._log("Using Malyan/Monoprice Connection Fix Plugin to create serial connection")
		if baudrate == 0:
			from octoprint.util.comm import baudrateList
			baudrates = baudrateList()
			baudrate = 115200 if 115200 in baudrates else baudrates[0]

		serial_obj1 = serial.Serial(str(port), baudrate, timeout=read_timeout, writeTimeout=10000,
		                            parity=serial.PARITY_ODD)
		serial_obj2 = serial.Serial(str(port), baudrate, timeout=read_timeout, writeTimeout=10000,
		                            parity=serial.PARITY_NONE)

		serial_obj1.close()  # close the first instance, we don't actually need that

		return serial_obj2  # return the second instance
Example #5
0
def get_connection_options():
    """
	Retrieves the available ports, baudrates, prefered port and baudrate for connecting to the printer.

	Returned ``dict`` has the following structure::

	    ports: <list of available serial ports>
	    baudrates: <list of available baudrates>
	    portPreference: <configured default serial port>
	    baudratePreference: <configured default baudrate>
	    autoconnect: <whether autoconnect upon server startup is enabled or not>

	Returns:
	    (dict): A dictionary holding the connection options in the structure specified above
	"""
    return {
        "ports": comm.serialList(),
        "baudrates": comm.baudrateList(),
        "portPreference": settings().get(["serial", "port"]),
        "baudratePreference": settings().getInt(["serial", "baudrate"]),
        "autoconnect": settings().getBoolean(["serial", "autoconnect"])
    }
Example #6
0
def get_connection_options():
	"""
	Retrieves the available ports, baudrates, prefered port and baudrate for connecting to the printer.

	Returned ``dict`` has the following structure::

	    ports: <list of available serial ports>
	    baudrates: <list of available baudrates>
	    portPreference: <configured default serial port>
	    baudratePreference: <configured default baudrate>
	    autoconnect: <whether autoconnect upon server startup is enabled or not>

	Returns:
	    (dict): A dictionary holding the connection options in the structure specified above
	"""
	return {
		"ports": comm.serialList(),
		"baudrates": comm.baudrateList(),
		"portPreference": settings().get(["serial", "port"]),
		"baudratePreference": settings().getInt(["serial", "baudrate"]),
		"autoconnect": settings().getBoolean(["serial", "autoconnect"])
	}