Skip to content

Commit

Permalink
Update GCodeSender.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
RBEGamer committed Mar 18, 2022
1 parent 20d1785 commit 0e2b58e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/src_controller/controller/controller/GCodeSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,21 @@ bool GCodeSender::init_serial_port(std::string _serial_port_file, int _baud_rate
}
//configure serialport though 3rd party lib
close_serial_port(); //CLOSE PORT IF OPEN

if(std::filesystem::is_symlink(_serial_port_file)){
LOG_F(INFO, "filesystem::is_symlink(_port) %s", _serial_port_file.c_str());
//GET PREFIX EG /dev/
std::string prefix = "";
const size_t slash_index = _serial_port_file.find_last_of("/\\");
if(slash_index){
prefix = _serial_port_file.substr(0,slash_index) + '/';
}
//ADD SYMLINK DESTINATION ttyTEST =>prefix + ttyUSB0 = /dev/ttyUSB0
_serial_port_file = prefix + std::filesystem::read_symlink(_serial_port_file).string();
LOG_F(INFO, "filesystem::read_symlink(_port) %s", _serial_port_file.c_str());
}


if(port->openDevice(_serial_port_file.c_str(), _baud_rate) != 1) {
LOG_F(ERROR, "serial port open failed %s WITH BAUD %i",_serial_port_file.c_str(),_baud_rate);
return false;
Expand Down Expand Up @@ -408,4 +423,4 @@ bool GCodeSender::is_target_position_reached() {
//IN THIS CASE WE DONT READ THE CURRENT POS (gcode M114) ONLY WAITING FOR FINISHING THE MOVE
//MORE IS NOT NEEDED FOR THIS APPLICATION
return write_gcode("M400", true);
}
}

0 comments on commit 0e2b58e

Please sign in to comment.