This is Unofficial EPICS BASE Doxygen Site
caget.c File Reference
#include <stdio.h>
#include <string.h>
#include <epicsStdlib.h>
#include <epicsString.h>
#include <alarm.h>
#include <cadef.h>
#include <epicsGetopt.h>
#include "epicsVersion.h"
#include "tool_lib.h"
+ Include dependency graph for caget.c:

Go to the source code of this file.

Macros

#define VALID_DOUBLE_DIGITS   18 /* Max usable precision for a double */
 
#define PEND_EVENT_SLICES   5 /* No. of pend_event slices for callback requests */
 

Enumerations

enum  OutputT {
  plain, terse, all, specifiedDbr,
  plain, terse, all
}
 
enum  RequestT { get, callback, get, callback }
 

Functions

int main (int argc, char *argv[])
 

Macro Definition Documentation

#define PEND_EVENT_SLICES   5 /* No. of pend_event slices for callback requests */

Definition at line 42 of file caget.c.

#define VALID_DOUBLE_DIGITS   18 /* Max usable precision for a double */

Definition at line 41 of file caget.c.

Enumeration Type Documentation

enum OutputT
Enumerator
plain 
terse 
all 
specifiedDbr 
plain 
terse 
all 

Definition at line 45 of file caget.c.

Definition: caget.c:45
OutputT
Definition: caget.c:45
Definition: caget.c:45
Definition: caget.c:45
enum RequestT
Enumerator
get 
callback 
get 
callback 

Definition at line 48 of file caget.c.

48 { get, callback } RequestT;
RequestT
Definition: caget.c:48
Definition: caget.c:48

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 376 of file caget.c.

377 {
378  int n;
379  int result; /* CA result */
380  OutputT format = plain; /* User specified format */
381  RequestT request = get; /* User specified request type */
382  IntFormatT outType; /* Output type */
383 
384  int count = 0; /* 0 = not specified by -# option */
385  int opt; /* getopt() current option */
386  int type = -1; /* getopt() data type argument */
387  int digits = 0; /* getopt() no. of float digits */
388 
389  int nPvs; /* Number of PVs */
390  pv* pvs; /* Array of PV structures */
391 
392  LINE_BUFFER(stdout); /* Configure stdout buffering */
393 
394  while ((opt = getopt(argc, argv, ":taicnhsSVe:f:g:l:#:d:0:w:p:F:")) != -1) {
395  switch (opt) {
396  case 'h': /* Print usage */
397  usage();
398  return 0;
399  case 'V':
400  printf( "\nEPICS Version %s, CA Protocol version %s\n", EPICS_VERSION_STRING, ca_version() );
401  return 0;
402  case 't': /* Terse output mode */
403  complainIfNotPlainAndSet(&format, terse);
404  break;
405  case 'a': /* Wide output mode */
406  complainIfNotPlainAndSet(&format, all);
407  break;
408  case 'c': /* Callback mode */
409  request = callback;
410  break;
411  case 'd': /* Data type specification */
412  complainIfNotPlainAndSet(&format, specifiedDbr);
413  /* Argument (type) may be text or number */
414  if (sscanf(optarg, "%d", &type) != 1)
415  {
416  dbr_text_to_type(optarg, type);
417  if (type == -1) /* Invalid? Try prefix DBR_ */
418  {
419  char str[30] = "DBR_";
420  strncat(str, optarg, 25);
421  dbr_text_to_type(str, type);
422  }
423  }
424  if (type < DBR_STRING || type > DBR_CLASS_NAME
425  || type == DBR_PUT_ACKT || type == DBR_PUT_ACKS)
426  {
427  fprintf(stderr, "Requested dbr type out of range "
428  "or invalid - ignored. ('caget -h' for help.)\n");
429  format = plain;
430  }
431  break;
432  case 'n': /* Print ENUM as index numbers */
433  enumAsNr = 1;
434  break;
435  case 'w': /* Set CA timeout value */
436  if(epicsScanDouble(optarg, &caTimeout) != 1)
437  {
438  fprintf(stderr, "'%s' is not a valid timeout value "
439  "- ignored. ('caget -h' for help.)\n", optarg);
441  }
442  break;
443  case '#': /* Array count */
444  if (sscanf(optarg,"%d", &count) != 1)
445  {
446  fprintf(stderr, "'%s' is not a valid array element count "
447  "- ignored. ('caget -h' for help.)\n", optarg);
448  count = 0;
449  }
450  break;
451  case 'p': /* CA priority */
452  if (sscanf(optarg,"%u", &caPriority) != 1)
453  {
454  fprintf(stderr, "'%s' is not a valid CA priority "
455  "- ignored. ('caget -h' for help.)\n", optarg);
457  }
459  break;
460  case 's': /* Select string dbr for floating type data */
461  floatAsString = 1;
462  break;
463  case 'S': /* Treat char array as (long) string */
464  charArrAsStr = 1;
465  break;
466  case 'e': /* Select %e/%f/%g format, using <arg> digits */
467  case 'f':
468  case 'g':
469  if (sscanf(optarg, "%d", &digits) != 1)
470  fprintf(stderr,
471  "Invalid precision argument '%s' "
472  "for option '-%c' - ignored.\n", optarg, opt);
473  else
474  {
475  if (digits>=0 && digits<=VALID_DOUBLE_DIGITS)
476  sprintf(dblFormatStr, "%%-.%d%c", digits, opt);
477  else
478  fprintf(stderr, "Precision %d for option '-%c' "
479  "out of range - ignored.\n", digits, opt);
480  }
481  break;
482  case 'l': /* Convert to long and use integer format */
483  case '0': /* Select integer format */
484  switch ((char) *optarg) {
485  case 'x': outType = hex; break; /* x print Hex */
486  case 'b': outType = bin; break; /* b print Binary */
487  case 'o': outType = oct; break; /* o print Octal */
488  default :
489  outType = dec;
490  fprintf(stderr, "Invalid argument '%s' "
491  "for option '-%c' - ignored.\n", optarg, opt);
492  }
493  if (outType != dec) {
494  if (opt == '0') {
495  type = DBR_LONG;
496  outTypeI = outType;
497  } else {
498  outTypeF = outType;
499  }
500  }
501  break;
502  case 'F': /* Store this for output and tool_lib formatting */
503  fieldSeparator = (char) *optarg;
504  break;
505  case '?':
506  fprintf(stderr,
507  "Unrecognized option: '-%c'. ('caget -h' for help.)\n",
508  optopt);
509  return 1;
510  case ':':
511  fprintf(stderr,
512  "Option '-%c' requires an argument. ('caget -h' for help.)\n",
513  optopt);
514  return 1;
515  default :
516  usage();
517  return 1;
518  }
519  }
520 
521  nPvs = argc - optind; /* Remaining arg list are PV names */
522 
523  if (nPvs < 1)
524  {
525  fprintf(stderr, "No pv name specified. ('caget -h' for help.)\n");
526  return 1;
527  }
528  /* Start up Channel Access */
529 
531  if (result != ECA_NORMAL) {
532  fprintf(stderr, "CA error %s occurred while trying "
533  "to start channel access.\n", ca_message(result));
534  return 1;
535  }
536  /* Allocate PV structure array */
537 
538  pvs = calloc (nPvs, sizeof(pv));
539  if (!pvs)
540  {
541  fprintf(stderr, "Memory allocation for channel structures failed.\n");
542  return 1;
543  }
544  /* Connect channels */
545 
546  for (n = 0; optind < argc; n++, optind++)
547  pvs[n].name = argv[optind] ; /* Copy PV names from command line */
548 
549  result = connect_pvs(pvs, nPvs);
550 
551  /* Read and print data */
552  if (!result)
553  result = caget(pvs, nPvs, request, format, type, count);
554 
555  /* Shut down Channel Access */
557 
558  return result;
559 }
IntFormatT
Definition: tool_lib.h:64
RequestT
Definition: caget.c:48
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition: epicsGetopt.c:65
pvac::PutEvent result
Definition: clientSync.cpp:117
std::string request
Definition: caget.c:45
IntFormatT outTypeI
Definition: tool_lib.c:46
capri caPriority
Definition: tool_lib.c:56
char dblFormatStr[30]
Definition: tool_lib.c:49
char fieldSeparator
Definition: tool_lib.c:51
#define DEFAULT_TIMEOUT
Definition: tool_lib.h:50
int optind
Definition: epicsGetopt.c:50
#define CA_PRIORITY_MAX
Definition: cadef.h:190
Definition: tool_lib.h:67
#define printf
Definition: epicsStdio.h:41
pvd::StructureConstPtr type
#define DBR_PUT_ACKS
Definition: db_access.h:110
#define str(v)
int charArrAsStr
Definition: tool_lib.c:54
OutputT
Definition: caget.c:45
#define LINE_BUFFER(stream)
Definition: tool_lib.h:53
#define epicsScanDouble(str, to)
Definition: epicsStdlib.h:78
Definition: caget.c:45
int optopt
Definition: epicsGetopt.c:50
int epicsStdCall ca_context_create(ca_preemptive_callback_select premptiveCallbackSelect)
Definition: access.cpp:172
#define dbr_text_to_type(text, type)
Definition: db_access.h:691
#define ECA_NORMAL
Definition: caerr.h:77
#define DEFAULT_CA_PRIORITY
Definition: tool_lib.h:49
int caget(pv *pvs, int nPvs, OutputT format, chtype dbrType, unsigned long reqElems)
Definition: caput.c:128
Definition: caget.c:48
#define stdout
Definition: epicsStdio.h:30
int connect_pvs(pv *pvs, int nPvs)
Definition: tool_lib.c:621
const char *epicsStdCall ca_message(long ca_status)
Definition: access.cpp:561
const char *epicsStdCall ca_version()
Definition: access.cpp:641
#define DBR_CLASS_NAME
Definition: db_access.h:112
Definition: caget.c:45
#define DBR_LONG
Definition: db_access.h:75
#define VALID_DOUBLE_DIGITS
Definition: caget.c:41
Definition: tool_lib.h:64
Definition: tool_lib.h:64
Definition: tool_lib.h:64
#define DBR_PUT_ACKT
Definition: db_access.h:109
#define stderr
Definition: epicsStdio.h:32
Definition: tool_lib.h:64
void epicsStdCall ca_context_destroy()
Definition: access.cpp:232
int enumAsNr
Definition: tool_lib.c:53
IntFormatT outTypeF
Definition: tool_lib.c:47
char * optarg
Definition: epicsGetopt.c:55
double caTimeout
Definition: tool_lib.c:55