Skip to content
Snippets Groups Projects
Commit a5acf6d1 authored by Alain BUTEAU's avatar Alain BUTEAU
Browse files

- code a relire

parent 507779ee
Branches
Tags
No related merge requests found
static const char *RcsId = "$Header: /users/chaize/newsvn/cvsroot/Instrumentation/CYBERSTAR/src/CYBERSTARx1000.cpp,v 1.16 2008-02-19 17:49:08 sebleport Exp $";
static const char *RcsId = "$Header: /users/chaize/newsvn/cvsroot/Instrumentation/CYBERSTAR/src/CYBERSTARx1000.cpp,v 1.17 2008-02-26 17:56:58 buteau Exp $";
//+=============================================================================
//
// file : CYBERSTARx1000.cpp
......@@ -11,11 +11,15 @@ static const char *RcsId = "$Header: /users/chaize/newsvn/cvsroot/Instrumentatio
//
// project : TANGO Device Server
//
// $Author: sebleport $
// $Author: buteau $
//
// $Revision: 1.16 $
// $Revision: 1.17 $
//
// $Log: not supported by cvs2svn $
// Revision 1.16 2008/02/19 17:49:08 sebleport
// - _DEV_TRY added
// - 300 ms de temporistaion entre l'ecriture des 2 SCA
//
// Revision 1.15 2007/10/24 15:37:15 sebleport
// - read_lowSca() & read-upSca() added in overloaded dev_state() methods (is usefull for the scanserver interfacing)
//
......@@ -96,6 +100,12 @@ static const char *RcsId = "$Header: /users/chaize/newsvn/cvsroot/Instrumentatio
#include <CYBERSTARx1000.h>
#include <CYBERSTARx1000Class.h>
const double SCA_UPPER_THRESHOLD_MAX=10.0; // in volts
const double SCA_LOWER_THRESHOLD_MIN=0.0; // in volts
const double PEAKING_TIME_VALUE1= 300.0; //possible values for peaking time are 300, 500, 1000 and 3000 ns
const double PEAKING_TIME_VALUE2= 500.0;
const double PEAKING_TIME_VALUE3= 1000.0;
const double PEAKING_TIME_VALUE4= 3000.0;
namespace CYBERSTARx1000_ns
{
......@@ -183,6 +193,19 @@ namespace CYBERSTARx1000_ns
//pointer to device proxy initialized to 0
mySerial = 0;
/*
// Write parts of attribut must be egal to read values at startup
read_upper();
read_lower();
if(attr_scaUpperThreshold_write ==0)
attr_scaUpperThreshold_write= (*attr_scaUpperThreshold_read);
if(attr_scaLowerThreshold_write ==0)
attr_scaLowerThreshold_write= (*attr_scaLowerThreshold_read);
*/
}
//+----------------------------------------------------------------------------
//
......@@ -334,28 +357,24 @@ void CYBERSTARx1000::write_windowCenterPosition(Tango::WAttribute &attr)
{
// high threshold updating
attr_scaUpperThreshold_write = attr_windowCenterPosition_write + attr_windowWidth_write/2;
high_level = XString<double>::convertToString(attr_scaUpperThreshold_write);
// low threshold updating
attr_scaLowerThreshold_write = attr_windowCenterPosition_write - attr_windowWidth_write/2;
low_level = XString<double>::convertToString(attr_scaLowerThreshold_write);
if(attr_scaUpperThreshold_write<=10 && attr_scaLowerThreshold_write>=0 )
// check upper and lower values before writing on hardware
if(attr_scaUpperThreshold_write<=SCA_UPPER_THRESHOLD_MAX && attr_scaLowerThreshold_write>=SCA_LOWER_THRESHOLD_MIN )
{
//wait for cyberstar to process command
omni_thread::sleep(0,300000000); // in nanoseconds -> 250 ms
// omni_thread::sleep(0,300000000); // in nanoseconds -> 250 ms
_DEV_TRY(
response = write_read(":SENS0:SCA:UPP "+ high_level,false),
"write sca upper threshold",
"CYBERSTARx1000::write_windowCenterPosition()");
write_upper(attr_scaUpperThreshold_write);
//read_upper();
//wait for cyberstar to process command
omni_thread::sleep(0,300000000); // in nanoseconds -> 250 ms
// omni_thread::sleep(0,300000000); // in nanoseconds -> 250 ms
_DEV_TRY(
response = write_read(":SENS0:SCA:LOW "+ low_level,false),
"write sca lower threshold",
"CYBERSTARx1000::write_windowCenterPosition()");
write_lower(attr_scaLowerThreshold_write);
// read_lower();
}
else
{
......@@ -383,14 +402,13 @@ void CYBERSTARx1000::write_windowCenterPosition(Tango::WAttribute &attr)
void CYBERSTARx1000::read_voltage(Tango::Attribute &attr)
{
DEBUG_STREAM << "CYBERSTARx1000::read_voltage(Tango::Attribute &attr) entering... "<< endl;
string response;
_DEV_TRY(
response = write_read(":SOUR0:VOLT?",true),
"read high voltage",
"CYBERSTARx1000::read_voltage()");
response = process_string(response);
*attr_voltage_read = XString<double>::convertFromString(response);
attr.set_value(attr_voltage_read);
......@@ -426,14 +444,12 @@ void CYBERSTARx1000::write_windowCenterPosition(Tango::WAttribute &attr)
void CYBERSTARx1000::read_forcedRemoteMode(Tango::Attribute &attr)
{
DEBUG_STREAM << "CYBERSTARx1000::read_forcedRemoteMode(Tango::Attribute &attr) entering... "<< endl;
string response;
_DEV_TRY(
response = write_read(":SYST0:COMM:REM?",true),
"read remote state",
"CYBERSTARx1000::read_forcedRemoteMode()");
response = process_string(response);
int forced_remote = XString<int>::convertFromString(response);
if (forced_remote == 0)
......@@ -469,7 +485,7 @@ void CYBERSTARx1000::write_windowCenterPosition(Tango::WAttribute &attr)
"set front of mode",
"CYBERSTARx1000::write_forcedRemoteMode()");
}
else if(attr_forcedRemoteMode_write == true)
else
{
_DEV_TRY(
write_read(":SYST0:COMM:REM ON",false),
......@@ -488,14 +504,12 @@ void CYBERSTARx1000::write_windowCenterPosition(Tango::WAttribute &attr)
void CYBERSTARx1000::read_amplifierGain(Tango::Attribute &attr)
{
DEBUG_STREAM << "CYBERSTARx1000::read_amplifierGain(Tango::Attribute &attr) entering... "<< endl;
string response;
_DEV_TRY(
response = write_read(":INP0:GAIN?",true),
"read gain",
"CYBERSTARx1000::read_amplifierGain()");
response = process_string(response);
*attr_amplifierGain_read = XString<double>::convertFromString(response);
attr.set_value(attr_amplifierGain_read);
......@@ -514,7 +528,7 @@ void CYBERSTARx1000::write_windowCenterPosition(Tango::WAttribute &attr)
attr.get_write_value(attr_amplifierGain_write);
preset = XString<double>::convertToString(attr_amplifierGain_write);
string preset = XString<double>::convertToString(attr_amplifierGain_write);
_DEV_TRY(
write_read(":INP0:GAIN "+ preset,false),
......@@ -532,13 +546,12 @@ void CYBERSTARx1000::write_windowCenterPosition(Tango::WAttribute &attr)
void CYBERSTARx1000::read_peakingTime(Tango::Attribute &attr)
{
DEBUG_STREAM << "CYBERSTARx1000::read_peakingTime(Tango::Attribute &attr) entering... "<< endl;
string response;
_DEV_TRY(
response = write_read(":SENS0:PKT?",true),
"read peaking Time",
"CYBERSTARx1000::read_peakingTime()");
response = process_string(response);
*attr_peakingTime_read = XString<double>::convertFromString(response);
......@@ -560,9 +573,9 @@ void CYBERSTARx1000::write_windowCenterPosition(Tango::WAttribute &attr)
double pkt = attr_peakingTime_write;
if(pkt==300 || pkt==500 || pkt==1000 || pkt==3000)
if(pkt==PEAKING_TIME_VALUE1 || pkt==PEAKING_TIME_VALUE2 || pkt==PEAKING_TIME_VALUE3 || pkt==PEAKING_TIME_VALUE4)
{
preset = XString<double>::convertToString(pkt);
string preset = XString<double>::convertToString(pkt);
_DEV_TRY(
write_read(":SENS0:PKT "+ preset,false),
......@@ -612,15 +625,12 @@ void CYBERSTARx1000::write_windowCenterPosition(Tango::WAttribute &attr)
DEBUG_STREAM << "CYBERSTARx1000::write_scaUpperThreshold(Tango::WAttribute &attr) entering... "<< endl;
attr.get_write_value(attr_scaUpperThreshold_write);
// refresh lower value from hardware
read_lower();
if(attr_scaUpperThreshold_write > *attr_scaLowerThreshold_read)
{
preset = XString<double>::convertToString(attr_scaUpperThreshold_write);
_DEV_TRY(
write_read(":SENS0:SCA:UPP "+ preset,false),
"write SCA upper thresold",
"CYBERSTARx1000::write_scaUpperThreshold()");
write_upper(attr_scaUpperThreshold_write);
}
else
{
......@@ -662,15 +672,12 @@ void CYBERSTARx1000::write_windowCenterPosition(Tango::WAttribute &attr)
DEBUG_STREAM << "CYBERSTARx1000::write_scaLowerThreshold(Tango::WAttribute &attr) entering... "<< endl;
attr.get_write_value(attr_scaLowerThreshold_write);
// refresh upper value from hardware
read_upper();
if (attr_scaLowerThreshold_write < *attr_scaUpperThreshold_read)
{
preset = XString<double>::convertToString(attr_scaLowerThreshold_write);
_DEV_TRY(
write_read(":SENS0:SCA:LOW "+ preset,false),
"write SCA lower thresold",
"CYBERSTARx1000::write_scaLowerThreshold()");
write_lower(attr_scaLowerThreshold_write);
}
else
......@@ -704,6 +711,7 @@ void CYBERSTARx1000::write_windowCenterPosition(Tango::WAttribute &attr)
long nb_char_written,mode=2;
cout << "**** cmd_to_send=" << cmd_to_send <<endl;
// Construct a dedicated DevVarCharArray with validation char <LF>
Tango::DevVarCharArray *LF = new Tango::DevVarCharArray();
LF->length(1);
......@@ -746,6 +754,11 @@ void CYBERSTARx1000::write_windowCenterPosition(Tango::WAttribute &attr)
mySerial->command_inout("DevSerReadString", readMode, response),
"read response",
"CYBERSTARx1000::write_read()");
// get rid of ACK characters in the response
response = process_string(response);
cout << "**** response=" << response <<endl;
}
return string(response);
......@@ -773,6 +786,8 @@ void CYBERSTARx1000::write_windowCenterPosition(Tango::WAttribute &attr)
"CYBERSTARx1000::init_CYBERSTARx1000()");
*attr_forcedRemoteMode_read = true;
//
}// end function
......@@ -791,6 +806,7 @@ void CYBERSTARx1000::write_windowCenterPosition(Tango::WAttribute &attr)
{
//- Creates the Proxy
mySerial = new Tango::DeviceProxyHelper(serialProxyName,this);
}
catch(Tango::DevFailed &df)
......@@ -820,9 +836,10 @@ void CYBERSTARx1000::write_windowCenterPosition(Tango::WAttribute &attr)
try
{
// the "ack" character at the begining of the string is removed
processed_string = origin_string.substr(1);
// the "ack" character(s) at the begining of the string is removed
char ack=0x06;
size_t idx= origin_string.find_last_of(string(&ack));
processed_string=origin_string.substr(idx+1);
return processed_string;
}
......@@ -849,36 +866,96 @@ void CYBERSTARx1000::write_windowCenterPosition(Tango::WAttribute &attr)
//+------------------------------------------------------------------
void CYBERSTARx1000::read_lower()
{
string response;
_DEV_TRY(
response = write_read(":SENS0:SCA:LOW?",true),
"read sca lower threshold",
"CYBERSTARx1000::read_lower()");
response = process_string(response);
*attr_scaLowerThreshold_read = XString<double>::convertFromString(response);
}
//+------------------------------------------------------------------
/**
* method: CYBERSTARx1000::write_lower
*
* description: write the upper threshold
*
*/
//+------------------------------------------------------------------
void CYBERSTARx1000::write_lower(double setpoint)
{
char buffer [50];
int n = sprintf (buffer, ":SENS0:SCA:LOW %3.1f",setpoint);
//string high_level = XString<int>::convertToString(setpoint);
//string response = write_read(":SENS0:SCA:UPP "+ high_level,false);
string response = write_read(buffer,false);
//string low_level = XString<double>::convertToString(setpoint);
// string response = write_read(":SENS0:SCA:LOW "+ low_level,false);
read_lower();
double delta = (*attr_scaLowerThreshold_read) -attr_scaLowerThreshold_write;
if ((delta/attr_scaLowerThreshold_write) > 0,1)
{
cout << "retrying" << endl;
//wait for cyberstar to process command
omni_thread::sleep(0,900000000); // in nanoseconds -> 300 ms
// string response = write_read(":SENS0:SCA:LOW "+ low_level,false);
string response = write_read(buffer,false);
}
}
//+------------------------------------------------------------------
/**
* method: CYBERSTARx1000::read_upper
*
* description: read the lower threshold
*
* @return State Code
* description: read the upper threshold
*
*/
//+------------------------------------------------------------------
void CYBERSTARx1000::read_upper()
{
string response;
_DEV_TRY(
response = write_read(":SENS0:SCA:UPP?",true),
"read sca upper threshold",
"CYBERSTARx1000::read_upper()");
response = process_string(response);
*attr_scaUpperThreshold_read = XString<double>::convertFromString(response);
}
//+------------------------------------------------------------------
/**
* method: CYBERSTARx1000::write_upper
*
* description: write the upper threshold
*
*/
//+------------------------------------------------------------------
void CYBERSTARx1000::write_upper(double setpoint)
{
// NEVER send more than a 3.1f string to the Cyberstar otherwise sometimes its doesn't take the command into account
char buffer [50];
int n = sprintf (buffer, ":SENS0:SCA:UPP %3.1f",setpoint);
//string high_level = XString<int>::convertToString(setpoint);
//string response = write_read(":SENS0:SCA:UPP "+ high_level,false);
string response = write_read(buffer,false);
read_upper();
double delta = (*attr_scaUpperThreshold_read) -attr_scaUpperThreshold_write;
if ((delta/attr_scaUpperThreshold_write) > 0.1)
{
cout << "retrying delta =" << delta << ", attr_scaUpperThreshold_write=" << attr_scaUpperThreshold_write<< endl;
//wait for cyberstar to process command
omni_thread::sleep(0,900000000); // in nanoseconds -> 300 ms
// string response = write_read(":SENS0:SCA:UPP "+ high_level,false);
string response = write_read(buffer,false);
}
}
//+------------------------------------------------------------------
/**
* method: CYBERSTARx1000::dev_state
......@@ -897,19 +974,14 @@ Tango::DevState CYBERSTARx1000::dev_state()
Tango::DevState argout;
// get Tango::Attribute
Tango::Attribute &low_threshold = dev_attr->get_attr_by_name("scaLowerThreshold");
Tango::Attribute &high_threshold = dev_attr->get_attr_by_name("scaUpperThreshold");
// Tango::Attribute &low_threshold = dev_attr->get_attr_by_name("scaLowerThreshold");
// Tango::Attribute &high_threshold = dev_attr->get_attr_by_name("scaUpperThreshold");
// update attributes SCA threshold, useful with scan server interfacing
_DEV_TRY(
read_lower(),
"read sca lower threshold",
"CYBERSTARx1000::read_lower()");
// update attributes SCA thresholds, useful for scanserver interfacing
read_upper();
read_lower();
_DEV_TRY(
read_upper(),
"read sca upper threshold",
"CYBERSTARx1000::read_upper()");
// To check if threashol are moving we calculate target margins
double borneLowerPlus = (this->attr_windowCenterPosition_write - this->attr_windowWidth_write/2)*(2 - (tolerance/100));
double borneLowerMoins = (this->attr_windowCenterPosition_write - this->attr_windowWidth_write/2)*tolerance/100 ;
......@@ -922,6 +994,8 @@ Tango::DevState CYBERSTARx1000::dev_state()
INFO_STREAM << "borne upper plus = " << XString<double>::convertToString(borneUpperPlus) << endl;
INFO_STREAM << " " << endl;
// are actual position of threshold with target margins
if((
*this->attr_scaLowerThreshold_read <= borneLowerMoins
)
......
......@@ -6,11 +6,14 @@
//
// project : CYBERSTARx1000
//
// $Author: flanglois $
// $Author: buteau $
//
// $Revision: 1.11 $
// $Revision: 1.12 $
//
// $Log: not supported by cvs2svn $
// Revision 1.11 2007/06/12 15:11:57 flanglois
// - some modifs: cleaning the code+ tests with sleep; still tests to do (with A.B.)
//
// Revision 1.10 2007/05/15 13:00:22 sebleport
// - add OS sleep between reading and writing command in write_read() method
// - some changes in DevState() method
......@@ -69,8 +72,8 @@
//using namespace Tango;
/**
* @author $Author: flanglois $
* @version $Revision: 1.11 $
* @author $Author: buteau $
* @version $Revision: 1.12 $
*/
// Add your own constants definitions here.
......@@ -327,7 +330,7 @@ protected :
//data
Tango::DeviceProxyHelper* mySerial;
bool init_CYBERSTARx1000_done;
std::string response,preset;
//std::string preset;
//methodes
std::string write_read(std::string cmd_to_send,bool read_required);
......@@ -338,6 +341,8 @@ protected :
void read_lower();
void read_upper();
void write_lower(double setpoint);
void write_upper(double setpoint);
};
......
static const char *RcsId = "$Header: /users/chaize/newsvn/cvsroot/Instrumentation/CYBERSTAR/src/CYBERSTARx1000Class.cpp,v 1.8 2007-04-24 16:22:52 sebleport Exp $";
static const char *RcsId = "$Header: /users/chaize/newsvn/cvsroot/Instrumentation/CYBERSTAR/src/CYBERSTARx1000Class.cpp,v 1.9 2008-02-26 17:56:58 buteau Exp $";
static const char *TagName = "$Name: not supported by cvs2svn $";
static const char *HttpServer= "http://www.esrf.fr/computing/cs/tango/tango_doc/ds_doc/";
//+=============================================================================
......@@ -12,11 +12,16 @@ static const char *HttpServer= "http://www.esrf.fr/computing/cs/tango/tango_doc/
//
// project : TANGO Device Server
//
// $Author: sebleport $
// $Author: buteau $
//
// $Revision: 1.8 $
// $Revision: 1.9 $
//
// $Log: not supported by cvs2svn $
// Revision 1.8 2007/04/24 16:22:52 sebleport
// polling attribute set to 10000 ms by default (POGO).
// the concerned attributes are:
// voltage, peakingTime, gain
//
// Revision 1.7 2007/04/13 17:25:02 sebleport
// some changes in devstate() due to the interraction with the scan server device
//
......@@ -309,7 +314,6 @@ void CYBERSTARx1000Class::attribute_factory(vector<Tango::Attr *> &att_list)
sca_lower_threshold_prop.set_min_value("0.02");
sca_lower_threshold_prop.set_description("defines the lower voltage threshold which generates TTL pulses.\nCommonly an SCA is operated by setting an upper and lower\nlevels. it is adjustable between 50 mV to 10 V,\nprecision +/- 10 mV.");
sca_lower_threshold->set_default_properties(sca_lower_threshold_prop);
sca_lower_threshold->set_polling_period(3000);
att_list.push_back(sca_lower_threshold);
// Attribute : scaUpperThreshold
......@@ -324,7 +328,6 @@ void CYBERSTARx1000Class::attribute_factory(vector<Tango::Attr *> &att_list)
sca_upper_threshold_prop.set_min_value("0.02");
sca_upper_threshold_prop.set_description("defines the upper voltage threshold which generates output\nTTL pulses. Commonly an SCA is operated by setting an upper and lower\nlevels. it is adjustable between 50 mV to 10 V,\nprecision +/- 10 mV.");
sca_upper_threshold->set_default_properties(sca_upper_threshold_prop);
sca_upper_threshold->set_polling_period(3000);
att_list.push_back(sca_upper_threshold);
// Attribute : windowWidth
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment