Ejemplo n.º 1
0
int FilterWheel::OnState(MM::PropertyBase* pProp, MM::ActionType eAct)
{
   if (eAct == MM::BeforeGet)
   {
      // return pos as we know it
      pProp->Set(pos_);
   }
   else if (eAct == MM::AfterSet)
   {
      long pos;
      int ret;
      pProp->Get(pos);
      // sanity check
      if (pos < 0)
         pos = 0;
      if (pos >= numPos_)
         pos = numPos_ - 1;
      if ((pos == pos_) && (open_ == gateOpen_))
         return DEVICE_OK;
      if (gateOpen_)
         ret = g_hub.SetFilterWheelPosition(*this, *GetCoreCallback(), wheelNr_, pos);
      else
         ret = g_hub.SetFilterWheelPosition(*this, *GetCoreCallback(), wheelNr_, gateClosedPosition_);
      if (ret != DEVICE_OK)
         return ret;

      pos_ = pos;
      open_ = gateOpen_;
      pProp->Set(pos_);
   }
   return DEVICE_OK;
}
Ejemplo n.º 2
0
int Shutter::Initialize()
{
   // Ensure a serial port has been set -- otherwise return an error.
   if (! g_hub.IsConnected())
      return DEVICE_ERR;

  // Name
   int ret = CreateProperty(MM::g_Keyword_Name, name_.c_str(), MM::String, true);
   if (DEVICE_OK != ret)
      return ret;

   // Description
   ret = CreateProperty(MM::g_Keyword_Description, "ASIFW1000 Shutter", MM::String, true);
   if (DEVICE_OK != ret)
      return ret;

  // Set timer for the Busy signal, or we'll get a time-out the first time we check the state of the shutter, for good measure, go back 'delay' time into the past
   changedTime_ = GetCurrentMMTime();   
   
   bool open;
   // Check current state of shutter:
   ret = g_hub.GetShutterPosition(*this, *GetCoreCallback(), shutterNr_, open);
   if (DEVICE_OK != ret)
      return ret;

   // State
   CPropertyAction* pAct = new CPropertyAction (this, &Shutter::OnState);
   if (open)
      ret = CreateProperty(MM::g_Keyword_State, "1", MM::Integer, false, pAct); 
   else
      ret = CreateProperty(MM::g_Keyword_State, "0", MM::Integer, false, pAct); 

   if (ret != DEVICE_OK) 
      return ret; 

   AddAllowedValue(MM::g_Keyword_State, "0"); // Closed
   AddAllowedValue(MM::g_Keyword_State, "1"); // Open

   //Label

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

   initialized_ = true;

   return DEVICE_OK;
}
Ejemplo n.º 3
0
int Shutter::SetOpen(bool open)
{
   changedTime_ = GetCurrentMMTime();
   if (open)
   {
      int ret = g_hub.OpenShutter(*this, *GetCoreCallback(), shutterNr_);
      if (ret != DEVICE_OK)
         return ret;
   } else
   {
      int ret = g_hub.CloseShutter(*this, *GetCoreCallback(), shutterNr_);
      if (ret != DEVICE_OK)
         return ret;
   }
   return DEVICE_OK;
}
Ejemplo n.º 4
0
int Hub::Initialize()
{
   // Ensure a serial port has been set -- otherwise return an error.
   if (! g_hub.IsConnected())
      return DEVICE_ERR;

   // set property list
   // -----------------
   
   // Name
   int ret = CreateProperty(MM::g_Keyword_Name, g_ASIFW1000Hub, MM::String, true);
   if (DEVICE_OK != ret)
      return ret;

   // Description
   ret = CreateProperty(MM::g_Keyword_Description, "ASIFW1000 controller", MM::String, true);
   if (DEVICE_OK != ret)
      return ret;

   // Version
   char version[256];
   ret = g_hub.GetVersion(*this, *GetCoreCallback(), version);
   if (DEVICE_OK != ret)
      return ret;
   ret = CreateProperty("Firmware version", version, MM::String, true);
   if (DEVICE_OK != ret)
      return ret;

   // Set verbose level to 6 to speed stuff up
   ret = g_hub.SetVerboseMode(*this, *GetCoreCallback(), 6);
   if (DEVICE_OK != ret)
      return ret;

   // Enquire about the current wheel, this is mainly to set the variable activeWheel_, private to g_hub.
   int wheelNr;
   ret = g_hub.GetCurrentWheel(*this, *GetCoreCallback(), wheelNr);
   if (DEVICE_OK != ret)
      return ret;

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

   initialized_ = true;
   
   return DEVICE_OK;
}
Ejemplo n.º 5
0
int FilterWheel::OnState(MM::PropertyBase* pProp, MM::ActionType eAct)
{
   if (eAct == MM::BeforeGet)
   {
      // return pos as we know it
      pProp->Set(pos_);
   }
   else if (eAct == MM::AfterSet)
   {
      long pos;
      int ret;
      bool gateOpen;
      GetGateOpen(gateOpen);
      pProp->Get(pos);
      // sanity check
      if (pos < 0)
         pos = 0;
      if (pos >= numPos_)
         pos = numPos_ - 1;
      if ((pos == pos_) && (open_ == gateOpen))
         return DEVICE_OK;

      if (gateOpen)
         ret = g_hub.SetFilterWheelPosition(*this, *GetCoreCallback(), wheelNr_, pos);
      else {
         char closedPos[MM::MaxStrLength];
         GetProperty(MM::g_Keyword_Closed_Position, closedPos);
         int gateClosedPosition = atoi(closedPos);

         ret = g_hub.SetFilterWheelPosition(*this, *GetCoreCallback(), wheelNr_, gateClosedPosition);
      }
      if (ret != DEVICE_OK)
         return ret;

      pos_ = pos;
      open_ = gateOpen;
      pProp->Set(pos_);
   }
   return DEVICE_OK;
}
Ejemplo n.º 6
0
int Shutter::GetOpen(bool &open)
{

   // Check current state of shutter: 
   int ret = g_hub.GetShutterPosition(*this, *GetCoreCallback(), shutterNr_, open);
   if (DEVICE_OK != ret)
      return ret;

   if (shutterType_ == "Normally Closed")
      open = !open;

   return DEVICE_OK;
}
Ejemplo n.º 7
0
/*
 * Sets the Serial Port to be used.
 * Should be called before initialization
 */
int Hub::OnPort(MM::PropertyBase* pProp, MM::ActionType eAct)
{
   if (eAct == MM::BeforeGet)
   {
      pProp->Set(port_.c_str());
   }
   else if (eAct == MM::AfterSet)
   {
      if (initialized_)
      {
         // revert
         pProp->Set(port_.c_str());
         //return ERR_PORT_CHANGE_FORBIDDEN;
      }

      pProp->Get(port_);
      g_hub.SetPort(port_.c_str());
   }
   return DEVICE_OK;
}
Ejemplo n.º 8
0
bool FilterWheel::Busy()
{
   bool busy(false);
   g_hub.FilterWheelBusy(*this, *GetCoreCallback(), busy);
   return busy;
}
Ejemplo n.º 9
0
int FilterWheel::Initialize()
{
   // Ensure a serial port has been set -- otherwise return an error.
   if (! g_hub.IsConnected())
      return DEVICE_ERR;

   // Name
   int ret = CreateProperty(MM::g_Keyword_Name, name_.c_str(), MM::String, true);
   if (DEVICE_OK != ret)
      return ret;

   // Description
   ret = CreateProperty(MM::g_Keyword_Description, "ASIFW1000 FilterWheel", MM::String, true);
   if (DEVICE_OK != ret)
      return ret;

   // State
   CPropertyAction* pAct = new CPropertyAction (this, &FilterWheel::OnState);
   ret = CreateProperty(MM::g_Keyword_State, "0", MM::Integer, false, pAct); 
   if (ret != DEVICE_OK) 
      return ret; 

   // Gate Closed Position
   ret = CreateProperty(MM::g_Keyword_Closed_Position,"", MM::String, false);

   // Get the number of filters in this wheel and add these as allowed values
   ret = g_hub.SetCurrentWheel(*this, *GetCoreCallback(), wheelNr_);
   if (ret != DEVICE_OK)
      return ret;
   ret = g_hub.GetNumberOfPositions(*this, *GetCoreCallback(), wheelNr_, numPos_);
   if (ret != DEVICE_OK) 
      return ret; 
   char pos[3];
   for (int i=0; i<numPos_; i++) 
   {
      sprintf(pos, "%d", i);
      AddAllowedValue(MM::g_Keyword_State, pos);
      AddAllowedValue(MM::g_Keyword_Closed_Position, pos);
   }

   // Get current position
   int tmp;
   ret = g_hub.GetFilterWheelPosition(*this, *GetCoreCallback(), wheelNr_, tmp);
   if (ret != DEVICE_OK)
      return ret;
   pos_ = tmp;

   // Label
   pAct = new CPropertyAction (this, &CStateBase::OnLabel);
   ret = CreateProperty(MM::g_Keyword_Label, "Undefined", MM::String, false, pAct);
   if (ret != DEVICE_OK) 
      return ret;

   // create default positions and labels
   char state[8];
   for (int i=0; i<numPos_; i++) 
   {
      sprintf(state, "State-%d", i);
      SetPositionLabel(i,state);
   }

   GetGateOpen(open_);

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

   initialized_ = true;

   return DEVICE_OK;
}
Ejemplo n.º 10
0
MM::DeviceDetectionStatus Hub::DetectDevice(void)
{
   // all conditions must be satisfied...
   MM::DeviceDetectionStatus result = MM::Misconfigured;
   char answerTO[MM::MaxStrLength];

   try
   {
      std::string portLowerCase = port_;
      for( std::string::iterator its = portLowerCase.begin(); its != portLowerCase.end(); ++its)
      {
         *its = (char)tolower(*its);
      }
      if( 0< portLowerCase.length() &&  0 != portLowerCase.compare("undefined")  && 0 != portLowerCase.compare("unknown") )
      {
         result = MM::CanNotCommunicate;

         // record the default answer time out
         GetCoreCallback()->GetDeviceProperty(port_.c_str(), "AnswerTimeout", answerTO);

         // device specific default communication parameters
         // for ASI FW
         GetCoreCallback()->SetDeviceProperty(port_.c_str(), MM::g_Keyword_Handshaking, "Off");
         GetCoreCallback()->SetDeviceProperty(port_.c_str(), MM::g_Keyword_StopBits, "1");
         GetCoreCallback()->SetDeviceProperty(port_.c_str(), "AnswerTimeout", "500.0");
         GetCoreCallback()->SetDeviceProperty(port_.c_str(), "DelayBetweenCharsMs", "0");
         MM::Device* pS = GetCoreCallback()->GetDevice(this, port_.c_str());

         std::vector< std::string> possibleBauds;
         possibleBauds.push_back("115200");
         possibleBauds.push_back("28800");         
         possibleBauds.push_back("19200");
         possibleBauds.push_back("9600");


         for( std::vector< std::string>::iterator bit = possibleBauds.begin(); bit!= possibleBauds.end(); ++bit )
         {
            GetCoreCallback()->SetDeviceProperty(port_.c_str(), MM::g_Keyword_BaudRate, (*bit).c_str() );
            pS->Initialize();
            PurgeComPort(port_.c_str());
            // Version
            char version[256];
            int ret = g_hub.GetVersion(*this, *GetCoreCallback(), version);
            if( DEVICE_OK != ret )
            {
               LogMessageCode(ret,true);
            }
            else
            {
               // to succeed must reach here....
               result = MM::CanCommunicate;
            }
            pS->Shutdown();
            CDeviceUtils::SleepMs(300);
            if( MM::CanCommunicate == result)
               break;
         }
         // always restore the AnswerTimeout to the default
         GetCoreCallback()->SetDeviceProperty(port_.c_str(), "AnswerTimeout", answerTO);

      }
   }
   catch(...)
   {
      LogMessage("Exception in DetectDevice!",false);
   }
   return result;
}