36 #include <epicsGetopt.h> 37 #include "epicsVersion.h" 41 #define VALID_DOUBLE_DIGITS 18 42 #define PEND_EVENT_SLICES 5 52 static int floatAsString = 0;
55 static void usage (
void)
57 fprintf (
stderr,
"\nUsage: caget [options] <PV name> ...\n\n" 58 " -h: Help: Print this message\n" 59 " -V: Version: Show EPICS and CA versions\n" 60 "Channel Access options:\n" 61 " -w <sec>: Wait time, specifies CA timeout, default is %f second(s)\n" 62 " -c: Asynchronous get (use ca_get_callback and wait for completion)\n" 63 " -p <prio>: CA priority (0-%u, default 0=lowest)\n" 65 " Default output format is \"name value\"\n" 66 " -t: Terse mode - print only value, without name\n" 67 " -a: Wide mode \"name timestamp value stat sevr\" (read PVs as DBR_TIME_xxx)\n" 68 " -d <type>: Request specific dbr type; use string (DBR_ prefix may be omitted)\n" 69 " or number of one of the following types:\n" 70 " DBR_STRING 0 DBR_STS_FLOAT 9 DBR_TIME_LONG 19 DBR_CTRL_SHORT 29\n" 71 " DBR_INT 1 DBR_STS_ENUM 10 DBR_TIME_DOUBLE 20 DBR_CTRL_INT 29\n" 72 " DBR_SHORT 1 DBR_STS_CHAR 11 DBR_GR_STRING 21 DBR_CTRL_FLOAT 30\n" 73 " DBR_FLOAT 2 DBR_STS_LONG 12 DBR_GR_SHORT 22 DBR_CTRL_ENUM 31\n" 74 " DBR_ENUM 3 DBR_STS_DOUBLE 13 DBR_GR_INT 22 DBR_CTRL_CHAR 32\n" 75 " DBR_CHAR 4 DBR_TIME_STRING 14 DBR_GR_FLOAT 23 DBR_CTRL_LONG 33\n" 76 " DBR_LONG 5 DBR_TIME_INT 15 DBR_GR_ENUM 24 DBR_CTRL_DOUBLE 34\n" 77 " DBR_DOUBLE 6 DBR_TIME_SHORT 15 DBR_GR_CHAR 25 DBR_STSACK_STRING 37\n" 78 " DBR_STS_STRING 7 DBR_TIME_FLOAT 16 DBR_GR_LONG 26 DBR_CLASS_NAME 38\n" 79 " DBR_STS_SHORT 8 DBR_TIME_ENUM 17 DBR_GR_DOUBLE 27\n" 80 " DBR_STS_INT 8 DBR_TIME_CHAR 18 DBR_CTRL_STRING 28\n" 82 " -n: Print DBF_ENUM value as number (default is enum string)\n" 83 "Arrays: Value format: print number of requested values, then list of values\n" 84 " Default: Print all values\n" 85 " -# <count>: Print first <count> elements of an array\n" 86 " -S: Print array of char as a string (long string)\n" 87 "Floating point type format:\n" 88 " Default: Use %%g format\n" 89 " -e <nr>: Use %%e format, with a precision of <nr> digits\n" 90 " -f <nr>: Use %%f format, with a precision of <nr> digits\n" 91 " -g <nr>: Use %%g format, with a precision of <nr> digits\n" 92 " -s: Get value as string (honors server-side precision)\n" 93 " -lx: Round to long integer and print as hex number\n" 94 " -lo: Round to long integer and print as octal number\n" 95 " -lb: Round to long integer and print as binary number\n" 96 "Integer number format:\n" 97 " Default: Print as decimal number\n" 98 " -0x: Print as hex number\n" 99 " -0o: Print as octal number\n" 100 " -0b: Print as binary number\n" 101 "Alternate output field separator:\n" 102 " -F <ofs>: Use <ofs> as an alternate output field separator\n" 103 "\nExample: caget -a -f8 my_channel another_channel\n" 104 " (uses wide output format, doubles are printed as %%f with precision of 8)\n\n" 157 chtype dbrType,
unsigned long reqElems)
162 for (n = 0; n < nPvs; n++) {
163 unsigned long nElems;
182 else if (floatAsString &&
199 pvs[n].
reqElems = reqElems > nElems ? nElems : reqElems;
207 pvs[n].
nElems = reqElems && reqElems < nElems ? reqElems : nElems;
210 fprintf(
stderr,
"Memory allocation failed\n");
223 if (!nConn)
return 1;
230 fprintf(
stderr,
"Read operation timed out: some PV data was not read.\n");
240 if (nRead >= nConn)
break;
243 fprintf(
stderr,
"Read operation timed out: some PV data was not read.\n");
246 while (nRead < nConn) {
255 for (n = 0; n < nPvs; n++) {
260 else printf(
"%s", pvs[n].name);
264 printf(
"*** not connected\n");
266 printf(
"*** no read access\n");
269 else if (pvs[n].
value == 0)
270 printf(
"*** no data available (timeout)\n");
276 char *d = calloc(dlen+1,
sizeof(
char));
282 fprintf(
stderr,
"Failed to allocate space for escaped string\n");
286 for (i=0; i<pvs[n].
nElems; ++
i) {
298 printf(
"%s\n", pvs[n].name);
300 printf(
" *** not connected\n");
302 printf(
" *** no read access\n");
307 printf(
" Native data type: %s\n",
309 printf(
" Request type: %s\n",
312 printf(
" Class Name: %s\n",
316 printf(
" Element count: %lu\n" 322 char *d = calloc(dlen+1,
sizeof(
char));
328 fprintf(
stderr,
"Failed to allocate space for escaped string\n");
331 for (i=0; i<pvs[n].
nElems; ++
i) {
367 static void complainIfNotPlainAndSet (
OutputT *current,
const OutputT requested)
369 if (*current !=
plain)
371 "Options t,d,a are mutually exclusive. " 372 "('caget -h' for help.)\n");
373 *current = requested;
376 int main (
int argc,
char *argv[])
394 while ((opt =
getopt(argc, argv,
":taicnhsSVe:f:g:l:#:d:0:w:p:F:")) != -1) {
400 printf(
"\nEPICS Version %s, CA Protocol version %s\n", EPICS_VERSION_STRING,
ca_version() );
403 complainIfNotPlainAndSet(&format,
terse);
406 complainIfNotPlainAndSet(&format,
all);
414 if (sscanf(
optarg,
"%d", &type) != 1)
419 char str[30] =
"DBR_";
427 fprintf(
stderr,
"Requested dbr type out of range " 428 "or invalid - ignored. ('caget -h' for help.)\n");
438 fprintf(
stderr,
"'%s' is not a valid timeout value " 439 "- ignored. ('caget -h' for help.)\n",
optarg);
444 if (sscanf(
optarg,
"%d", &count) != 1)
446 fprintf(
stderr,
"'%s' is not a valid array element count " 447 "- ignored. ('caget -h' for help.)\n",
optarg);
454 fprintf(
stderr,
"'%s' is not a valid CA priority " 455 "- ignored. ('caget -h' for help.)\n",
optarg);
469 if (sscanf(
optarg,
"%d", &digits) != 1)
471 "Invalid precision argument '%s' " 472 "for option '-%c' - ignored.\n",
optarg, opt);
478 fprintf(
stderr,
"Precision %d for option '-%c' " 479 "out of range - ignored.\n", digits, opt);
485 case 'x': outType =
hex;
break;
486 case 'b': outType =
bin;
break;
487 case 'o': outType =
oct;
break;
490 fprintf(
stderr,
"Invalid argument '%s' " 491 "for option '-%c' - ignored.\n", optarg, opt);
493 if (outType !=
dec) {
507 "Unrecognized option: '-%c'. ('caget -h' for help.)\n",
512 "Option '-%c' requires an argument. ('caget -h' for help.)\n",
525 fprintf(
stderr,
"No pv name specified. ('caget -h' for help.)\n");
532 fprintf(
stderr,
"CA error %s occurred while trying " 533 "to start channel access.\n",
ca_message(result));
538 pvs = calloc (nPvs,
sizeof(
pv));
541 fprintf(
stderr,
"Memory allocation for channel structures failed.\n");
546 for (n = 0; optind < argc; n++, optind++)
547 pvs[n].name = argv[optind] ;
553 result =
caget(pvs, nPvs, request, format, type, count);
int getopt(int nargc, char *const *nargv, const char *ostr)
#define dbr_type_is_ENUM(type)
LIBCA_API int epicsStdCall ca_array_get_callback(chtype type, unsigned long count, chid chanId, caEventCallBackFunc *pFunc, void *pArg)
#define dbf_type_to_text(type)
size_t epicsStrnEscapedFromRawSize(const char *src, size_t srclen)
LIBCA_API unsigned long epicsStdCall ca_element_count(chid chan)
LIBCA_API enum channel_state epicsStdCall ca_state(chid chan)
int epicsStdCall ca_pend_io(ca_real timeout)
pvd::StructureConstPtr type
#define PEND_EVENT_SLICES
#define epicsScanDouble(str, to)
LIBCA_API short epicsStdCall ca_field_type(chid chan)
#define dbr_type_is_CHAR(type)
#define dbr_type_to_text(type)
#define dbr_value_ptr(PDBR, DBR_TYPE)
int epicsStdCall ca_context_create(ca_preemptive_callback_select premptiveCallbackSelect)
int epicsStdCall ca_pend_event(ca_real timeout)
int main(int argc, char *argv[])
#define dbr_text_to_type(text, type)
int caget(pv *pvs, int nPvs, OutputT format, chtype dbrType, unsigned long reqElems)
LIBCA_API int epicsStdCall ca_array_get(chtype type, unsigned long count, chid chanId, void *pValue)
void event_handler(struct event_handler_args args)
epicsOldString dbr_string_t
const char *epicsStdCall ca_message(long ca_status)
const char *epicsStdCall ca_version()
#define VALID_DOUBLE_DIGITS
#define dbr_size_n(TYPE, COUNT)
#define dbr_type_is_FLOAT(type)
#define dbr_type_is_DOUBLE(type)
void epicsStdCall ca_context_destroy()
int epicsStrnEscapedFromRaw(char *dst, size_t dstlen, const char *src, size_t srclen)
#define dbf_type_to_DBR_TIME(type)