#include "modbus.h" #include "message_queue.h" CModbusTcpSensor::CModbusTcpSensor(CMessageQueue* q) :_message(q) { _run = false; } void CModbusTcpSensor::SetModbusTcpSensor(SensorModbusTcp* modbus) { _modbus = modbus; } void CModbusTcpSensor::Start() { if(!_run) { _thread = std::thread(&CModbusTcpSensor::Run, this); _run = true; } //_modbus->read_registers(0x28,0x04); } void CModbusTcpSensor::Run() { while (_run) { _modbus->read_input_registers(0x10A,1); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } } void CModbusTcpSensor::Stop() { if (_run) { _run = false; _thread.join(); } } void CModbusTcpSensor::Notify(uint16_t * buffer) { if (_run) { _message->_Radardata.r7 = buffer[0]; _message->_Radardata.r8 = buffer[1]; } }