Exemplo n.º 1
0
/**
*  Try to connect device 
*  @return int  1 if successful connected
*/
int OkolabDevice::TryConnectDevice(int iport)
{
 char strPort[3];
 char param[2][10];
 sprintf(param[0],"%d",product_id);
 sprintf(param[1],"%d",device_id);

 if(iport<0) return -1;
 // disconnect first 
 if(!OCSConnectionOpen(ipport_,ipaddress_)) return -1;
 if(!OCSSendRcvdCommand("connect",param[0],"0","")) return -1; 
 OCSConnectionClose();

 sprintf(strPort,"%d",iport);
 if(!OCSConnectionOpen(ipport_,ipaddress_)) return -1;
 if(!OCSSendRcvdCommand("comport",param[0],param[1],strPort)) return -1; 
 OCSConnectionClose();
 if(rcv_statuscode!=0) return -1;
 if(strcmp(rcv_answer,"1")!=0) return -1;

 if(!OCSConnectionOpen(ipport_,ipaddress_)) return -1;
 if(!OCSSendRcvdCommand("checkcon",param[0],"","")) return -1; 
 OCSConnectionClose();
 if(rcv_statuscode!=0) return -1;
 if(strcmp(rcv_answer,"1")!=0) return -1;

 return 1;
}
Exemplo n.º 2
0
MM::DeviceDetectionStatus H101CryoControl::DetectDevice(void)
{
 int iport=-1;
 char strPort[3];
 if(initialized_) return MM::CanCommunicate;

 // all conditions must be satisfied...
 MM::DeviceDetectionStatus result = MM::Misconfigured;
   
 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;

	 if(portLowerCase.compare("com1")==0) iport=1;
     else if(portLowerCase.compare("com2")==0) iport=2;
     else if(portLowerCase.compare("com3")==0) iport=3;
     else if(portLowerCase.compare("com4")==0) iport=4;
     if(iport<0) return MM::CanNotCommunicate;

     sprintf(strPort,"%d",iport);
     if(!OCSConnectionOpen(ipport_,ipaddress_)) return MM::CanNotCommunicate;
     if(!OCSSendRcvdCommand("comport","1","0",strPort)) return MM::CanNotCommunicate; 
     OCSConnectionClose();
     if(rcv_statuscode!=0) return MM::CanNotCommunicate;
     if(!strcmp(rcv_answer,"1")) return MM::CanNotCommunicate;

     if(!OCSConnectionOpen(ipport_,ipaddress_)) return MM::CanNotCommunicate;
     if(!OCSSendRcvdCommand("checkcon","1","0","")) return MM::CanNotCommunicate; 
     OCSConnectionClose();
     if(rcv_statuscode!=0) return MM::CanNotCommunicate;
     if(!strcmp(rcv_answer,"1")) return MM::CanNotCommunicate;

	 result=MM::CanCommunicate;
    }
   }
  catch(...)
   {
    LogMessage("Exception in DetectDevice!",false);
   }
 return result;
}
Exemplo n.º 3
0
/*
 *  Try to stop OCS
 *  @return 1 if all ok otherwise negative code
*/
int OkolabDevice::OCSStop()
{
 if(!OCSRunning()) return -1;
 if(!OCSConnectionOpen(ipport_,ipaddress_)) return -2;
 if(!OCSSendRcvdCommand("close", "", "", "")) return -3;
 OCSConnectionClose();
 if(rcv_statuscode!=0) return -4;
 return 1;
}
Exemplo n.º 4
0
int H101CryoControl::GetTemp(double& temp)
{   
 if(!initialized_) return DEVICE_ERR;
 if(!OCSConnectionOpen(ipport_,ipaddress_)) return DEVICE_ERR;
 if(!OCSSendRcvdCommand("readval","1","-1","-1")) return DEVICE_ERR; 
 OCSConnectionClose();
 if(rcv_statuscode!=0) return DEVICE_ERR;
 temp=atof(rcv_answer);
 return DEVICE_OK;                                                         
} 
Exemplo n.º 5
0
/*
 *  Obtains set-point value from OCS
 */
int OkolabDevice::GetSetPoint(double& sp)
{   
 char param[2][10];
 sprintf(param[0],"%d",product_id);
 sprintf(param[1],"%d",device_id);
 if(!OCSConnectionOpen(ipport_,ipaddress_)) return -1;
 if(!OCSSendRcvdCommand("readsetpoint",param[0],param[1],"-1")) return -2; 
 OCSConnectionClose();
 if(rcv_statuscode!=0) return -3;
 sp=atof(rcv_answer);
 return 1;                                                         
} 
Exemplo n.º 6
0
/**
*  Unconnect the device 
*  @return int  1 if successful unconnected
*/
int OkolabDevice::UnconnectDevice()
{
 char prod_id_str[10];
 sprintf(prod_id_str,"%d",product_id);

	 // disconnect first 
 if(!OCSConnectionOpen(ipport_,ipaddress_)) return -1;
 if(!OCSSendRcvdCommand("connect",prod_id_str,"0","")) return -1; 
 OCSConnectionClose();
	
 return 1;
}
Exemplo n.º 7
0
/*
 *  Send set-point value to OCS
 */
int OkolabDevice::SetSetPoint(double sp)
{
 char strSP[8];
 char param[2][10];
 sprintf(param[0],"%d",product_id);
 sprintf(param[1],"%d",device_id);
 snprintf(strSP,8,"%.01f",sp);
 if(!OCSConnectionOpen(ipport_,ipaddress_)) return -1;
 if(!OCSSendRcvdCommand("writesetpoint",param[0],param[1],strSP)) return -2; 
 OCSConnectionClose();
 if(rcv_statuscode!=0) return -3;
 return 1;                                           
} 
Exemplo n.º 8
0
/*
 *  Send comport value to OCS
 */
int OkolabDevice::SetCommPort(int port)
{
 char strP[8];
 char param[2][10];
 sprintf(param[0],"%d",product_id);
 sprintf(param[1],"%d",device_id);
 snprintf(strP,8,"%d",port);
 if(!OCSConnectionOpen(ipport_,ipaddress_)) return -1;
 if(!OCSSendRcvdCommand("comport",param[0],param[1],strP)) return -2; 
 OCSConnectionClose();
 if(rcv_statuscode!=0) return -3;
 return 1;                                           
}
Exemplo n.º 9
0
/**
 * Get working status (connected and working) of a product  
 * 
 * @params int product_id
 * @return int 1=connected 
 */
int OkolabDevice::IsDeviceWorking(int product_id)
{
 int ret=-4;
 char param[10];
 int rv[3]; 
 rv[0]=0;rv[1]=0;rv[2]=0;
 sprintf(param,"%d",product_id);
 if(!OCSConnectionOpen(ipport_,ipaddress_)) return -2;
 if(!OCSSendRcvdCommand("getprodinfo",param,"","")) return -3;
 OCSConnectionClose();
 sscanf(rcv_answer,"%d %d %d",&rv[0],&rv[1],&rv[2]);
 if((rcv_statuscode<2) && (rv[1]==1)) ret=1;
 return ret;
}
Exemplo n.º 10
0
/*
 *  Obtains ComPort on witch OCS is connected to this device
 * 
 *  @return 1 if all ok otherwise negative code
 */
int OkolabDevice::GetCommPort(char *strcommport)
{   
 int pn;
 int ret=1;
 char param[2][10];
 sprintf(param[0],"%d",product_id);
 sprintf(param[1],"%d",device_id);
 strcpy(strcommport,"Undefined");
 if(!OCSConnectionOpen(ipport_,ipaddress_)) return -1;
 if(!OCSSendRcvdCommand("comport",param[0],param[1],"")) return -2;
 OCSConnectionClose();
 if(rcv_statuscode!=0) return -3;
 sscanf(rcv_answer,"%d",&pn);
 if((pn>0) && (pn<256)) sprintf(strcommport,"COM %d",pn);
 else { strcpy(strcommport,"-"); ret=0; }
 return ret; 
} 
Exemplo n.º 11
0
OkolabDevice::~OkolabDevice()
{
 OCSConnectionClose();
}