Example #1
0
int RAMPSXYStage::SetPositionSteps(long x, long y)
{
  LogMessage("XYStage: SetPositionSteps");
  RAMPSHub* pHub = static_cast<RAMPSHub*>(GetParentHub());
  std::string status = pHub->GetState();
  if (status == "Running") {
      return ERR_STAGE_MOVING;
  }
  double newPosX = x * stepSize_um_;
  double newPosY = y * stepSize_um_;
  double difX = newPosX - posX_um_;
  double difY = newPosY - posY_um_;
  double distance = sqrt( (difX * difX) + (difY * difY) );
     
  
  posX_um_ = x * stepSize_um_;
  posY_um_ = y * stepSize_um_;

  // TODO(dek): if no position change, don't send new position.
  char buff[100];
  sprintf(buff, "G0 X%f Y%f", posX_um_/1000., posY_um_/1000.);
  std::string buffAsStdStr = buff;
  int ret = pHub->SendCommand(buffAsStdStr);
  if (ret != DEVICE_OK)
    return ret;

  pHub->SetTargetXY(posX_um_, posY_um_);

  ret = OnXYStagePositionChanged(posX_um_, posY_um_);
  if (ret != DEVICE_OK)
    return ret;

  return DEVICE_OK;
}
int ZStage::Initialize()
{
    if(!g_device_connected)
        return DEVICE_NOT_CONNECTED;

    if(_init)
        return DEVICE_OK;

    // Name and description
    CreateProperty(MM::g_Keyword_Name, g_devlist[MoticZ][0],
                   MM::String, true);
    CreateProperty(MM::g_Keyword_Description, g_devlist[MoticZ][1],
                   MM::String, true);

    double l(0), r(0);
    z_SpeedRange(&l, &r);
    CreateProperty(PROP_ZSPEED, CDeviceUtils::ConvertToString(r / 2), MM::Float, false, 0);
    SetPropertyLimits(PROP_ZSPEED, l, r);

    Hub* hub = static_cast<Hub*>(GetParentHub());
    if(hub)
    {
        hub->AddEventReceiver(this);
    }

    UpdateStatus();

    _init = true;
    return DEVICE_OK;
}
Example #3
0
bool RAMPSXYStage::Busy()
{
  LogMessage("XYStage: Busy called");
  
  RAMPSHub* pHub = static_cast<RAMPSHub*>(GetParentHub());
  std::string status = pHub->GetState();

  LogMessage("Status is:");
  LogMessage(status);
  status_ = status;

  if (status_ == "Idle") {
	  LogMessage("idle, return false.");
    return false;

  }
  else if (status_ == "Running") {
    LogMessage("Running, return true.");
    return true;
  }
  else {
	  LogMessage("Unexpected status.");
	  return false;
  }
}
int Illumination::Shutdown()
{
    Hub* hub = static_cast<Hub*>(GetParentHub());
    if(hub)
    {
        hub->RemoveEventReceiver(this);
    }

    _init = false;
    return DEVICE_OK;
}
int XYStage::Shutdown()
{
    _busy = false;
    _init = false;

    Hub* hub = static_cast<Hub*>(GetParentHub());
    if(hub)
    {
        hub->RemoveEventReceiver(this);
    }
    return DEVICE_OK;
}
void Objectives::EventHandler(int eventId, int /*data*/)
{
    if(eventId == OBJECTIVE_CHANGED)
    {
        Hub* hub = static_cast<Hub*>(GetParentHub());
        if(hub)
        {
            hub->SetOff();
        }
        _busy = false;
    }
}
int Objectives::Initialize()
{
    if(!g_device_connected)
        return DEVICE_NOT_CONNECTED;

    if(_init)
        return DEVICE_OK;

    // Name and description
    CreateProperty(MM::g_Keyword_Name, g_devlist[MoticObjectives][0],
                   MM::String, true);
    CreateProperty(MM::g_Keyword_Description, g_devlist[MoticObjectives][1],
                   MM::String, true);

    _mag.clear();
    if(obj_Available())
    {
        for(int i = 0; i < obj_GetCount(); i++)
        {
            double m = obj_GetObjectiveMagnification(i);
            if(m > 0)
            {
                _mag[i] = m;
            }
        }
        char buf[64];
        for(map<int, double>::iterator i = _mag.begin(); i != _mag.end(); ++i)
        {
            sprintf(buf, "%dX", (int)i->second);
            SetPositionLabel(i->first, buf);
        }
        _curpos = obj_GetCurrentObjective();

        CPropertyAction* act = new CPropertyAction(this, &Objectives::OnState);
        CreateProperty(MM::g_Keyword_State, CDeviceUtils::ConvertToString(_curpos), MM::Integer, false, act);

        act = new CPropertyAction(this, &CStateBase::OnLabel);
        CreateProperty(MM::g_Keyword_Label, "", MM::String, false, act);
    }

    Hub* hub = static_cast<Hub*>(GetParentHub());
    if(hub)
    {
        hub->AddEventReceiver(this);
    }

    UpdateStatus();

    _init = true;
    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);
    }
}
void XYStage::EventHandler(int eventId, int /*data*/)
{
    if(eventId == XY_MOVED)
    {
        Hub* hub = static_cast<Hub*>(GetParentHub());
        if(hub)
        {
            hub->SetOff();
        }
        _busy = false;
        // Notify
        double x(0), y(0);
        xy_CurrentPosition(&x, &y);
        OnXYStagePositionChanged(x, y);
    }
}
int CArduinoNeoPixelShutter::OnMulti(MM::PropertyBase* pProp, MM::ActionType eAct)
{
   CArduinoNeoPixelHub* hub = static_cast<CArduinoNeoPixelHub*>(GetParentHub());
   if (eAct == MM::BeforeGet)
   {
      // use cached state
      pProp->Set((long)hub->GetMulti());
   }
   else if (eAct == MM::AfterSet)
   {
      long pos;
      pProp->Get(pos);
      hub->SetMulti(pos);
   }
   return DEVICE_OK;
}
Example #11
0
int RAMPSXYStage::Initialize()
{
  LogMessage("XYStage: initialize");
  RAMPSHub* pHub = static_cast<RAMPSHub*>(GetParentHub());
  if (pHub)
  {
    char hubLabel[MM::MaxStrLength];
    pHub->GetLabel(hubLabel);
    SetParentID(hubLabel); // for backward comp.
  }
  else
    LogMessage(NoHubError);

  if (initialized_)
    return DEVICE_OK;

  // set property list
  // -----------------

  // Name
  int ret = CreateStringProperty(MM::g_Keyword_Name, g_XYStageDeviceName, true);
  if (DEVICE_OK != ret)
    return ret;

  // Description
  ret = CreateStringProperty(MM::g_Keyword_Description, "RAMPS XY stage driver", true);
  if (DEVICE_OK != ret)
    return ret;

  CPropertyAction* pAct = new CPropertyAction (this, &RAMPSXYStage::OnStepSize);
  CreateProperty(g_StepSizeProp, CDeviceUtils::ConvertToString(stepSize_um_), MM::Float, false, pAct);

  // Update lower and upper limits.  These values are cached, so if they change during a session, the adapter will need to be re-initialized
  ret = UpdateStatus();
  if (ret != DEVICE_OK)
    return ret;

  
  initialized_ = true;

  return DEVICE_OK;
}
int CArduinoNeoPixelShutter::OnBlueBrightness(MM::PropertyBase* pProp, MM::ActionType eAct)
{
   CArduinoNeoPixelHub* hub = static_cast<CArduinoNeoPixelHub*>(GetParentHub());
   if (eAct == MM::BeforeGet)
   {
      // use cached state
      pProp->Set((long)hub->GetBlueBrightness());
   }
   else if (eAct == MM::AfterSet)
   {
      long pos;
      pProp->Get(pos);
      std::string command = "B" + boost::lexical_cast<std::string>((long long)pos) + "\r";
      int ret = hub->WriteToComPortH((const unsigned char*) command.c_str(), command.length());
      if (ret != DEVICE_OK)
	return ret;
      hub->SetBlueBrightness(pos);
   }
   return DEVICE_OK;
}
int XYStage::SetPositionSteps(long x, long y)
{
    if(xy_Available())
    {
        double sx(0), sy(0);
        xy_GetHardwareMotionScale(&sx, &sy);
        double posx = x * sx;
        double posy = y * sy;
        double spd(0);
        GetProperty(PROP_XYSPEED, spd);
        Hub* hub = static_cast<Hub*>(GetParentHub());
        if(hub)
        {
            hub->SetOn();
        }
        _busy = true;
        if(xy_MoveAbsolutely(posx, posy, spd))
        {
            if(hub)
            {
                if(hub->Wait())
                {
                    return DEVICE_OK;
                }
                else
                {
                    xy_Stop();
                    return ERR_XY_TIMEOUT;
                }
            }
            return DEVICE_OK;
        }
        else
        {
            _busy = false;
            return ERR_XY_MOVE;
        }
    }
    return ERR_XY_INVALID;
}
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;
}
int Objectives::OnState(MM::PropertyBase* pProp, MM::ActionType eAct)
{
    if(eAct == MM::AfterSet)
    {
        long pos;
        pProp->Get(pos);

        if(_mag.find(pos) == _mag.end())
        {
            pProp->Set(_curpos);
            return ERR_OBJECTIVE_NOTFOUND;
        }
        Hub* hub = static_cast<Hub*>(GetParentHub());
        if(hub)
        {
            hub->SetOn();
        }
        _busy = true;
        if(obj_SwitchObjective(pos))
        {
            if(hub->Wait())
            {
                _curpos = pos;
                return DEVICE_OK;
            }
            else
            {
                return ERR_OBJECTIVE_TIMEOUT;
            }
        }
        else
        {
            return DEVICE_OK;
        }
    }
    return DEVICE_OK;
}
int Illumination::Initialize()
{
    if(!g_device_connected)
        return DEVICE_NOT_CONNECTED;

    if(_init)
        return DEVICE_OK;

    // Name and description
    CreateProperty(MM::g_Keyword_Name, g_devlist[MoticIllumination][0],
                   MM::String, true);
    CreateProperty(MM::g_Keyword_Description, g_devlist[MoticIllumination][1],
                   MM::String, true);

    if(illumination_Available())
    {
        int v = illumination_GetValue();
        CPropertyAction* act = new CPropertyAction(this, &Illumination::OnIntensity);
        CreateProperty(PROP_ILLUMINATION_INTENSITY, CDeviceUtils::ConvertToString(v), MM::Integer, false, act);
        int l(0), r(0);
        illumination_GetRange(&l, &r);
        SetPropertyLimits(PROP_ILLUMINATION_INTENSITY, l, r);
    }

    Hub* hub = static_cast<Hub*>(GetParentHub());
    if(hub)
    {
        hub->AddEventReceiver(this);
    }

    UpdateStatus();

    _init = true;

    return DEVICE_OK;
}
int CArduinoNeoPixelShutter::OnOnOff(MM::PropertyBase* pProp, MM::ActionType eAct)
{
   CArduinoNeoPixelHub* hub = static_cast<CArduinoNeoPixelHub*>(GetParentHub());
   if (eAct == MM::BeforeGet)
   {
      // use cached state
      pProp->Set((long)hub->GetShutterState());
   }
   else if (eAct == MM::AfterSet)
   {
      long pos;
      pProp->Get(pos);
      int ret;
      std::string command = "I" + boost::lexical_cast<std::string>((long long)hub->GetIntensity());
      ret = hub->WriteToComPortH((const unsigned char*) command.c_str(), command.length());
      if (ret != DEVICE_OK)
	return ret;
      if (pos == 0) {
	std::string command = "P0\r";
	int ret = hub->WriteToComPortH((const unsigned char*) command.c_str(), command.length());
	if (ret != DEVICE_OK)
	  return ret;
      }
      else {
	std::string command = "P111111111111111111111111111111111111111\r";
	int ret = hub->WriteToComPortH((const unsigned char*) command.c_str(), command.length());
	if (ret != DEVICE_OK)
	  return ret;
	int multi = hub->GetMulti();
	LogMessage("multi:");
	if (multi & 0x1) {
	  std::string command = "R" + boost::lexical_cast<std::string>((long long)hub->GetRedBrightness()) + "\r";
	  int ret = hub->WriteToComPortH((const unsigned char*) command.c_str(), command.length());
	  if (ret != DEVICE_OK)
	    return ret;
	} else {
	  std::string command = "R0\r";
	  int ret = hub->WriteToComPortH((const unsigned char*) command.c_str(), command.length());
	  if (ret != DEVICE_OK)
	    return ret;
	}

	if (multi & 0x2) {
	  std::string command = "G" + boost::lexical_cast<std::string>((long long)hub->GetGreenBrightness()) + "\r";
	  int ret = hub->WriteToComPortH((const unsigned char*) command.c_str(), command.length());
	  if (ret != DEVICE_OK)
	    return ret;
	} else {
	  std::string command = "G0\r";
	  int ret = hub->WriteToComPortH((const unsigned char*) command.c_str(), command.length());
	  if (ret != DEVICE_OK)
	    return ret;
	}
	if (multi & 0x4) {
	  std::string command = "B" + boost::lexical_cast<std::string>((long long)hub->GetBlueBrightness()) + "\r";
	  int ret = hub->WriteToComPortH((const unsigned char*) command.c_str(), command.length());
	  if (ret != DEVICE_OK)
	    return ret;
	} else {
	  std::string command = "B0\r";
	  int ret = hub->WriteToComPortH((const unsigned char*) command.c_str(), command.length());
	  if (ret != DEVICE_OK)
	    return ret;
	}
      }
      hub->SetShutterState(pos);
      changedTime_ = GetCurrentMMTime();
   }

   return DEVICE_OK;
}
int CArduinoNeoPixelShutter::Initialize()
{
   CArduinoNeoPixelHub* hub = static_cast<CArduinoNeoPixelHub*>(GetParentHub());
   if (!hub || !hub->IsPortAvailable()) {
      return ERR_NO_PORT_SET;
   }
   char hubLabel[MM::MaxStrLength];
   hub->GetLabel(hubLabel);
   SetParentID(hubLabel); // for backward comp.

   // set property list
   // -----------------
   
   // OnOff
   // ------
   CPropertyAction* pAct = new CPropertyAction (this, &CArduinoNeoPixelShutter::OnOnOff);
   int ret = CreateProperty("OnOff", "1", MM::Integer, false, pAct);
   if (ret != DEVICE_OK)
      return ret;

   pAct = new CPropertyAction (this, &CArduinoNeoPixelShutter::OnIntensity);
   ret = CreateProperty("Intensity", "255", MM::Integer, false, pAct);
   SetPropertyLimits("Intensity", 0, 255);
   if (ret != DEVICE_OK)
      return ret;

   pAct = new CPropertyAction(this, &CArduinoNeoPixelShutter::OnRedBrightness);
   ret = CreateProperty("Red brightness", "255", MM::Integer, false, pAct);
   SetPropertyLimits("Red brightness", 0, 255);
   if (ret != DEVICE_OK)
      return ret;
   pAct = new CPropertyAction(this, &CArduinoNeoPixelShutter::OnGreenBrightness);
   ret = CreateProperty("Green brightness", "255", MM::Integer, false, pAct);
   SetPropertyLimits("Green brightness", 0, 255);
   if (ret != DEVICE_OK)
      return ret;
   pAct = new CPropertyAction(this, &CArduinoNeoPixelShutter::OnBlueBrightness);
   ret = CreateProperty("Blue brightness", "255", MM::Integer, false, pAct);
   SetPropertyLimits("Blue brightness", 0, 255);
   if (ret != DEVICE_OK)
      return ret;
   pAct = new CPropertyAction(this, &CArduinoNeoPixelShutter::OnMulti);
   ret = CreateProperty("Multi", "8", MM::Integer, false, pAct);
   SetPropertyLimits("Multi", 0, 1<<3);
   if (ret != DEVICE_OK)
      return ret;


   // set shutter into the off state
   //WriteToPort(0);
   
   std::vector<std::string> vals;
   vals.push_back("0");
   vals.push_back("1");
   ret = SetAllowedValues("OnOff", vals);
   if (ret != DEVICE_OK)
      return ret;

   ret = UpdateStatus();
   if (ret != DEVICE_OK)
      return ret;

   changedTime_ = GetCurrentMMTime();
   initialized_ = true;

   return DEVICE_OK;
}
Example #19
0
VTiSIMHub* VTiSIMLasers::VTiHub()
{
   return static_cast<VTiSIMHub*>(GetParentHub());
}
Example #20
0
VTiSIMHub* VTiSIMScanner::VTiHub()
{
   return static_cast<VTiSIMHub*>(GetParentHub());
}
Example #21
0
VTiSIMHub* VTiSIMPinholeArray::VTiHub()
{
   return static_cast<VTiSIMHub*>(GetParentHub());
}