Esempio n. 1
0
int Stradus::GetOpen(bool& open)
{
   long state;
   std::ostringstream command;
   std::string answer;
   std::vector<std::string> tokens;
   std::string delims="=";

   command << "?le";
   int ret = SendSerialCommand(port_.c_str(), command.str().c_str(), "\r");
   if (ret != DEVICE_OK) return ret;
   CDeviceUtils::SleepMs(50);
   ret = GetSerialAnswer(port_.c_str(), "\r\n", answer);
   ret = GetSerialAnswer(port_.c_str(), "\r\n", answer);
   PurgeComPort(port_.c_str());
   if (ret != DEVICE_OK) return ret;

   Stradus::Tokenize(answer, tokens, delims);
   if ( 2 == tokens.size())
   {
   		answer=tokens.at(1).c_str();
   }

   state=atol(answer.c_str());
   if (state==1)
      open = true;
   else if (state==0)
      open = false;

   return DEVICE_OK;
}
Esempio n. 2
0
//System Faults or Operating Condition
int Stradus::OnFault(MM::PropertyBase* pProp, MM::ActionType eAct)
{
     std::ostringstream command;
     std::string answer;
     std::vector<std::string> tokens;
     std::string delims="=";
     
     if(eAct==MM::BeforeGet)
     {
        command << "?fd";
        int ret = SendSerialCommand(port_.c_str(), command.str().c_str(), "\r");
        if (ret != DEVICE_OK) return ret;
        CDeviceUtils::SleepMs(50);
        ret = GetSerialAnswer(port_.c_str(), "\r\n", answer);
        ret = GetSerialAnswer(port_.c_str(), "\r\n", answer);
        PurgeComPort(port_.c_str());
        if (ret != DEVICE_OK) return ret;

        Stradus::Tokenize(answer, tokens, delims);
        if ( 2 == tokens.size())
        {
		    answer=tokens.at(1).c_str();
        }
        pProp->Set(answer.c_str());
     }
     else
        if(eAct==MM::AfterSet)
        {
            //Read Only, Do Nothing
        }

     return DEVICE_OK;

}
Esempio n. 3
0
int Stradus::LaserOnOff(int onoff)
{
     std::string answer;
     std::ostringstream command;

     if (onoff == 0)
     {
          command << "le=0";
          laserOn_ = "OFF";
     }
     else if (onoff == 1)
     {
          command << "le=1";
          laserOn_ = "ON";
     }
     int ret = SendSerialCommand(port_.c_str(), command.str().c_str(), "\r");
     if (ret != DEVICE_OK) return ret;
     CDeviceUtils::SleepMs(100);
     ret = GetSerialAnswer(port_.c_str(), "\r\n", answer);
     ret = GetSerialAnswer(port_.c_str(), "\r\n", answer);
     PurgeComPort(port_.c_str());
     if (ret != DEVICE_OK) return ret;

	 return DEVICE_OK;
}
Esempio n. 4
0
//Peak Power Set/Get (Digital Modulation Only)
int Stradus::OnPulPwr(MM::PropertyBase* pProp, MM::ActionType eAct)
{
     std::string answer;
     std::ostringstream command;

     if (eAct == MM::BeforeGet)
     {
          command << "?pp";
          int ret = SendSerialCommand(port_.c_str(), command.str().c_str(), "\r");
          if (ret != DEVICE_OK) return ret;
          CDeviceUtils::SleepMs(50);
          ret = GetSerialAnswer(port_.c_str(), "\r\n", answer);
          ret = GetSerialAnswer(port_.c_str(), "\r\n", answer);
          PurgeComPort(port_.c_str());
          if (ret != DEVICE_OK) return ret;

          std::vector<std::string> tokens;
          std::string delims="=";

          Stradus::Tokenize(answer, tokens, delims);

          if ( 2 == tokens.size())
		  {
			   answer=tokens.at(1).c_str();
		  }

          pProp->Set(answer.c_str());
     }
     else if (eAct == MM::AfterSet)
     {
          pProp->Get((long&)pulPwr_);
          command << "pp=" << pulPwr_;
          int ret = SendSerialCommand(port_.c_str(), command.str().c_str(), "\r");
          if (ret != DEVICE_OK) return ret;
          CDeviceUtils::SleepMs(1000);
          ret = GetSerialAnswer(port_.c_str(), "\r\n", answer);
          ret = GetSerialAnswer(port_.c_str(), "\r\n", answer);
          PurgeComPort(port_.c_str());
          if (ret != DEVICE_OK) return ret;
     }

   return DEVICE_OK;
}
Esempio n. 5
0
//External Power Control
int Stradus::OnEPC(MM::PropertyBase* pProp, MM::ActionType eAct)
{
    std::ostringstream command;
    std::string answer;

    if (eAct == MM::BeforeGet)
     {
          command << "?epc";
          int ret = SendSerialCommand(port_.c_str(), command.str().c_str(), "\r");
          if (ret != DEVICE_OK) return ret;
          CDeviceUtils::SleepMs(50);
          ret = GetSerialAnswer(port_.c_str(), "\r\n", answer);
          ret = GetSerialAnswer(port_.c_str(), "\r\n", answer);
          PurgeComPort(port_.c_str());
          if (ret != DEVICE_OK) return ret;

          std::vector<std::string> tokens;
          std::string delims="=";

          Stradus::Tokenize(answer, tokens, delims);

          if ( 2 == tokens.size())
		  {
			   answer=tokens.at(1).c_str();
		  }

	      if (answer == "0")
               epc_ = "OFF";
          else if (answer == "1")
               epc_ = "ON";

          pProp->Set(epc_.c_str());
     }
     else
          if (eAct == MM::AfterSet)
          {
            pProp->Get(answer);
            if (answer == "OFF")
            {
               epcOnOff(false); //Turn EPC off
            }
            else
                if(answer=="ON")
                {
                    epcOnOff(true); //Turn EPC on
                }
          }


     return DEVICE_OK;
}
Esempio n. 6
0
int Xcite120PC::ExecuteCommand( const std::string& cmd, char* input, int inputLen, std::string* ret)
// Exedute a command, input, inputlen and ret are 0 by default
// if a pointer to input and a value for inputlen is given, this input is sent to the device
// if a pointer to ret is given, the return value of the device it returned in ret
{
  char* cmd_i;
  
  if (input==NULL) // no input
  {
    cmd_i = new char[cmd.size()+1];
    strcpy(cmd_i,cmd.c_str());
  }
  else  // command with input
  {
    cmd_i = new char[cmd.size() + inputLen + 1];
    strcpy( cmd_i, cmd.c_str() );
    strncat( cmd_i, input, inputLen );
  }
  
  // clear comport
  int s = PurgeComPort( port_.c_str() );
  if (s!=DEVICE_OK)
    return s;

  // send command
  s = SendSerialCommand( port_.c_str(), cmd_i, "\r" );
  if (s!=DEVICE_OK)
    return s;

  delete [] cmd_i;

  // get status
  std::string buff;
  s = GetSerialAnswer( port_.c_str(), "\r", buff );
  if (s!=DEVICE_OK)
    return s;
  if (!buff.compare(g_XciteRetERR))
    return DEVICE_ERR;
  if (buff.compare(g_XciteRetOK) && ret==NULL)
    return DEVICE_NOT_CONNECTED;

  if (ret!=NULL) // read return value
  {
    *ret = buff;
  }
  return DEVICE_OK;
}
Esempio n. 7
0
//Digital Modulation On/Off
int Stradus::OnDigMod(MM::PropertyBase* pProp, MM::ActionType eAct)
{
    std::ostringstream command;
    std::string answer;

    if (eAct == MM::BeforeGet)
    {
          command << "?pul";
          int ret = SendSerialCommand(port_.c_str(), command.str().c_str(), "\r");
          if (ret != DEVICE_OK) return ret;
          CDeviceUtils::SleepMs(50);
          ret = GetSerialAnswer(port_.c_str(), "\r\n", answer);
          ret = GetSerialAnswer(port_.c_str(), "\r\n", answer);
          PurgeComPort(port_.c_str());
          if (ret != DEVICE_OK) return ret;


	      if (answer == "?PUL=0")
               digMod_ = "OFF";
          else if (answer == "?PUL=1")
               digMod_ = "ON";
          pProp->Set(digMod_.c_str());
     }
     else
     {
        if (eAct == MM::AfterSet)
        {
          pProp->Get(answer);
          if (answer == "OFF")
          {
               digModOnOff(false); //Turn laser off
          }
          else
            if(answer == "ON")
            {
               digModOnOff(true); //Turn laser on
            }
        }
     }
     return DEVICE_OK;
}
int CArduinoNeoPixelHub::Initialize()
{
   // Name
   int ret = CreateProperty(MM::g_Keyword_Name, g_DeviceNameArduinoNeoPixelHub, MM::String, true);
   if (DEVICE_OK != ret)
      return ret;

   // The first second or so after opening the serial port, the Arduino is waiting for firmwareupgrades.  Simply sleep 1 second.
   CDeviceUtils::SleepMs(2000);

   MMThreadGuard myLock(lock_);

   // Check that we have a controller:
   PurgeComPort(port_.c_str());
   ret = GetControllerVersion(version_);
   if( DEVICE_OK != ret)
      return ret;

   // if (version_ < g_Min_MMVersion || version_ > g_Max_MMVersion)
   //    return ERR_VERSION_MISMATCH;

   CPropertyAction* pAct = new CPropertyAction(this, &CArduinoNeoPixelHub::OnVersion);
   std::ostringstream sversion;
   sversion << version_;
   CreateProperty(g_versionProp, sversion.str().c_str(), MM::Integer, true, pAct);

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

   // turn on verbose serial debug messages
   GetCoreCallback()->SetDeviceProperty(port_.c_str(), "Verbose", "1");

   initialized_ = true;
   return DEVICE_OK;
}
Esempio n. 9
0
/**
 * This function not only sends the command but also reads back an answer from teh device
 * Note that the SC10 echoes the command.  We strip the echo here from the answer 
 * in order to facilitate downstream parsing
 */
int SC10::ExecuteCommand(const std::string& cmd, std::string& answer)
{
   // send command
   PurgeComPort(port_.c_str());
   if (DEVICE_OK != SendSerialCommand(port_.c_str(), cmd.c_str(), "\r"))
      return DEVICE_SERIAL_COMMAND_FAILED;

   // Get answer from the device.  It will always end with a new prompt
   int ret = GetSerialAnswer(port_.c_str(), ">", answer);
   if (ret != DEVICE_OK)
      return ret;

   // Check if the command was echoed and strip it out
   if (answer.compare(0, cmd.length(), cmd) == 0) {
      answer = answer.substr(cmd.length() + 1);
   // I really don't understand this, but on the Mac I get a space as the first character
   // This could be a problem in the serial adapter!
   } else if (answer.compare(1, cmd.length(), cmd) == 0) {
      answer = answer.substr(cmd.length() + 2);
   } else
      return DEVICE_SERIAL_COMMAND_FAILED;

   return DEVICE_OK;
}
Esempio n. 10
0
void Sapphire::Purge()
{
   int ret = PurgeComPort(port_.c_str());
   if (ret!=0)
      error_ = DEVICE_SERIAL_COMMAND_FAILED;
}
MM::DeviceDetectionStatus CArduinoNeoPixelHub::DetectDevice(void)
{
   if (initialized_)
      return MM::CanCommunicate;

   // 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 Arduino Duemilanova
         GetCoreCallback()->SetDeviceProperty(port_.c_str(), MM::g_Keyword_Handshaking, "Off");
         GetCoreCallback()->SetDeviceProperty(port_.c_str(), MM::g_Keyword_BaudRate, "9600" );
         GetCoreCallback()->SetDeviceProperty(port_.c_str(), MM::g_Keyword_StopBits, "1");
         // Arduino timed out in GetControllerVersion even if AnswerTimeout  = 300 ms
         GetCoreCallback()->SetDeviceProperty(port_.c_str(), "AnswerTimeout", "1000.0");
         GetCoreCallback()->SetDeviceProperty(port_.c_str(), "DelayBetweenCharsMs", "0");
         MM::Device* pS = GetCoreCallback()->GetDevice(this, port_.c_str());
         pS->Initialize();
         // The first second or so after opening the serial port, the Arduino is waiting for firmwareupgrades.  Simply sleep 2 seconds.
         CDeviceUtils::SleepMs(2000);
         MMThreadGuard myLock(lock_);
         PurgeComPort(port_.c_str());
         int v = 0;
         int ret = GetControllerVersion(v);
         // later, Initialize will explicitly check the version #
         if( DEVICE_OK != ret )
         {
            LogMessageCode(ret,true);
         }
         else
         {
            // to succeed must reach here....
            result = MM::CanCommunicate;
         }
         pS->Shutdown();
         // always restore the AnswerTimeout to the default
         GetCoreCallback()->SetDeviceProperty(port_.c_str(), "AnswerTimeout", answerTO);

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

   return result;
}