User Tools

Site Tools


Sidebar


User's Manual & Quick Start Guide

Specifications

Where to Purchase

Donations & Support

Replacements Parts & Information

Mods & Improvements

How-to

OctoPrint

Slicer Stuff

Troubleshooting

Maintenance

WiFi

Web UI

Firmware

Downloads

Donations & Support



Looking for the Monoprice MP Mini Delta Wiki?

octoprint:serial_double_open_plugin

This is an old revision of the document!


Serial Double Open Plugin


Experimental
This plugin is still in testing.

Having trouble connecting to your printer with OctoPrint?
This may be a solution/workaround to your OctoPrint connection woes.


Installation Instructions

https://github.com/foosel/OctoPrint/issues/2271#issuecomment-359500927

foosel commented about 18 hours ago

So… here's something to test with.

It's a minimal plugin that changes the serial opening to what @ygator suggested. Note that a) it doesn't work at all on Windows based systems, b) it doesn't play nice with other printers (so I couldn't really test this) and c) I have absolutely no idea at all if this might actually help or not.

To test, on OctoPi, SSH into your machine, then:

cd ~/.octoprint/plugins
wget https://gist.githubusercontent.com/foosel/73dd83fc723fa164a8e2f88b5d8476e6/raw/dd58f5f6e423a00458b4754a0931e8bffa8ce415/serial_double_open.py
sudo service octoprint restart

Please report back. To uninstall/disable it again, it can be found as “Serial Double Open Plugin” in the Plugin Manager.


https://gist.github.com/foosel/73dd83fc723fa164a8e2f88b5d8476e6

Minimal OctoPrint plugin that performs a double open on the serial port to potentially work around issues with Malyan printers. Put file into ~/.octoprint/plugins and restart the server. Based on https://github.com/foosel/OctoPrint/issues/2271#issuecomment-352662485

serial_double_open.py
# coding=utf-8
from __future__ import absolute_import
 
import serial
import logging
import sys
 
import octoprint.plugin
from octoprint.events import Events, eventManager
 
def serial_factory(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
    """
    if sys.platform == "win32":
        # Windows doesn't allow double open, log and bail
        logging.getLogger("octoprint.plugins.serial_double_open").error("Cannot run serial double open under windows")
        return None
 
    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
 
    # connect to regular serial port
    comm_instance._log("Connecting to: %s" % port)
    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
 
__plugin_name__ = "Serial Double Open Plugin"
__plugin_description__ = "Performs a double open on the serial port to potentially work around issues with Malyan printers"
__plugin_author__ = "Gina Häußge"
__plugin_homepage__ = "https://github.com/foosel/OctoPrint/issues/2271#issuecomment-352662485"
__plugin_hooks__ = {
    "octoprint.comm.transport.serial.factory": serial_factory
}
octoprint/serial_double_open_plugin.1516707670.txt.gz · Last modified: 2018/01/23 11:41 by Matthew Upp