added support for multi channel double
This commit is contained in:
121
src/pvaClientMultiPutDouble.cpp
Normal file
121
src/pvaClientMultiPutDouble.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
/* pvaClientMultiPutDouble.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2015.03
|
||||
*/
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include <pv/pvaClientMultiChannel.h>
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/convert.h>
|
||||
#include <epicsMath.h>
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::nt;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
static ConvertPtr convert = getConvert();
|
||||
static FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
static PVDataCreatePtr pvDataCreate = getPVDataCreate();
|
||||
static StandardFieldPtr standardField = getStandardField();
|
||||
static CreateRequest::shared_pointer createRequest = CreateRequest::create();
|
||||
|
||||
|
||||
PvaClientMultiPutDoublePtr PvaClientMultiPutDouble::create(
|
||||
PvaClientMultiChannelPtr const &pvaMultiChannel,
|
||||
PvaClientChannelArray const &pvaClientChannelArray)
|
||||
{
|
||||
PvaClientMultiPutDoublePtr pvaClientMultiPutDouble(
|
||||
new PvaClientMultiPutDouble(pvaMultiChannel,pvaClientChannelArray));
|
||||
return pvaClientMultiPutDouble;
|
||||
}
|
||||
|
||||
PvaClientMultiPutDouble::PvaClientMultiPutDouble(
|
||||
PvaClientMultiChannelPtr const &pvaClientMultiChannel,
|
||||
PvaClientChannelArray const &pvaClientChannelArray)
|
||||
: pvaClientMultiChannel(pvaClientMultiChannel),
|
||||
pvaClientChannelArray(pvaClientChannelArray),
|
||||
nchannel(pvaClientChannelArray.size()),
|
||||
pvaClientPut(std::vector<PvaClientPutPtr>(nchannel,PvaClientPutPtr())),
|
||||
isPutConnected(false),
|
||||
isDestroyed(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
PvaClientMultiPutDouble::~PvaClientMultiPutDouble()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
void PvaClientMultiPutDouble::destroy()
|
||||
{
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
pvaClientChannelArray.clear();
|
||||
}
|
||||
|
||||
void PvaClientMultiPutDouble::connect()
|
||||
{
|
||||
shared_vector<bool> isConnected = pvaClientMultiChannel->getIsConnected();
|
||||
for(size_t i=0; i<nchannel; ++i)
|
||||
{
|
||||
if(isConnected[i]) {
|
||||
pvaClientPut[i] = pvaClientChannelArray[i]->createPut();
|
||||
pvaClientPut[i]->issueConnect();
|
||||
}
|
||||
}
|
||||
for(size_t i=0; i<nchannel; ++i)
|
||||
{
|
||||
if(isConnected[i]) {
|
||||
Status status = pvaClientPut[i]->waitConnect();
|
||||
if(status.isOK()) continue;
|
||||
stringstream ss;
|
||||
string channelName = pvaClientChannelArray[i]->getChannelName();
|
||||
ss << "channel " << channelName << " PvaChannelPut::waitConnect " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
}
|
||||
isPutConnected = true;
|
||||
}
|
||||
|
||||
void PvaClientMultiPutDouble::put(epics::pvData::shared_vector<double> const &data)
|
||||
{
|
||||
if(!isPutConnected) connect();
|
||||
if(data.size()!=nchannel) {
|
||||
throw std::runtime_error("data has wrong size");
|
||||
}
|
||||
shared_vector<bool> isConnected = pvaClientMultiChannel->getIsConnected();
|
||||
for(size_t i=0; i<nchannel; ++i)
|
||||
{
|
||||
if(isConnected[i]) {
|
||||
PVStructurePtr pvTop = pvaClientPut[i]->getData()->getPVStructure();
|
||||
PVDoublePtr pvValue = pvTop->getSubField<PVDouble>("value");
|
||||
pvValue->put(data[i]);
|
||||
pvaClientPut[i]->issuePut();
|
||||
}
|
||||
if(isConnected[i]) {
|
||||
Status status = pvaClientPut[i]->waitPut();
|
||||
if(status.isOK()) continue;
|
||||
stringstream ss;
|
||||
string channelName = pvaClientChannelArray[i]->getChannelName();
|
||||
ss << "channel " << channelName << " PvaChannelPut::waitConnect " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}}
|
||||
Reference in New Issue
Block a user