private void cleanupPort() {
   //		if (m_commBr != null) {
   //			try {
   //				m_commBr.close();
   //			} catch (IOException e) {
   //				s_logger.error("Cannot close port buffered reader", e);
   //			}
   //			m_commBr = null;
   //		}
   //		if (m_commBw != null) {
   //			try {
   //				m_commBw.close();
   //			} catch (IOException e) {
   //				s_logger.error("Cannot close port buffered writer", e);
   //			}
   //			m_commBw = null;
   //		}
   if (m_commIs != null) {
     try {
       s_logger.info("Closing port input stream...");
       m_commIs.close();
       s_logger.info("Closed port input stream");
     } catch (IOException e) {
       s_logger.error("Cannot close port input stream", e);
     }
     m_commIs = null;
   }
   if (m_commOs != null) {
     try {
       s_logger.info("Closing port output stream...");
       m_commOs.close();
       s_logger.info("Closed port output stream");
     } catch (IOException e) {
       s_logger.error("Cannot close port output stream", e);
     }
     m_commOs = null;
   }
   if (m_commConnection != null) {
     try {
       s_logger.info("Closing port...");
       m_commConnection.close();
       s_logger.info("Closed port");
     } catch (IOException e) {
       s_logger.error("Cannot close port", e);
     }
     m_commConnection = null;
   }
 }
 public void disconnect() throws ModbusProtocolException {
   if (conn != null) {
     try {
       conn.close();
       s_logger.debug("Serial connection closed");
     } catch (IOException e) {
       throw new ModbusProtocolException(
           ModbusProtocolErrorCode.TRANSACTION_FAILURE, e.getMessage());
     }
     conn = null;
   }
   if (m_serial485) {
     if (gpioModeSwitch != null) {
       try {
         gpioModeSwitch.close();
       } catch (IOException e) {
         throw new ModbusProtocolException(
             ModbusProtocolErrorCode.TRANSACTION_FAILURE, e.getMessage());
       }
     }
   }
 }
Beispiel #3
0
    public void disconnect() {

      if ((m_task != null) && (!m_task.isDone())) {
        s_logger.debug("disconnect() :: Cancelling GpsSerialCommunicate task ...");
        m_task.cancel(true);
        s_logger.info("disconnect() :: GpsSerialCommunicate task cancelled? = {}", m_task.isDone());
        m_task = null;
      }

      if (m_executor != null) {
        s_logger.debug("disconnect() :: Terminating GpsSerialCommunicate Thread ...");
        m_executor.shutdownNow();
        try {
          m_executor.awaitTermination(THREAD_TERMINATION_TOUT, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
          s_logger.warn("Interrupted", e);
        }
        s_logger.info(
            "disconnect() :: GpsSerialCommunicate Thread terminated? - {}",
            m_executor.isTerminated());
        m_executor = null;
      }

      if (conn != null) {
        try {
          if (in != null) {
            in.close();
            in = null;
          }
          conn.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
        conn = null;
      }
    }