Exemplo n.º 1
0
//Moves stage to given absolute z coordinate
int ZStage::SetPositionSteps(long pos)
{
   int ret = ClearPort(*this, *GetCoreCallback(), port_);
   if (ret != DEVICE_OK)
      return ret;

   std::ostringstream command;
   command << "absz " << pos;

   ret = SendSerialCommand(port_.c_str(), command.str().c_str(), "\r");
   if (ret != DEVICE_OK)
      return ret;

   std::string answer;
   ret = GetSerialAnswer(port_.c_str(), "\r", answer);
   if (ret != DEVICE_OK)
      return ret;

   if (answer.substr(0,1).compare("A") == 0)
   {
      curSteps_ = pos;
      return DEVICE_OK;
   }

   return ERR_UNRECOGNIZED_ANSWER;   
}
Exemplo n.º 2
0
//Reports coordinate the stage is at
int ZStage::GetPositionSteps(long& steps)
{
   int ret = ClearPort(*this, *GetCoreCallback(), port_);
   if (ret != DEVICE_OK)
      return ret;

   const char* command="PZ";

   ret = SendSerialCommand(port_.c_str(), command, "\r");
   if (ret != DEVICE_OK)
      return ret;

   std::string answer;
   ret = GetSerialAnswer(port_.c_str(), "\r", answer);
   if (ret != DEVICE_OK)
   {
      return ret;
   }

   if (answer.length() > 2 && answer.substr(0, 1).compare("E") == 0)
   {
      int errNo = atoi(answer.substr(2).c_str());
      return ERR_OFFSET + errNo;
   }
   else if (answer.length() > 0)
   {
      steps = atol(answer.c_str());
      curSteps_ = steps;
      return DEVICE_OK;
   }

   return ERR_UNRECOGNIZED_ANSWER;
}
Exemplo n.º 3
0
// XYStage utility functions
int XYStage::GetPositionStepsSingle(char axis, long& steps)
{
   int ret = ClearPort(*this, *GetCoreCallback(), port_);
   if (ret != DEVICE_OK)
      return ret;

   std::stringstream command;
   command << "P" << axis;

   ret = SendSerialCommand(port_.c_str(), command.str().c_str(), "\r");
   if (ret != DEVICE_OK)
      return ret;

   std::string answer;
   ret = GetSerialAnswer(port_.c_str(), "\r", answer);
   if (ret != DEVICE_OK)
   {
      return ret;
   }

   if (answer.length() > 0)
   {
      steps = atol(answer.c_str());
      return DEVICE_OK;
   }

   return ERR_UNRECOGNIZED_ANSWER;
}
Exemplo n.º 4
0
// Checks if stage is busy, returns true if the stage is curently moving false otherwise
// This is effected by XYStage movement
bool ZStage::Busy()
{
   int ret = ClearPort(*this, *GetCoreCallback(), port_);
   if (ret != DEVICE_OK)
      return false; 

   const char* command = "s";

   ret = SendSerialCommand(port_.c_str(), command, "\r");
   if (ret != DEVICE_OK)
      return false;

   std::string answer="";
   ret = GetSerialAnswer(port_.c_str(), "\r", answer);
   if (ret != DEVICE_OK)
      return false;
   
   if (answer.length() >=1)
   {
      int status = atoi(answer.substr(0,1).c_str());
      if (status==0) 
         return false;
      else 
         return true;
   }

   return false;
}
Exemplo n.º 5
0
//Moves stage relative to current position by given number of steps
int XYStage::SetRelativePositionSteps(long x, long y)
{
   MMThreadGuard guard(lock_);

   int ret = ClearPort(*this, *GetCoreCallback(), port_);
   if (ret != DEVICE_OK)
      return ret;

   std::ostringstream command;
   command << "rel " << x << " " << y;

   ret = SendSerialCommand(port_.c_str(), command.str().c_str(), "\r");
   if (ret != DEVICE_OK)
      return ret;

   std::string answer;
   ret = GetSerialAnswer(port_.c_str(), "\r", answer);
   if (ret != DEVICE_OK)
      return ret;

   if (answer.substr(0,1).compare("A") == 0)
   {
      return DEVICE_OK;
   }
   return ERR_UNRECOGNIZED_ANSWER;   
}
Exemplo n.º 6
0
int ZStage::SetPositionSteps(long pos)
{
   // First Clear serial port from previous stuff
   int ret = ClearPort(*this, *GetCoreCallback(), port_);
   if (ret != DEVICE_OK)
      return ret;

   long delta = pos - curSteps_;

   // LIN 01-03-2012 ADDED C COMMAND BELOW. H128 USES C TO SET # STEPS THEN DOES U OR D WITHOUT ARGUMENTS
   std::ostringstream command;
   if (delta >= 0)
      command << "C," << delta; 
   else
      command << "C," << -delta;

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

   // block/wait for acknowledge, or until we time out;
   std::string answer;
   ret = GetSerialAnswer(port_.c_str(), "\r", answer);
   if (ret != DEVICE_OK)
      return ret;

   if (answer.substr(0, 1).compare("E") == 0 && answer.length() > 2) // LIN 01-03-2012 note I don't think the H128 reports E## errors but we can leave this in
   {
      int errNo = atoi(answer.substr(2).c_str()); // LIN 01-03-2012 note here the error number is extracted, atol converts string to short integer
      return ERR_OFFSET + errNo;
   }

   // LIN 01-03-2012 DIRECTLY SEND "U" OR "D" AS APPROPRIATE
   if (delta >= 0)
      ret = SendSerialCommand(port_.c_str(), "U", "\r");
   else
      ret = SendSerialCommand(port_.c_str(), "D", "\r");

   if (ret != DEVICE_OK)
      return ret;

   // block/wait for acknowledge, or until we time out;
   ret = GetSerialAnswer(port_.c_str(), "\r", answer);
   if (ret != DEVICE_OK)
      return ret;

   if (answer.substr(0,1).compare("R") == 0)
   {
      curSteps_ = pos;
      return DEVICE_OK;
   }
   else if (answer.substr(0, 1).compare("E") == 0 && answer.length() > 2) // LIN 01-03-2012 note I don't think the H128 reports E## errors but we can leave this in
   {
      int errNo = atoi(answer.substr(2).c_str()); // LIN 01-03-2012 note here the error number is extracted, atol converts string to short integer
      return ERR_OFFSET + errNo;
   }

   return ERR_UNRECOGNIZED_ANSWER;   
}
Exemplo n.º 7
0
/**
 * Gets and sets the Acceleration of the Prior stage travels
 */
int XYStage::OnAcceleration(MM::PropertyBase* pProp, MM::ActionType eAct) 
{
   int ret = ClearPort(*this, *GetCoreCallback(), port_);
   if (ret != DEVICE_OK)
      return ret;

   if (eAct == MM::BeforeGet) 
   {
      // send command
     ret = SendSerialCommand(port_.c_str(), "SRX", "\r"); // LIN 01-01-2012 H128 USES SRX INSTEAD OF SAS
      if (ret != DEVICE_OK)
         return ret;

      // block/wait for acknowledge, or until we time out;
      std::string answer;
      ret = GetSerialAnswer(port_.c_str(), "\r", answer);
      if (ret != DEVICE_OK)
         return ret;

      int acceleration = atoi(answer.c_str());
      if (acceleration < 1 || acceleration > 100) // LIN 01-01-2012 H128 ACCELERATION VALUE MAX 100 NOT 150
         return  ERR_UNRECOGNIZED_ANSWER;

      pProp->Set((long)acceleration);

   } 
   else if (eAct == MM::AfterSet) 
   {
      long acceleration;
      pProp->Get(acceleration);

      std::ostringstream os;
      os << "SRX," <<  acceleration; // LIN 01-01-2012 H128 USES SRX,acceleration INSTEAD OF SAS,acceleration

      // send command
      ret = SendSerialCommand(port_.c_str(), os.str().c_str(), "\r");
      if (ret != DEVICE_OK)
         return ret;

      // block/wait for acknowledge, or until we time out;
      std::string answer;
      ret = GetSerialAnswer(port_.c_str(), "\r", answer);
      if (ret != DEVICE_OK)
         return ret;

      if (answer.substr(0,1).compare("0") == 0)
      {
         return DEVICE_OK; // LIN 01-03-2012 note "0" is the correct response from H128
      }
      else if (answer.substr(0, 1).compare("E") == 0 && answer.length() > 2) // LIN 01-03-2012 note I don't think the H128 reports E## errors but we can leave this in
      {
         int errNo = atoi(answer.substr(2).c_str()); // LIN 01-03-2012 note here the error number is extracted, atol converts string to short integer
         return ERR_OFFSET + errNo;
      }
      return ERR_UNRECOGNIZED_ANSWER;

   }

   return DEVICE_OK;
}
Exemplo n.º 8
0
int XYStage::SetOrigin()
// LIN 01-01-2012 H128 USES Z INSTEAD OF PS TO SET ORIGIN AND IT DOES IT FOR ALL 3 AXES
{
   MMThreadGuard guard(lock_);

   // First Clear serial port from previous stuff
   int ret = ClearPort(*this, *GetCoreCallback(), port_);
   if (ret != DEVICE_OK)
      return ret;

   // send command
   ret = SendSerialCommand(port_.c_str(), "Z", "\r"); // LIN 01-01-2012 CHANGED COMMAND FOR ORIGIN FROM PS TO Z
   if (ret != DEVICE_OK)
      return ret;

   // block/wait for acknowledge, or until we time out;
   std::string answer;
   ret = GetSerialAnswer(port_.c_str(), "\r", answer);
   if (ret != DEVICE_OK)
      return ret;

   if (answer.substr(0,1).compare("0") == 0)
   {
      return DEVICE_OK; // LIN 01-03-2012 note "0" is the correct response from H128
   }
   else if (answer.substr(0, 1).compare("E") == 0 && answer.length() > 2) // LIN 01-03-2012 note I don't think the H128 reports E## errors but we can leave this in
   {
      int errNo = atoi(answer.substr(2).c_str()); // LIN 01-03-2012 note here the error number is extracted, atol converts string to short integer
      return ERR_OFFSET + errNo;
   }

   return ERR_UNRECOGNIZED_ANSWER; 
}
Exemplo n.º 9
0
int XYStage::SetPositionSteps(long x, long y)
{
   MMThreadGuard guard(lock_);

   // First Clear serial port from previous stuff
   int ret = ClearPort(*this, *GetCoreCallback(), port_);
   if (ret != DEVICE_OK)
      return ret;

   std::ostringstream command;
   command << "G," << x << "," << y;

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

   // block/wait for acknowledge, or until we time out;
   std::string answer;
   ret = GetSerialAnswer(port_.c_str(), "\r", answer);
   if (ret != DEVICE_OK)
      return ret;

   if (answer.substr(0,1).compare("R") == 0)
   {
      return DEVICE_OK; // LIN 01-03-2012 note "R" is the correct response from H128
   }
   else if (answer.substr(0, 1).compare("E") == 0 && answer.length() > 2) // LIN 01-03-2012 note I don't think the H128 reports E## errors but we can leave this in
   {
      int errNo = atoi(answer.substr(2).c_str()); // LIN 01-03-2012 note here the error number is extracted, atol converts string to short integer
      return ERR_OFFSET + errNo;
   }

   return ERR_UNRECOGNIZED_ANSWER;   
}
Exemplo n.º 10
0
//Zeros XY position
int XYStage::SetOrigin()
{
   MMThreadGuard guard(lock_);

   int ret = ClearPort(*this, *GetCoreCallback(), port_);
   if (ret != DEVICE_OK)
      return ret;

   ret = SendSerialCommand(port_.c_str(), "PX 0", "\r");
   if (ret != DEVICE_OK)
      return ret;

   std::string answer;
   ret = GetSerialAnswer(port_.c_str(), "\r", answer);
   if (ret != DEVICE_OK)
      return ret;

   if (answer.substr(0,1).compare("A") == 0)
   {
		ret = ClearPort(*this, *GetCoreCallback(), port_);
	   if (ret != DEVICE_OK)
		  return ret;

	   ret = SendSerialCommand(port_.c_str(), "PY 0", "\r");
	   if (ret != DEVICE_OK)
		  return ret;

	   std::string answer2;
	   ret = GetSerialAnswer(port_.c_str(), "\r", answer2);
	   if (ret != DEVICE_OK)
		  return ret;

	   if (answer2.substr(0,1).compare("A") == 0)
	   {
		  return DEVICE_OK;
	   }
   }
   return ERR_UNRECOGNIZED_ANSWER; 
}
Exemplo n.º 11
0
//Gets and sets the Acceleration of the stage travels
int XYStage::OnAcceleration(MM::PropertyBase* pProp, MM::ActionType eAct) 
{
   int ret = ClearPort(*this, *GetCoreCallback(), port_);
   if (ret != DEVICE_OK)
      return ret;

   if (eAct == MM::BeforeGet) 
   {
      ret = SendSerialCommand(port_.c_str(), "ACC", "\r");
      if (ret != DEVICE_OK)
         return ret;

      std::string answer;
      ret = GetSerialAnswer(port_.c_str(), "\r", answer);
      if (ret != DEVICE_OK)
         return ret;

      int acceleration = atoi(answer.c_str());

      pProp->Set((long)acceleration);

   } 
   else if (eAct == MM::AfterSet) 
   {
      long acceleration;
      pProp->Get(acceleration);

      std::ostringstream os;
      os << "ACC " <<  acceleration;

      ret = SendSerialCommand(port_.c_str(), os.str().c_str(), "\r");
      if (ret != DEVICE_OK)
         return ret;

      std::string answer;
      ret = GetSerialAnswer(port_.c_str(), "\r", answer);
      if (ret != DEVICE_OK)
         return ret;

      if (answer.substr(0,1).compare("A") == 0)
      {
         return DEVICE_OK;
      }
      return ERR_UNRECOGNIZED_ANSWER;

   }

   return DEVICE_OK;
}
void TxPacket1(int port_num)
{
    int _idx;

    UINT8_T _checksum = 0;
    UINT8_T _total_packet_length = packetData[port_num].txpacket_[PKT_LENGTH] + 4; // 4: HEADER0 HEADER1 ID LENGTH
    UINT8_T _written_packet_length = 0;

    if (is_using_[port_num])
    {
        packetData[port_num].communication_result_ = COMM_PORT_BUSY;
        return ;
    }
    is_using_[port_num] = true;

    // check max packet length
    if (_total_packet_length > TXPACKET_MAX_LEN)
    {
        is_using_[port_num] = false;
        packetData[port_num].communication_result_ = COMM_TX_ERROR;
        return;
    }

    // make packet header
    packetData[port_num].txpacket_[PKT_HEADER0] = 0xFF;
    packetData[port_num].txpacket_[PKT_HEADER1] = 0xFF;

    // add a checksum to the packet
    for (_idx = 2; _idx < _total_packet_length - 1; _idx++)   // except header, checksum
        _checksum += packetData[port_num].txpacket_[_idx];
    packetData[port_num].txpacket_[_total_packet_length - 1] = ~_checksum;

    // tx packet
    ClearPort(port_num);
    _written_packet_length = WritePort(port_num, packetData[port_num].txpacket_, _total_packet_length);
    if (_total_packet_length != _written_packet_length)
    {
        is_using_[port_num] = false;
        packetData[port_num].communication_result_ = COMM_TX_FAIL;
        return;
    }

    packetData[port_num].communication_result_ = COMM_SUCCESS;
}
Exemplo n.º 13
0
//Sends to corner and sets them postions to 0
int XYStage::Home()
{
   MMThreadGuard guard(lock_);

   int ret = ClearPort(*this, *GetCoreCallback(), port_);
   if (ret != DEVICE_OK)
      return ret;

	// move to corner
   ret = SendSerialCommand(port_.c_str(), "vj 30000 30000 0", "\r");
    if (ret != DEVICE_OK)
      return ret;
	
	std::string answer;
    ret = GetSerialAnswer(port_.c_str(), "\r", answer);
    if (ret != DEVICE_OK)
       return ret;

    if (answer.substr(0,1).compare("A") == 0)
    {
		//set x postion to 0
	    ret = SendSerialCommand(port_.c_str(), "px = 0", "\r");
		if (ret != DEVICE_OK)
		   return ret;

		//set y postion to 0
	    ret = SendSerialCommand(port_.c_str(), "py = 0", "\r");
		if (ret != DEVICE_OK)
		   return ret;

	    std::string answer;
	    ret = GetSerialAnswer(port_.c_str(), "\r", answer);
	    if (ret != DEVICE_OK)
		   return ret;

	    if (answer.substr(0,1).compare("A") == 0)
	    {
		  return DEVICE_OK;
        }
	}
   return ERR_UNRECOGNIZED_ANSWER;
}
Exemplo n.º 14
0
int ZStage::GetPositionSteps(long& steps)
{
   // First Clear serial port from previous stuff
   int ret = ClearPort(*this, *GetCoreCallback(), port_);
   if (ret != DEVICE_OK)
      return ret;

   const char* command="PZ"; // LIN 01-03-2012 SAME COMMAND FOR H128 AS NEWER CONTROLLERS

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

   // block/wait for acknowledge, or until we time out;
   std::string answer;
   ret = GetSerialAnswer(port_.c_str(), "\r", answer);
   if (ret != DEVICE_OK)
   {
      // failed reading the port
      return ret;
   }

   if (answer.length() > 2 && answer.substr(0, 1).compare("E") == 0) // LIN 01-03-2012 note I don't think the H128 reports E## errors but we can leave this in
   {
      int errNo = atoi(answer.substr(2).c_str()); // LIN 01-03-2012 note here the error number is extracted
      return ERR_OFFSET + errNo;
   }
   else if (answer.length() > 0)
   {
      steps = atol(answer.c_str());
      curSteps_ = steps; // LIN 01-03-2012 note curSteps was passed to this function by reference and here gets modified to the reported steps number
      return DEVICE_OK;
   }

   return ERR_UNRECOGNIZED_ANSWER;
}
Exemplo n.º 15
0
int XYStage::GetPositionStepsSingle(char axis, long& steps) 
// LIN 01-01-2012 NOTE this function is called by function GetPositionSteps(long& x, long& y) where long& x is a variable x of type long, passed here by reference with modification rights
{
   // First Clear serial port from previous stuff
   int ret = ClearPort(*this, *GetCoreCallback(), port_);
   if (ret != DEVICE_OK)
      return ret;

   std::stringstream command;
   command << "P" << axis; //LIN assembles command as either PX or PY depending on whether X or Y is being asked by GetPositionSteps

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

   // block/wait for acknowledge, or until we time out;
   std::string answer;
   ret = GetSerialAnswer(port_.c_str(), "\r", answer);
   if (ret != DEVICE_OK)
   {
      return ret;
   }

   if (answer.length() > 2 && answer.substr(0, 1).compare("E") == 0) // LIN 01-03-2012 note I don't think the H128 reports E## errors but we can leave this in
   {
      int errNo = atoi(answer.substr(2).c_str()); // LIN 01-03-2012 note here the error number is extracted, atol converts string to short integer
      return ERR_OFFSET + errNo;
   }
   else if (answer.length() > 0)
   {
      steps = atol(answer.c_str()); // LIN 01-03-2012 this is where x or y is updated, atol converts string to long integer
      return DEVICE_OK;
   }

   return ERR_UNRECOGNIZED_ANSWER;
}