Skip to content

Commit

Permalink
working Modbus IO thread
Browse files Browse the repository at this point in the history
  • Loading branch information
DaAwesomeP committed Feb 13, 2023
1 parent 87934d5 commit 038eac6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions include/aniray/IOInterfaceModbus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef ANIRAY_INPUTINTERFACEMODBUS_HPP
#define ANIRAY_INPUTINTERFACEMODBUS_HPP

#include <chrono>
#include <cstdint>
#include <shared_mutex>
#include <string>
Expand All @@ -35,6 +36,7 @@
#include <modbus/modbus.h>

#include <aniray/IOInterface.hpp>
#include <aniray/PeriodicThread.hpp>

namespace aniray {
namespace IOInterface {
Expand Down Expand Up @@ -113,6 +115,13 @@ class IOInterfaceModbus : public aniray::IOInterface::IOInterfaceGeneric {
// void updateInputsCounter(ConfigFunction functionConfig) {}
};

class IOInterfaceModbusThread : public IOInterfaceModbus, public aniray::PeriodicThread {
public:
IOInterfaceModbusThread(std::string tcpAddress, std::uint16_t tcpPort, std::chrono::milliseconds updateRateMs);
private:
void periodicAction() override;
};

} // namespace IOInterfaceModbus
} // namespace IOInterface
} // namespace aniray
Expand Down
2 changes: 1 addition & 1 deletion include/aniray/PeriodicThread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class PeriodicThread { // NOLINT(cppcoreguidelines-special-member-functions,hicp
std::unique_ptr<boost::thread> mIOThread;
mutable std::shared_mutex mUpdateRateMutex;

void timerHandler ();
void timerHandler();
};

} // namespace aniray
Expand Down
8 changes: 8 additions & 0 deletions src/IOInterfaceModbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ void IOInterfaceModbus::updateInputDiscrete(ConfigInputDiscrete configInputDiscr
values->setValues(out);
}

IOInterfaceModbusThread::IOInterfaceModbusThread(std::string tcpAddress, std::uint16_t tcpPort, std::chrono::milliseconds updateRateMs)
: IOInterfaceModbus(tcpAddress, tcpPort)
, PeriodicThread(updateRateMs) {}

void IOInterfaceModbusThread::periodicAction() {
refreshInputs();
}

} // namespace Modbus
} // namespace IOInterface
} // namespace aniray

0 comments on commit 038eac6

Please sign in to comment.