37 #include <epicsGetopt.h> 40 #include "epicsVersion.h" 44 #define VALID_DOUBLE_DIGITS 18 60 fprintf (
stderr,
"\nUsage: caput [options] <PV name> <PV value> ...\n" 61 " caput -a [options] <PV name> <no of values> <PV value> ...\n\n" 62 " -h: Help: Print this message\n" 63 " -V: Version: Show EPICS and CA versions\n" 64 "Channel Access options:\n" 65 " -w <sec>: Wait time, specifies CA timeout, default is %f second(s)\n" 66 " -c: Asynchronous put (use ca_put_callback and wait for completion)\n" 67 " -p <prio>: CA priority (0-%u, default 0=lowest)\n" 69 " -t: Terse mode - print only sucessfully written value, without name\n" 70 " -l: Long mode \"name timestamp value stat sevr\" (read PVs as DBR_TIME_xxx)\n" 72 " Default: Auto - try value as ENUM string, then as index number\n" 73 " -n: Force interpretation of values as numbers\n" 74 " -s: Force interpretation of values as strings\n" 76 " Default: Put scalar\n" 77 " Value format: all value arguments concatenated with spaces\n" 78 " -S: Put string as an array of chars (long string)\n" 80 " Value format: number of values, then list of values\n" 81 "Alternate output field separator:\n" 82 " -F <ofs>: Use <ofs> as an alternate output field separator\n" 83 "\nExample: caput my_channel 1.2\n" 84 " (puts 1.2 to my_channel)\n\n" 129 chtype dbrType,
unsigned long reqElems)
134 for (n = 0; n < nPvs; n++) {
152 if (reqElems == 0 || pvs[n].nElems < reqElems)
167 fprintf(
stderr,
"Allocation failed\n");
179 if (!nConn)
return 1;
186 fprintf(
stderr,
"Read operation timed out: PV data was not read.\n");
191 for (n = 0; n < nPvs; n++) {
196 else printf(
"%s", pvs[n].name);
200 printf(
"*** not connected\n");
202 printf(
"*** no read access\n");
205 else if (pvs[n].
value == 0)
206 printf(
"*** no data available (timeout)\n");
212 char *d = calloc(dlen+1,
sizeof(
char));
214 fprintf(
stderr,
"Allocation failed\n");
258 int main (
int argc,
char *argv[])
265 int enumAsString = 0;
284 putenv(
"POSIXLY_CORRECT=");
286 while ((opt =
getopt(argc, argv,
":cnlhatsVS#:w:p:F:")) != -1) {
292 printf(
"\nEPICS Version %s, CA Protocol version %s\n", EPICS_VERSION_STRING,
ca_version() );
322 fprintf(
stderr,
"'%s' is not a valid timeout value " 323 "- ignored. ('caput -h' for help.)\n",
optarg);
328 if (sscanf(
optarg,
"%d", &count) != 1)
330 fprintf(
stderr,
"'%s' is not a valid array element count " 331 "- ignored. ('caput -h' for help.)\n",
optarg);
338 fprintf(
stderr,
"'%s' is not a valid CA priority " 339 "- ignored. ('caget -h' for help.)\n",
optarg);
349 "Unrecognized option: '-%c'. ('caput -h' for help.)\n",
354 "Option '-%c' requires an argument. ('caput -h' for help.)\n",
366 fprintf(
stderr,
"No pv name specified. ('caput -h' for help.)\n");
370 fprintf(
stderr,
"No value specified. ('caput -h' for help.)\n");
382 fprintf(
stderr,
"CA error %s occurred while trying " 383 "to start channel access.\n",
ca_message(result));
388 pvs = calloc (nPvs,
sizeof(
pv));
390 fprintf(
stderr,
"Memory allocation for channel structure failed.\n");
413 for (i = optind; i < argc; i++) {
414 len += strlen(argv[i]);
417 cbuf = calloc(len,
sizeof(
char));
419 fprintf(
stderr,
"Memory allocation failed.\n");
422 strcpy(cbuf, argv[optind]);
424 if (argc > optind+1) {
425 for (i = optind + 1; i < argc; i++) {
427 strcat(cbuf, argv[i]);
431 if ((argc - optind) >= 1)
436 sbuf = calloc (count,
sizeof(
EpicsStr));
437 dbuf = calloc (count,
sizeof(
double));
439 fprintf(
stderr,
"Memory allocation failed\n");
452 fprintf(
stderr,
"Read operation timed out: ENUM data was not read.\n");
458 for (i = 0; i < count; ++
i) {
460 if (*(argv+optind+i) == pend) {
461 fprintf(
stderr,
"Enum index value '%s' is not a number.\n",
465 if (dbuf[i] >= bufGrEnum.
no_str) {
466 fprintf(
stderr,
"Warning: enum index value '%s' may be too large.\n",
474 for (i = 0; i < count; ++
i) {
480 for (len = 0; len < bufGrEnum.
no_str; len++)
481 if (!strcmp(sbuf[i], bufGrEnum.
strs[len]))
484 if (len >= bufGrEnum.
no_str) {
487 if (sbuf[i] == pend || enumAsString) {
488 fprintf(
stderr,
"Enum string value '%s' invalid.\n", sbuf[i]);
491 if (dbuf[i] >= bufGrEnum.
no_str) {
492 fprintf(
stderr,
"Warning: enum index value '%s' may be too large.\n", sbuf[i]);
503 ebuf = calloc(len,
sizeof(
char));
505 fprintf(
stderr,
"Memory allocation failed\n");
510 for (i = 0; i < count; ++
i) {
519 if (format !=
terse) {
521 result =
caget(pvs, nPvs, format, 0, 0);
526 else if (dbrType ==
DBR_CHAR) pbuf = ebuf;
536 result =
ca_array_put (dbrType, count, pvs[0].chid, pbuf);
545 fprintf(
stderr,
"Write operation timed out: Data was not written.\n");
551 fprintf(
stderr,
"Write callback operation timed out\n");
566 result =
caget(pvs, nPvs, format, 0, 0);
int getopt(int nargc, char *const *nargv, const char *ostr)
#define dbr_type_is_ENUM(type)
size_t epicsStrnEscapedFromRawSize(const char *src, size_t srclen)
LIBCA_API int epicsStdCall ca_array_put_callback(chtype type, unsigned long count, chid chanId, const void *pValue, caEventCallBackFunc *pFunc, void *pArg)
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)
LIBCOM_API epicsEventStatus epicsEventWaitWithTimeout(epicsEventId id, double timeOut)
Wait an the event or until the specified timeout period is over.
#define epicsScanDouble(str, to)
LIBCA_API short epicsStdCall ca_field_type(chid chan)
#define dbr_type_is_CHAR(type)
#define dbr_value_ptr(PDBR, DBR_TYPE)
int epicsStdCall ca_context_create(ca_preemptive_callback_select premptiveCallbackSelect)
#define epicsEventSignal(ID)
A synonym for epicsEventTrigger().
LIBCA_API int epicsStdCall ca_array_put(chtype type, unsigned long count, chid chanId, const void *pValue)
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)
int main(int argc, char *argv[])
APIs for the epicsEvent binary semaphore.
const char *epicsStdCall ca_message(long ca_status)
const char *epicsStdCall ca_version()
#define dbr_size_n(TYPE, COUNT)
char EpicsStr[MAX_STRING_SIZE]
void epicsStdCall ca_context_destroy()
void put_event_handler(struct event_handler_args args)
LIBCOM_API epicsEventId epicsEventCreate(epicsEventInitialState initialState)
Create an epicsEvent for use from C code, or return NULL.
int epicsStrnEscapedFromRaw(char *dst, size_t dstlen, const char *src, size_t srclen)
int epicsStrnRawFromEscaped(char *dst, size_t dstlen, const char *src, size_t srclen)
char strs[MAX_ENUM_STATES][MAX_ENUM_STRING_SIZE]
#define dbf_type_to_DBR_TIME(type)