void TRegisterHandler::SetTextValue(const std::string& v)
{
    {
        // don't hold the lock while notifying the client below
        std::lock_guard<std::mutex> lock(SetValueMutex);
        Dirty = true;
        Value = ConvertMasterValue(v);
    }
    FlushNeeded->Signal();
}
void TRegisterHandler::Flush(PModbusContext ctx)
{
    set_value_mutex.lock();
    if (dirty) {
        dirty = false;
        set_value_mutex.unlock();
        ctx->SetSlave(reg.Slave);
        try {
            Write(ctx, ConvertMasterValue(value));
        } catch (const TModbusException& e) {
            std::cerr << "TRegisterHandler::Flush(): warning: " << e.what() << std::endl;
            return;
        }
    }
    else
        set_value_mutex.unlock();
}