31int main(
int argc,
char* argv[]) {
33 std::cout <<
"Usage: testRead [pvname]" << std::endl;
36 std::string pvName(argv[1]);
37 std::cout <<
"Reding pv: " << pvName.c_str() << std::endl;
38 auto result = ca_context_create(ca_disable_preemptive_callback);
39 if(result != ECA_NORMAL) {
40 std::cerr <<
"CA error " << ca_message(result)
41 <<
" occurred while trying "
42 "to start channel access"
46 pv* mypv = (
pv*)calloc(1,
sizeof(
pv));
47 mypv->
name = (
char*)pvName.c_str();
48 epicsTimeGetCurrent(&tsStart);
49 result = ca_create_channel(mypv->
name, 0, &mypv, default_ca_priority, &mypv->
chid);
50 if(result != ECA_NORMAL) {
51 std::cerr <<
"CA error " << ca_message(result)
52 <<
" occurred while trying "
54 << mypv->
name <<
"'." << std::endl;
57 result = ca_pend_io(1);
58 if(result == ECA_TIMEOUT) {
59 std::cerr <<
"Channel time out for PV: " << pvName << std::endl;
63 if(result != ECA_NORMAL) {
64 std::cerr <<
"CA error " << ca_message(result) <<
" occurred while trying to create channel " << mypv->
name
68 unsigned long nElems = ca_element_count(mypv->
chid);
71 if(ca_state(mypv->
chid) == cs_conn) {
75 fprintf(stderr,
"Memory allocation failed\n");
82 result = ca_pend_io(1);
83 if(result == ECA_TIMEOUT) std::cerr <<
"Read operation timed out: some PV data was not read." << std::endl;
86 std::cerr <<
"No connection..." << std::endl;
89 unsigned base_type = mypv->
dbfType % (LAST_TYPE + 1);
90 for(
size_t i = 0; i < mypv->
nElems; i++) {
94 if(i == 0) printTime<dbr_time_string>(i, mypv->
value);
98 if(i == 0) printTime<dbr_time_float>(i, mypv->
value);
102 if(i == 0) printTime<dbr_time_double>(i, mypv->
value);
106 if(i == 0) printTime<dbr_time_char>(i, mypv->
value);
110 if(i == 0) printTime<dbr_time_short>(i, mypv->
value);
114 if(i == 0) printTime<dbr_time_long>(i, mypv->
value);
118 if(i == 0) printTime<dbr_time_enum>(i, mypv->
value);
134 throw std::runtime_error(std::string(
"Type ") + std::to_string(mypv->
dbfType) +
" not implemented.");
146 ca_clear_channel(mypv->
chid);
147 ca_context_destroy();