diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index f627fc2b8..d7361e47c 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -2105,6 +2105,17 @@ int MachineObject::command_ams_refresh_rfid(std::string tray_id) return this->publish_gcode(gcode_cmd); } +int MachineObject::command_ams_refresh_rfid2(int ams_id, int slot_id) +{ + json j; + j["print"]["command"] = "ams_get_rfid"; + j["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++); + j["print"]["ams_id"] = ams_id; + j["print"]["slot_id"] = slot_id; + return this->publish_json(j.dump()); +} + + int MachineObject::command_ams_select_tray(std::string tray_id) { std::string gcode_cmd = (boost::format("M620 P%1% \n") % tray_id).str(); diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index 92a9733bd..2c8f414e5 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -1075,6 +1075,7 @@ public: int command_ams_filament_settings(int ams_id, int tray_id, std::string filament_id, std::string setting_id, std::string tray_color, std::string tray_type, int nozzle_temp_min, int nozzle_temp_max); int command_ams_select_tray(std::string tray_id); int command_ams_refresh_rfid(std::string tray_id); + int command_ams_refresh_rfid2(int ams_id, int slot_id); int command_ams_control(std::string action); int command_set_chamber_light(LIGHT_EFFECT effect, int on_time = 500, int off_time = 500, int loops = 1, int interval = 1000); int command_set_chamber_light2(LIGHT_EFFECT effect, int on_time = 500, int off_time = 500, int loops = 1, int interval = 1000); diff --git a/src/slic3r/GUI/StatusPanel.cpp b/src/slic3r/GUI/StatusPanel.cpp index 9ecca4c29..4c63fbc07 100644 --- a/src/slic3r/GUI/StatusPanel.cpp +++ b/src/slic3r/GUI/StatusPanel.cpp @@ -4381,16 +4381,6 @@ void StatusPanel::on_ams_refresh_rfid(wxCommandEvent &event) { if (obj) { - if (obj->is_filament_at_extruder()) { - MessageDialog msg_dlg( - nullptr, - _L("Cannot read filament info: the filament is loaded to the tool head,please unload the filament and try again."), - wxEmptyString, - wxICON_WARNING | wxYES); - msg_dlg.ShowModal(); - return; - } - //std::string curr_ams_id = m_ams_control->GetCurentAms(); if (event.GetInt() < 0 || event.GetInt() > VIRTUAL_TRAY_MAIN_ID){ return; @@ -4402,20 +4392,48 @@ void StatusPanel::on_ams_refresh_rfid(wxCommandEvent &event) } std::string curr_can_id = event.GetString().ToStdString(); - std::map::iterator it = obj->amsList.find(curr_ams_id); - if (it == obj->amsList.end()) { + std::map::iterator ams_it = obj->amsList.find(curr_ams_id); + if (ams_it == obj->amsList.end()) { BOOST_LOG_TRIVIAL(trace) << "ams: find " << curr_ams_id << " failed"; return; } - auto tray_it = it->second->trayList.find(curr_can_id); - if (tray_it == it->second->trayList.end()) { + auto slot_it = ams_it->second->trayList.find(curr_can_id); + if (slot_it == ams_it->second->trayList.end()) { BOOST_LOG_TRIVIAL(trace) << "ams: find " << curr_can_id << " failed"; return; } + auto has_filament_at_extruder = false; + auto use_new_command = false; + + if (obj->m_extder_data.total_extder_count <= 1 && !obj->is_enable_np) { + has_filament_at_extruder = obj->is_filament_at_extruder(); + } else { + use_new_command = true; + + if (ams_it->second->nozzle < obj->m_extder_data.extders.size()) { + has_filament_at_extruder = obj->m_extder_data.extders[ams_it->second->nozzle].ext_has_filament; + } + } + + if (has_filament_at_extruder) { + MessageDialog msg_dlg(nullptr, _L("Cannot read filament info: the filament is loaded to the tool head,please unload the filament and try again."), wxEmptyString, + wxICON_WARNING | wxYES); + msg_dlg.ShowModal(); + return; + } + + try { - int tray_index = atoi(curr_ams_id.c_str()) * 4 + atoi(tray_it->second->id.c_str()); - obj->command_ams_refresh_rfid(std::to_string(tray_index)); + if (!use_new_command) { + int tray_index = atoi(curr_ams_id.c_str()) * 4 + atoi(slot_it->second->id.c_str()); + obj->command_ams_refresh_rfid(std::to_string(tray_index)); + } + + if (use_new_command) { + obj->command_ams_refresh_rfid2(stoi(curr_ams_id), stoi(curr_can_id)); + } + } catch (...) { ; }