当前位置: 首页>>代码示例>>C++>>正文


C++ Core::GetSerialAnswer方法代码示例

本文整理汇总了C++中mm::Core::GetSerialAnswer方法的典型用法代码示例。如果您正苦于以下问题:C++ Core::GetSerialAnswer方法的具体用法?C++ Core::GetSerialAnswer怎么用?C++ Core::GetSerialAnswer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mm::Core的用法示例。


在下文中一共展示了Core::GetSerialAnswer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ExecuteCommand

/*
 * 1 = open
 * 0 = close
 */
int ASIFW1000Hub::GetShutterPosition(MM::Device& device, MM::Core& core, int shutterNr, bool& pos)
{
   //ClearAllRcvBuf(device, core);
   ostringstream os;
   os << "SQ " << shutterNr;
   int ret = ExecuteCommand(device, core, os.str().c_str());
   // analyze answer
   ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\n\r");
   if (ret != DEVICE_OK)
      return ret;
   string response = rcvBuf_;

   // If the answer is too short, there is likely no shutter card (we could do a better check)
   if (response.length() < 2)
   {
      return ERR_SHUTTER_NOT_FOUND;
   }

   int x = atoi(response.substr(response.length() - 2).c_str());
   // sometimes, the controller does not answer, but sends 0. ask once more
   if (x < 16)
   {
      ret = ExecuteCommand(device, core, os.str().c_str());
      ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\n\r");
      response = rcvBuf_;
      x = atoi(response.substr(response.length() - 2).c_str());
   }
   if (shutterNr==1)
      x = x >> 1;

   pos = x & 1;

   return DEVICE_OK;
}
开发者ID:jefferis,项目名称:micromanager12extras,代码行数:38,代码来源:ASIFW1000Hub.cpp

示例2: SetCurrentWheel

int ASIFW1000Hub::SetFilterWheelPosition(MM::Device& device, MM::Core& core, int wheelNr, int pos)
{
   if (wheelNr != activeWheel_)
      // TODO: error checking
      SetCurrentWheel(device, core, wheelNr);

   const char* command = "MP ";
   ostringstream os;
   os << command <<  pos;

   // send command
   int ret = ExecuteCommand(device, core, os.str().c_str());
   if (ret != DEVICE_OK)
      return ret;

   // devices echos command and returns position
   ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\n\r");
   if (ret != DEVICE_OK)
      return ret;

   int posread = rcvBuf_[strlen(rcvBuf_)-1] - '0';
   if ( pos != posread)
      return ERR_SETTING_WHEEL;

   return DEVICE_OK;
}
开发者ID:jefferis,项目名称:micromanager12extras,代码行数:26,代码来源:ASIFW1000Hub.cpp

示例3: sprintf

/*
 * The Spectral LMM5 has a silly difference between USB and serial communication:
 * Commands can be sent straight to USB.  Commands to the serial port need to converted in some kind of weird ASCI:  The command "0x1A0xFF0x000x12<CR>" becomes "1AFF0012<CR>".  Presumably, the same weird conversion takes place on the way back.  We handle this translation in this function
 */
int SpectralLMM5Interface::ExecuteCommand(MM::Device& device, MM::Core& core, unsigned char* buf, unsigned long bufLen, unsigned char* answer, unsigned long answerLen, unsigned long& read) 
{
   int ret;
   if (portType_ == MM::SerialPort) 
   {
      std::string serialCommand;
      char tmp[3];
      tmp[2] = 0;
      for (unsigned long i=0; i<bufLen; i++) {
         sprintf(tmp, "%.2x", buf[i]);
         serialCommand += tmp;
      }
      ret = core.SetSerialCommand(&device, port_.c_str(), serialCommand.c_str(), "\r");
   } else  // check for USB port
   {
      ret = core.WriteToSerial(&device, port_.c_str(), buf, bufLen);
   }

   if (ret != DEVICE_OK)  
      return ret;
  
   if (portType_ == MM::SerialPort) 
   {
      char strAnswer[128];
      read = 0;
      ret = core.GetSerialAnswer(&device, port_.c_str(), 128, strAnswer, "\r");
      if (ret != DEVICE_OK)
         return ret;
      
      std::ostringstream os;
      os << "LMM5 answered: " << strAnswer << " Port status: " << ret;
      core.LogMessage(&device, os.str().c_str(), true);
   
      // 'translate' back into numbers:
      std::string tmp = strAnswer;
      for (unsigned int i=0; i < tmp.length()/2; i++) {
         char * end;
         long j = strtol(tmp.substr(i*2,2).c_str(), &end, 16);
         answer[i] = (unsigned char) j;
         read++;
      }
   } else if (portType_ == MM::HIDPort) 
   {
      // The USB port will attempt to read up to answerLen characters
      ret = core.ReadFromSerial(&device, port_.c_str(), answer, answerLen, read);
      if (ret != DEVICE_OK)
         return ret;

      /* 
       // Uncomment for debugging (although port should give the same info)
      std::ostringstream os;
      os << "LMM5 answered: " << std::hex << std::setfill('0');
      for (unsigned int i=0; i < read; i++)
         os << std::setw(2) << (unsigned int) answer[i] << " ";
      core.LogMessage(&device, os.str().c_str(), true);
      */
   }
   return DEVICE_OK;
}
开发者ID:coronin,项目名称:micromanager-upstream,代码行数:63,代码来源:SpectralLMM5Interface.cpp

示例4: sprintf

/*
 * The Spectral LMM5 has a silly difference between USB and serial communication:
 * Commands can be sent straight to USB.  Commands to the serial port need to converted in some kind of weird ASCI:  The command "0x1A0xFF0x000x12<CR>" becomes "1AFF0012<CR>".  Presumably, the same weird conversion takes place on the way back.  We handle this translation in this function
 */
int SpectralLMM5Interface::ExecuteCommand(MM::Device& device, MM::Core& core, unsigned char* buf, unsigned long bufLen, unsigned char* answer, unsigned long answerLen, unsigned long& read) 
{
   int ret;
   if (portType_ == MM::SerialPort) 
   {
      std::string serialCommand;
      char tmp[3];
      tmp[2] = 0;
      for (unsigned long i=0; i<bufLen; i++) {
         sprintf(tmp, "%.2x", buf[i]);
         serialCommand += tmp;
      }
      ret = core.SetSerialCommand(&device, port_.c_str(), serialCommand.c_str(), "\r");
   } else  // check for USB port
   {
      unsigned char c[2];
      c[0]=0x01;
      c[1]=0x02;
      ret = core.WriteToSerial(&device, port_.c_str(), c, 2);
      //ret = core.WriteToSerial(&device, port_.c_str(), buf, bufLen);
   }

   if (ret != DEVICE_OK)  
      return ret;
  
   if (portType_ == MM::SerialPort) 
   {
      char strAnswer[128];
      read = 0;
      ret = core.GetSerialAnswer(&device, port_.c_str(), 128, strAnswer, "\r");
      if (ret != DEVICE_OK)
         return ret;
      std::ostringstream os;
      os << "LMM5 answered: " << strAnswer << " Port status: " << ret;
      core.LogMessage(&device, os.str().c_str(), true);
      // 'translate' back into numbers:
      std::string tmp = strAnswer;
      for (unsigned int i=0; i < tmp.length()/2; i++) {
         char * end;
         long j = strtol(tmp.substr(i*2,2).c_str(), &end, 16);
         answer[i] = (unsigned char) j;
         // printf("c:%x i:%u j:%ld\n", answer[i], i, j);
         read++;
      }
   } else // TODO: check that we have a USB port
   {
      // The USB port will attempt to read up to answerLen characters
      ret = core.ReadFromSerial(&device, port_.c_str(), answer, answerLen, read);
      if (ret != DEVICE_OK)
         return ret;
      std::ostringstream os;
      os << "LMM5 answered: ";
      for (unsigned int i=0; i < read; i++)
         os << std::hex << answer[i];
      os << std::endl;
      core.LogMessage(&device, os.str().c_str(), true);
   }
   return DEVICE_OK;
}
开发者ID:astraw,项目名称:micromanager1.3,代码行数:63,代码来源:SpectralLMM5Interface.cpp

示例5: GetAcknowledgment

/*
 * An 'A' acknowledges receipt of a command, ('N' means it is not understood)
 * Function is not really appropriately named
 */
int CSUXHub::GetAcknowledgment(MM::Device& device, MM::Core& core)
{
   // block until we get a response
   int ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
   if (ret != DEVICE_OK)
       return ret;
   return Acknowledge();
}
开发者ID:coronin,项目名称:micromanager-upstream,代码行数:12,代码来源:CSUXHub.cpp

示例6: ClearAllRcvBuf

/* 
 * Queries CSU for current NIR Shutter
 */
int CSUW1Hub::GetNIRShutterPosition(MM::Device& device, MM::Core& core, bool& open)
{
   ClearAllRcvBuf(device, core);
   int ret = ExecuteCommand(device, core, "SH2, ?");
   // analyze what comes back:
   ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
   if (ret != DEVICE_OK)
      return ret;
   open = (strstr(rcvBuf_, "OPEN") != 0);
   return DEVICE_OK;
}
开发者ID:csachs,项目名称:micro-manager,代码行数:14,代码来源:CSUW1Hub.cpp

示例7: GetPrismSliderPosition

int CARVIIHub::GetPrismSliderPosition(MM::Device& device, MM::Core& core, int pos) {
    ClearAllRcvBuf(device, core);
    int ret = ExecuteCommand(device, core, "rP");
    ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
    if (ret != DEVICE_OK)
        return ret;

    // CARVII echoes command, motor state is in bit 3
    pos = rcvBuf_[2];

    return DEVICE_OK;
}
开发者ID:ckc7,项目名称:micromanager2,代码行数:12,代码来源:CARVIIHub.cpp

示例8: GetShutterPosition

int CARVIIHub::GetShutterPosition(MM::Device& device, MM::Core& core, int pos) {
    ClearAllRcvBuf(device, core);
    int ret = ExecuteCommand(device, core, "rS");
    // analyze what comes back:
    ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
    if (ret != DEVICE_OK)
        return ret;
    //CARVII echoes command, shutter position is in bit 3
    pos = rcvBuf_[2];

    return DEVICE_OK;
}
开发者ID:ckc7,项目名称:micromanager2,代码行数:12,代码来源:CARVIIHub.cpp

示例9: GetTouchScreenState

int CARVIIHub::GetTouchScreenState(MM::Device& device, MM::Core& core, int state) {
    ClearAllRcvBuf(device, core);
    int ret = ExecuteCommand(device, core, "rM");
    ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
    if (ret != DEVICE_OK)
        return ret;

    // CARVII echoes command, motor state is in bit 3
    state = rcvBuf_[2];

    return DEVICE_OK;
}
开发者ID:ckc7,项目名称:micromanager2,代码行数:12,代码来源:CARVIIHub.cpp

示例10: ClearAllRcvBuf

/*
 * TODO: improve error reporting
 */
int CSU22Hub::GetDriveSpeedPosition(MM::Device& device, MM::Core& core, int& pos)
{
   ClearAllRcvBuf(device, core);
   int ret = ExecuteCommand(device, core, "rsm");
   // analyze what comes back:
   ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
   if (ret != DEVICE_OK)
      return ret;
   int speed = atoi(rcvBuf_);
   pos = speed;
   return DEVICE_OK;
}
开发者ID:astraw,项目名称:micromanager1.3,代码行数:15,代码来源:CSU22Hub.cpp

示例11:

/*
 * An 'A' acknowledges receipt of a command, ('N' means it is not understood)
 * Function is not really appropriately named
 */
int CSU22Hub::GetAcknowledgment(MM::Device& device, MM::Core& core)
{
   // block until we get a response
   int ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
   if (ret != DEVICE_OK)
       return ret;
   if (rcvBuf_[1]=='N')
      return 1;
   if (rcvBuf_[1]!='A')
      return DEVICE_SERIAL_INVALID_RESPONSE;

   return DEVICE_OK;
}
开发者ID:astraw,项目名称:micromanager1.3,代码行数:17,代码来源:CSU22Hub.cpp

示例12: GetDichroicPosition

int CSUXHub::GetDichroicPosition(MM::Device& device, MM::Core& core, long &dichroic)
{
   ClearAllRcvBuf(device, core);
   int ret = ExecuteCommand(device, core, "DM_POS, ?");
   ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
   if (ret != DEVICE_OK)
      return ret;
   ret = Acknowledge();
   if (ret != DEVICE_OK)
      return ret;
   dichroic = atol(rcvBuf_);

   return DEVICE_OK;
}
开发者ID:coronin,项目名称:micromanager-upstream,代码行数:14,代码来源:CSUXHub.cpp

示例13: GetShutterPosition

/*
 * 1 = closed
 * 0 = open
 */
int CSUXHub::GetShutterPosition(MM::Device& device, MM::Core& core, int& pos)
{
   ClearAllRcvBuf(device, core);
   int ret = ExecuteCommand(device, core, "SH, ?");
   // analyze what comes back:
   ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
   if (ret != DEVICE_OK)
      return ret;
   if (strstr(rcvBuf_, "CLOSE") != 0)
      pos = 1;
   pos = 0;

   return DEVICE_OK;
}
开发者ID:coronin,项目名称:micromanager-upstream,代码行数:18,代码来源:CSUXHub.cpp

示例14: GetMaxDriveSpeed

/*
 * Reports the maximum drive speed available from this model
 */
int CSUXHub::GetMaxDriveSpeed(MM::Device& device, MM::Core& core, long& maxSpeed)
{
   ClearAllRcvBuf(device, core);
   int ret = ExecuteCommand(device, core, "MS_MAX, ?");
   // analyze what comes back:
   ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
   if (ret != DEVICE_OK)
      return ret;
   ret = Acknowledge();
   if (ret != DEVICE_OK)
      return ret;

   maxSpeed = atol(rcvBuf_);
   return DEVICE_OK;
}
开发者ID:coronin,项目名称:micromanager-upstream,代码行数:18,代码来源:CSUXHub.cpp

示例15: GetFilterWheelSpeed

/*
 * Gets speed of filter wheel (0-3)
 */
int CSUXHub::GetFilterWheelSpeed(MM::Device& device, MM::Core& core, long wheelNr, long& speed)
{
   ClearAllRcvBuf(device, core);
   ostringstream os;
   os << "FW_SPEED, " << wheelNr  << ", ?";
   int ret = ExecuteCommand(device, core, os.str().c_str());
   ret = core.GetSerialAnswer(&device, port_.c_str(), RCV_BUF_LENGTH, rcvBuf_, "\r");
   if (ret != DEVICE_OK)
      return ret;
   ret = Acknowledge();
   if (ret != DEVICE_OK)
      return ret;
   speed = atol(rcvBuf_);
   return DEVICE_OK;
}
开发者ID:coronin,项目名称:micromanager-upstream,代码行数:18,代码来源:CSUXHub.cpp


注:本文中的mm::Core::GetSerialAnswer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。