|
| 1 | +/* |
| 2 | + * Copyright information and license terms for this software can be |
| 3 | + * found in the file LICENSE that is included with the distribution |
| 4 | + */ |
| 5 | + |
| 6 | +/** |
| 7 | + * @author mrk |
| 8 | + */ |
| 9 | + |
| 10 | +/* Author: Marty Kraimer */ |
| 11 | + |
| 12 | +#include <iostream> |
| 13 | + |
| 14 | +#include <pv/pvaClientMultiChannel.h> |
| 15 | +#include <pv/convert.h> |
| 16 | + |
| 17 | +using std::tr1::static_pointer_cast; |
| 18 | +using namespace std; |
| 19 | +using namespace epics::pvData; |
| 20 | +using namespace epics::pvAccess; |
| 21 | +using namespace epics::pvaClient; |
| 22 | + |
| 23 | + |
| 24 | +static void example( |
| 25 | + PvaClientPtr const &pva, |
| 26 | + string provider, |
| 27 | + shared_vector<const string> const &channelNames) |
| 28 | +{ |
| 29 | + cout << "_example provider " << provider << " channels " << channelNames << "_\n"; |
| 30 | + size_t num = channelNames.size(); |
| 31 | + PvaClientMultiChannelPtr multiChannel( |
| 32 | + PvaClientMultiChannel::create(pva,channelNames,provider)); |
| 33 | + Status status = multiChannel->connect(); |
| 34 | + if(!status.isSuccess()) { |
| 35 | + cout << "Did not connect: "; |
| 36 | + shared_vector<epics::pvData::boolean> isConnected = multiChannel->getIsConnected(); |
| 37 | + for(size_t i=0; i<num; ++i) { |
| 38 | + if(!isConnected[i]) cout << channelNames[i] << " "; |
| 39 | + } |
| 40 | + cout << endl; |
| 41 | + return; |
| 42 | + } |
| 43 | + PvaClientNTMultiGetPtr multiGet(multiChannel->createNTGet()); |
| 44 | + multiGet->get(); |
| 45 | + PvaClientNTMultiDataPtr multiData = multiGet->getData(); |
| 46 | + PVStructurePtr pvStructure = multiData->getNTMultiChannel()->getPVStructure(); |
| 47 | + PVUnionArrayPtr pvUnionArray = static_pointer_cast<PVUnionArray>(pvStructure->getSubField("value")); |
| 48 | + shared_vector<const PVUnionPtr> values = pvUnionArray->view(); |
| 49 | + for(size_t ind=0; ind < values.size(); ++ind) |
| 50 | + { |
| 51 | + PVUnionPtr pvUnion = values[ind]; |
| 52 | + PVFieldPtr pvField = pvUnion->get(); |
| 53 | + cout << channelNames[ind] << " = " << pvField << "\n"; |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +int main(int argc,char *argv[]) |
| 58 | +{ |
| 59 | + cout << "_____examplePvaClientNTMultiGet starting_______\n"; |
| 60 | + try { |
| 61 | + PvaClientPtr pva = PvaClient::get("pva ca"); |
| 62 | + size_t num = 4; |
| 63 | + shared_vector<string> channelNames(num); |
| 64 | + channelNames[0] = "PVRdouble"; |
| 65 | + channelNames[1] = "PVRstring"; |
| 66 | + channelNames[2] = "PVRdoubleArray"; |
| 67 | + channelNames[3] = "PVRstringArray"; |
| 68 | + shared_vector<const string> names(freeze(channelNames)); |
| 69 | + example(pva,"pva",names); |
| 70 | + cout << "_____examplePvaClientNTMultiGet done_______\n"; |
| 71 | + } catch (std::exception& e) { |
| 72 | + cout << "exception " << e.what() << endl; |
| 73 | + return 1; |
| 74 | + } |
| 75 | + return 0; |
| 76 | +} |
0 commit comments