diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index bff7881c463c3ce5ca15d33ff07d88e676744f02..a3dbeb59e4a01b571ad3d84772910f6f0d0c8198 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -10,7 +10,7 @@ build-package:
   script:
     - apt update || apt -y install ca-certificates && apt update
 #  Uncomment to install dependencies
-#    - apt -y install iri-<package_name>-dev
+#    - apt -y iri-<package_name>-dev
     - apt -y install iri-iriutils-dev
     - mkdir -pv build
     - cd build
diff --git a/include/can/can.h b/include/can/can.h
index 00129f1149407e9f2e3c518c2e67f694416236d3..57251edcbbe8cead6f980e9f6f8cb78c4090e895 100755
--- a/include/can/can.h
+++ b/include/can/can.h
@@ -13,6 +13,7 @@
 #include <linux/can/bcm.h>
 #include <linux/can/raw.h>
 #include <map>
+#include <linux/sockios.h>
 
 #include "threadserver.h"
 #include "eventserver.h"
diff --git a/include/serial/rs232.h b/include/serial/rs232.h
index f8921bad564598ce76e60867dc54b61d9a6d9883..fe70247bd0233da51ba749fc65bb0fcd3631f27a 100644
--- a/include/serial/rs232.h
+++ b/include/serial/rs232.h
@@ -6,7 +6,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h>
-#include <asm/termbits.h>
 #include <unistd.h>  
 #include <fcntl.h>
 #include <errno.h>
diff --git a/src/comm.cpp b/src/comm.cpp
index 3acf8a7f841046905bc147af039a0e6b65096813..28450cc25697454a15ebde54d44a167cddda470e 100644
--- a/src/comm.cpp
+++ b/src/comm.cpp
@@ -4,6 +4,7 @@
 #include "comm.h"
 #include "commexceptions.h"
 #include "ctime.h"
+#include "pthread.h"
 
 CComm::CComm(const std::string& comm_id) 
 {
@@ -127,7 +128,8 @@ int CComm::read(unsigned char *data,int len)
     }
     else
     {
-      throw CCommException(_HERE_,"The communication device is not configured yet.\n",this->comm_id);
+      return 0;
+//      throw CCommException(_HERE_,"The communication device is not configured yet.\n",this->comm_id);
     }
   }
   return len;
@@ -164,7 +166,8 @@ int CComm::write(unsigned char *data,int len)
     else
     {
       this->access_comm.exit();
-      throw CCommException(_HERE_,"The communication device is not configured yet.\n",this->comm_id);
+      return 0;
+//      throw CCommException(_HERE_,"The communication device is not configured yet.\n",this->comm_id);
     }
     this->access_comm.exit();
     return len;
@@ -212,7 +215,9 @@ void CComm::close(void)
   {
     /* finish the thread */
     if(this->state==configured)
+    {
       this->thread_server->kill_thread(this->comm_thread_id);
+    }
     /* close the communication device */
     this->access_comm.try_enter();
     try{
@@ -238,7 +243,9 @@ void *CComm::comm_thread(void *param)
 
   while(!end)
   {
+    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL);
     wait_result=comm_dev->hard_wait_comm_event();
+    pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL);
     try{
       comm_dev->access_comm.enter();
       if(wait_result==-1)
@@ -256,6 +263,17 @@ void *CComm::comm_thread(void *param)
       }
       comm_dev->access_comm.exit();
     }catch(CException &e){
+      try{
+        comm_dev->hard_close();
+      }catch(CException &close){
+        std::cout << close.what() << std::endl;
+      }
+      /* flush the data queues */
+      comm_dev->receive_queue.flush();
+      /* change the current state */
+      comm_dev->state=created;
+      comm_dev->access_comm.exit();
+      std::cout << e.what() << std::endl;
       end=true;
     }
   }
@@ -309,16 +327,12 @@ void CComm::on_error(void)
 
 CComm::~CComm()
 {
+  this->close();
   /* delete the events */
-  if(this->rx_event_id.size()!=0)
-    this->event_server->delete_event(this->rx_event_id);
-  if(this->error_event_id.size()!=0)
-  {
-    this->event_server->delete_event(this->error_event_id);
-  }
+  this->event_server->delete_event(this->rx_event_id);
+  this->rx_event_id="";
+  this->event_server->delete_event(this->error_event_id);
+  this->error_event_id="";
   /* delete the thread */
-  if(this->comm_thread_id.size()!=0)
-  {
-    this->thread_server->delete_thread(this->comm_thread_id);
-  }
+  this->thread_server->delete_thread(this->comm_thread_id);
 }
diff --git a/src/serial/rs232.cpp b/src/serial/rs232.cpp
index 9bf6cb9740ab3eb7d83ae3bd8a3fe11458cd0145..7dca545c5b1e29ef3ab30f42db8b6bfff64583ed 100644
--- a/src/serial/rs232.cpp
+++ b/src/serial/rs232.cpp
@@ -1,6 +1,7 @@
 #include "rs232.h"
 #include "rs232exceptions.h"
 #include "ctime.h"
+#include <asm/termbits.h>
 
 CRS232::CRS232(const std::string& comm_id) : CComm(comm_id)
 {