diff --git a/src/dynamixelserver_serial.cpp b/src/dynamixelserver_serial.cpp index d0199df5cf50489fe3fad117182bb946fc84b291..03d0676fb9a14d09938d285473a68d2c18738d0f 100644 --- a/src/dynamixelserver_serial.cpp +++ b/src/dynamixelserver_serial.cpp @@ -41,8 +41,12 @@ void CDynamixelServerSerial::config_bus(const std::string &device, int baudrate) { TRS232_config serial_config; - if(this->comm_dev==NULL) + if(this->comm_dev!=NULL) { + delete this->comm_dev; + this->comm_dev=NULL; + } + try{ serial_config.baud=baudrate; serial_config.num_bits=8; serial_config.parity=none; @@ -52,6 +56,13 @@ void CDynamixelServerSerial::config_bus(const std::string &device, int baudrate) this->comm_dev->config(&serial_config); this->bus_info.baud_rate=baudrate; this->bus_info.device=device; + }catch(CException &e){ + if(this->comm_dev!=NULL) + { + delete this->comm_dev; + this->comm_dev=NULL; + } + throw e; } }