From 767daa1201659a6ef48f9b47ed1207fcf5d14fc8 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 13 Apr 2026 21:57:18 +0200 Subject: [PATCH] CrealityPrint: add CFS material box query Add query_boxes_info() to discover loaded materials in the CFS (Creality Filament System) via websocket. Returns the boxsInfo JSON with slot details (type, color, vendor, temperature range). Signed-off-by: Igor Mammedov --- src/slic3r/Utils/CrealityPrint.cpp | 17 +++++++++++++++++ src/slic3r/Utils/CrealityPrint.hpp | 1 + 2 files changed, 18 insertions(+) diff --git a/src/slic3r/Utils/CrealityPrint.cpp b/src/slic3r/Utils/CrealityPrint.cpp index 0ae698001c..8174a2c6bb 100644 --- a/src/slic3r/Utils/CrealityPrint.cpp +++ b/src/slic3r/Utils/CrealityPrint.cpp @@ -261,6 +261,23 @@ bool CrealityPrint::supports_multi_color_print() const || m_model == "F021"; // K2 } +std::string CrealityPrint::query_boxes_info() const +{ + try { + net::io_context ioc; + websocket::stream ws{ioc}; + ws_connect(ioc, ws, m_host, "9999"); + + json boxs_query = {{"method", "get"}, {"params", {{"boxsInfo", 1}}}}; + std::string result = ws_send_and_read(ws, boxs_query, "boxsInfo"); + ws.close(websocket::close_code::normal); + return result; + } catch (std::exception const& e) { + BOOST_LOG_TRIVIAL(error) << "CrealityPrint: Failed to query boxsInfo: " << e.what(); + return {}; + } +} + bool CrealityPrint::start_print(wxString &msg, const std::string &filename) const { try { diff --git a/src/slic3r/Utils/CrealityPrint.hpp b/src/slic3r/Utils/CrealityPrint.hpp index 08c1bb883d..7952ae692e 100644 --- a/src/slic3r/Utils/CrealityPrint.hpp +++ b/src/slic3r/Utils/CrealityPrint.hpp @@ -30,6 +30,7 @@ public: PrintHostPostUploadActions get_post_upload_actions() const; bool upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn) const override; bool supports_multi_color_print() const; + std::string query_boxes_info() const; protected: virtual void set_auth(Http& http) const;