Пример #1
0
AMReadOnlyPVControl::AMReadOnlyPVControl(const QString& name, const QString& readPVname, QObject* parent, const QString description)
	: AMControl(name, "?", parent, description)  {

	wasConnected_ = false;
	readPV_ = new AMProcessVariable(readPVname, true, this);

	lowLimitPV_ = 0;
	highLimitPV_ = 0;

	allowLowLimitValuePVUpdates_ = true;
	allowHighLimitValuePVUpdates_ = true;

	lowLimitValue_ = -1;
	highLimitValue_ = -1;

	connect(readPV_, SIGNAL(valueChanged(double)), this, SIGNAL(valueChanged(double)));
	connect(readPV_, SIGNAL(alarmChanged(int,int)), this, SIGNAL(alarmChanged(int,int)));
	connect(readPV_, SIGNAL(readReadyChanged(bool)), this, SLOT(onPVConnected(bool)));
	connect(readPV_, SIGNAL(connectionTimeout()), this, SIGNAL(readConnectionTimeoutOccurred()));
	connect(readPV_, SIGNAL(error(int)), this, SLOT(onReadPVError(int)));
	connect(readPV_, SIGNAL(connectionTimeout()), this, SLOT(onConnectionTimeout()));

	connect(readPV_, SIGNAL(initialized()), this, SLOT(onReadPVInitialized()));

	// If the readPV_ is already initialized as soon as we create it [possible if it's sharing an existing connection], we'll never get the inialized() signal, do it here now:
	wasConnected_ = readPV_->readReady();	// same as isConnected(), but we cannot call virtual functions from a constructor, potentially breaks subclasses.
	if(readPV_->isInitialized())
		onReadPVInitialized();

}
Пример #2
0
    void
    BasicRemoteOperation::updateConnectionState(bool state)
    {
      if (!isActive())
        return;

      if (state)
      {
        if (!m_connection && (m_last_action > 0.0))
        {
          debug("connection resumed");
          onConnectionResumed();
        }

        m_connection = true;
        m_last_action = DUNE::Time::Clock::get();
      }
      else
      {
        if (m_connection)
        {
          debug("connection timeout");
          onConnectionTimeout();
        }

        m_connection = false;
      }
    }
Пример #3
0
AMProcessVariable::AMProcessVariable(const QString &pvName, bool monitor, QObject *parent, int connectionTimeoutMs) :
	QObject(parent)
{
	setObjectName("AMProcessVariable_" + pvName);
	shouldBeMonitoring_ = monitor;

	d_ = AMProcessVariableSupport::getPrivateForPVName(pvName);
	d_->attachProcessVariable(this);

	// This will notice if the connection times out:
	QTimer::singleShot(connectionTimeoutMs, this, SLOT(onConnectionTimeout()));
}
Пример #4
0
AMPVControl::AMPVControl(const QString& name, const QString& readPVname, const QString& writePVname, const QString& stopPVname, QObject* parent, double tolerance, double completionTimeoutSeconds, int stopValue, const QString &description)
	: AMReadOnlyPVControl(name, readPVname, parent, description)
{
	setTolerance(tolerance);
	allowsMovesWhileMoving_ = true;

	//not moving yet:
	moveInProgress_ = false;

	// not connected:
	wasConnected_ = false;

	// setpoint is initialized:
	setpoint_ = 0;

	// this is what to use for our timeout:
	completionTimeout_ = completionTimeoutSeconds;

	// connect the timer to the timeout handler:
	connect(&completionTimer_, SIGNAL(timeout()), this, SLOT(onCompletionTimeout()));

	// process variable:
	writePV_ = new AMProcessVariable(writePVname, true, this);
	// instead of connected(), use writeRead: connect(writePV_, SIGNAL(connected(bool)), this, SLOT(onPVConnected(bool)))
	connect(writePV_, SIGNAL(writeReadyChanged(bool)), this, SLOT(onPVConnected(bool)));
	connect(writePV_, SIGNAL(error(int)), this, SLOT(onWritePVError(int)));
	connect(writePV_, SIGNAL(connectionTimeout()), this, SIGNAL(writeConnectionTimeoutOccurred()));
	connect(writePV_, SIGNAL(connectionTimeout()), this, SLOT(onConnectionTimeout()));
	connect(writePV_, SIGNAL(valueChanged(double)), this, SLOT(onSetpointChanged(double)));
	connect(writePV_, SIGNAL(initialized()), this, SLOT(onWritePVInitialized()));

	// We now need to monitor the feedback position ourselves, to see if we get where we want to go:
	connect(readPV_, SIGNAL(valueChanged(double)), this, SLOT(onNewFeedbackValue(double)));

	// Do we have a stopPV?
	noStopPV_ = stopPVname.isEmpty();
	if(noStopPV_) {
		stopPV_ = 0;
	}
	else {
		stopPV_ = new AMProcessVariable(stopPVname, false, this);
		connect(stopPV_, SIGNAL(error(int)), this, SLOT(onReadPVError(int)));	/// \todo Does this need separate error handling? What if the stop write fails? That's really important.
	}
	stopValue_ = stopValue;


	// If any PVs are already connected [possible if they're sharing an existing connection]:
	wasConnected_ = (readPV_->readReady() && writePV_->writeReady());	// equivalent to isConnected(), but we cannot call virtual functions inside a constructor, that will break subclasses.
	if(writePV_->isInitialized())
		onWritePVInitialized();
}
Пример #5
0
AMPVwStatusControl::AMPVwStatusControl(const QString& name, const QString& readPVname, const QString& writePVname, const QString& movingPVname, const QString& stopPVname, QObject* parent, double tolerance, double moveStartTimeoutSeconds, AMAbstractControlStatusChecker* statusChecker, int stopValue, const QString &description)
	: AMReadOnlyPVwStatusControl(name, readPVname, movingPVname, parent, statusChecker, description) {

	// Initialize:
	moveInProgress_ = false;
	stopInProgress_ = false;
	startInProgress_ = false;
	settlingInProgress_ = false;
	settlingTime_ = 0.0;	/// \todo Once tested, this should maybe be enabled by default. All systems with separate status and feedback PVs will need it. How much time?
	setTolerance(tolerance);
	setpoint_ = 0;
	moveStartTimeout_ = moveStartTimeoutSeconds;
	hardwareWasMoving_ = false;

	// create new setpoint PV. Monitor it, in case someone else changes it
	writePV_ = new AMProcessVariable(writePVname, true, this);

	// connect:
	// use writeReadyChanged() instead of connected() here: connect(writePV_, SIGNAL(connected(bool)), this, SLOT(onPVConnected(bool)))
	connect(writePV_, SIGNAL(writeReadyChanged(bool)), this, SLOT(onPVConnected(bool)));
	connect(writePV_, SIGNAL(error(int)), this, SLOT(onWritePVError(int)));
	connect(writePV_, SIGNAL(connectionTimeout()), this, SIGNAL(writeConnectionTimeoutOccurred()));
	connect(writePV_, SIGNAL(connectionTimeout()), this, SLOT(onConnectionTimeout()));
	connect(writePV_, SIGNAL(valueChanged(double)), this, SLOT(onSetpointChanged(double)));
	connect(writePV_, SIGNAL(initialized()), this, SLOT(onWritePVInitialized()));

	// connect the timer to the timeout handler:
	connect(&moveStartTimer_, SIGNAL(timeout()), this, SLOT(onMoveStartTimeout()));
	connect(&settlingTimer_, SIGNAL(timeout()), this, SLOT(onSettlingTimeFinished()));

	// Do we have a stopPV?
	noStopPV_ = stopPVname.isEmpty();
	if(noStopPV_) {
		stopPV_ = 0;
	}
	else {
		stopPV_ = new AMProcessVariable(stopPVname, false, this);
		connect(stopPV_, SIGNAL(error(int)), this, SLOT(onReadPVError(int)));	/// \todo Does this need separate error handling? What if the stop write fails? That's really important.
	}
	stopValue_ = stopValue;


	// If any PVs were already connected on creation [possible if sharing an existing connection]:
	wasConnected_ = (readPV_->readReady() && writePV_->writeReady() && movingPV_->readReady());	// equivalent to isConnected(), but we cannot call virtual functions from the constructor, potentially breaks subclasses.
	if(writePV_->isInitialized())
		setMoveEnumStates(writePV_->enumStrings());
	if(movingPV_->readReady())
		hardwareWasMoving_ = (*statusChecker_)((int)movingPV_->lastValue());

}
Пример #6
0
CWebSocketClient::CWebSocketClient(QUrl url, QObject *parent)
	: m_url(url), QObject(parent)
{
	//m_url = QUrl(QStringLiteral("ws://localhost:1234"));

	connect(&m_webSocket, &QWebSocket::connected,		this, &CWebSocketClient::onConnected);
	connect(&m_webSocket, &QWebSocket::disconnected,	this, &CWebSocketClient::serverDisconnected);

	//Client tries to connect every 5s
	connection_Timer = new QTimer(this);
	connection_Timer->setInterval(5000);

	connect(connection_Timer,	SIGNAL(timeout()),		this,				SLOT(onConnectionTimeout()));
	connect(&m_webSocket,		SIGNAL(disconnected()),	this,				SLOT(resetSocket()));

	connect(&m_webSocket,		SIGNAL(connected()),	connection_Timer,	SLOT(stop()));
	connect(&m_webSocket,		SIGNAL(disconnected()),	connection_Timer,	SLOT(start()));

	connection_Timer->start();
}
Пример #7
0
AMReadOnlyPVwStatusControl::AMReadOnlyPVwStatusControl(const QString& name, const QString& readPVname, const QString& movingPVname, QObject* parent, AMAbstractControlStatusChecker* statusChecker, const QString &description)
	: AMReadOnlyPVControl(name, readPVname, parent, description)
{
	// Initializing:
	statusChecker_ = statusChecker;
	wasMoving_ = false;

	// Create the movingPV and hook it up:
	movingPV_ = new AMProcessVariable(movingPVname, true, this);
	connect(movingPV_, SIGNAL(valueChanged(int)), this, SLOT(onMovingChanged(int)));
	connect(movingPV_, SIGNAL(readReadyChanged(bool)), this, SLOT(onPVConnected(bool)));
	connect(movingPV_, SIGNAL(error(int)), this, SLOT(onStatusPVError(int)));
	connect(movingPV_, SIGNAL(connectionTimeout()), this, SIGNAL(movingConnectionTimeoutOccurred()));
	connect(movingPV_, SIGNAL(connectionTimeout()), this, SLOT(onConnectionTimeout()));

	// If any PVs were already connected on creation [possible if sharing an existing connection]:
	wasConnected_ = (readPV_->readReady() && movingPV_->readReady());	// equivalent to isConnected(), but we cannot call virtual functions inside a constructor, potentially breaks subclasses.
	if(movingPV_->readReady())
		wasMoving_ = (*statusChecker_)((int)movingPV_->lastValue());

}