Esempio n. 1
0
int CPI_E761_ZStage::OnPosition(MM::PropertyBase* pProp, MM::ActionType eAct) {
	MMThreadGuard guard(g_PI_ThreadLock);

	if (eAct == MM::BeforeGet) {
		double pos;
		int ret = GetPositionUm(pos);
		if (ret == DEVICE_OK) {
			pProp->Set(pos);
			LogMessage(
					"Get position: "
							+ boost::lexical_cast<std::string, float>(
									(float) pos) + "\tZephyre");
		}
		return ret;
	} else if (eAct == MM::AfterSet) {
		double pos;
		pProp->Get(pos);
		int ret = SetPositionUm(pos);
		LogMessage(
				"Set position: "
						+ boost::lexical_cast<std::string, float>((float) pos)
						+ "\tZephyre");
		OnStagePositionChanged(pos);
		return ret;
	}
	return DEVICE_OK;
}
void ZStage::EventHandler(int eventId, int /*data*/)
{
    if(eventId == Z_MOVED)
    {
        Hub* hub = static_cast<Hub*>(GetParentHub());
        if(hub)
        {
            hub->SetOff();
        }
        _busy = false;
        double z = z_CurrentPosition();
        OnStagePositionChanged(z);
    }
}
int ZStage::SetPositionUm(double pos)
{
    if(z_Available())
    {
        double spd(0);
        GetProperty(PROP_ZSPEED, spd);
        Hub* hub = static_cast<Hub*>(GetParentHub());
        if(hub)
        {
            hub->SetOn();
        }
        _busy = true;
        if(z_MoveAbsolutely(pos, spd))
        {
            if(hub)
            {
                if(hub->Wait())
                {
                    OnStagePositionChanged(pos);
                    return DEVICE_OK;
                }
                else
                {
                    z_Stop();
                    return ERR_Z_TIMEOUT;
                }
            }
            return DEVICE_OK;
        }
        else
        {
            _busy = false;
            return ERR_Z_MOVE;
        }
    }
    return ERR_Z_INVALID;
}