Commit 15300e62 authored by Marco Buttu's avatar Marco Buttu Committed by GitHub
Browse files

Merge pull request #122 from discos/ModbusChannel_refactoring

Refactored ModbusChannel to use ACE mutexes instead of boost
parents 5e44ee0b 44ef947b
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
#ifndef MODBUSCHANNEL_HPP
#define MODBUSCHANNEL_HPP

#include <acsThread.h>
#include <IRA>
#include <modbus/modbus.h>
#include <sys/time.h>
#include <string>
#include <cerrno>
#include <stdexcept>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>

#define MODBUS_DEFAULT_PORT MODBUS_TCP_DEFAULT_PORT
#define MODBUS_TIMEOUT 2
@@ -89,7 +90,7 @@ class ModbusChannel
        T get(int address); //throw ModbusError
    private:
        /* class members */
        boost::mutex _connection_guard;
        BACIMutex  _connection_guard;
        std::string _server_ip;
        int _server_port;
        bool _is_connected;
+2 −2
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ LIBRARIES_L =
#
# <brief description of lllll library>
ModbusChannel_OBJECTS   = ModbusChannel
ModbusChannel_LIBS      = modbus boost_thread
ModbusChannel_LIBS      = modbus acsnc

#
# Scripts (public and local)
+2 −2
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ ModbusChannel::~ModbusChannel()
void
ModbusChannel::connect()
{
    boost::mutex::scoped_lock lock(_connection_guard);
    baci::ThreadSyncGuard lock(&_connection_guard);
    int rc;
    if(!(this->_is_connected))
    {
@@ -66,7 +66,7 @@ ModbusChannel::connect()
void
ModbusChannel::disconnect()
{
    boost::mutex::scoped_lock lock(_connection_guard);
    baci::ThreadSyncGuard lock(&_connection_guard);
    if(this->_is_connected){
        modbus_close(this->_modbus_context);
        this->_is_connected = false;