Skip to content

Fix #8: WebSerial Communication Issues with Ender 3 v2#9

Open
nkymut wants to merge 6 commits intomachineagency:mainfrom
nkymut:upgrade
Open

Fix #8: WebSerial Communication Issues with Ender 3 v2#9
nkymut wants to merge 6 commits intomachineagency:mainfrom
nkymut:upgrade

Conversation

@nkymut
Copy link

@nkymut nkymut commented Dec 6, 2024

Changes Made

  1. Added async port handling

    • New connectPrinter() method for explicit connection
      • Clearer API for connecting to printer (fab.connectPrinter())
    • added async/await for port opening
    async connectPrinter() {
      try {
        await this.serial.requestPort();
        // Port selection triggers portavailable event handler
      } catch (err) {
        console.error("Failed to request port:", err);
        this.emit("error", err);
      }
    }
  2. Improved port opening event handlers

    • Convert callbacks to async/await
    • Added error handling
    this.serial.on("portavailable", async () => {
      try {
        await this.serial.open({ baudRate: this.baudRate });
        console.log("Port opened successfully");
      } catch (err) {
        console.error("Failed to open port:", err);
      }
    });
  3. Added a message buffer for command queue management

    • Clear command buffer after copying
    this.commandStream = [...this.commands];
    this.commands = []; // Clear commands after copying
  4. Improved message processing

    • Added basic logging for received messages
    • Added handlers for responses
    • Fixed position reporting parsing

Testing

Tested with Ender 3 v2:

  • Connection process
  • Control panel example
  • Multiple commands execute in sequence
  • Position reporting works throughout operation
  • Auto-home and movement commands
  • Nozzle and headbed temp control
  • midi thingy
  • fabscribe

Fixes #8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebSerial connection not working with Ender 3 v2

1 participant