diff --git a/src/ca/CAref.html b/src/ca/CAref.html index 57919150d..48d6a5b2f 100644 --- a/src/ca/CAref.html +++ b/src/ca/CAref.html @@ -877,6 +877,81 @@ example "dbr_short_t" should be used to send or receive type DBR_SHORT.
+ + +Channel value arrays can also be included within the structured CA data +types. If more than one element is requested, then the individual elements +can be accessed in an application program by indexing a pointer to the value +field in the DBR_XXX structure. For example, the following code computes the +sum of the elements in a array process variable and prints its time stamp. +The dbr_size_n function can be used to detrmine the +correct number of bytes to reserve when there are more than one value field +elements in a structured CA data type.
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "cadef.h"
+
+int main ( int argc, char ** argv )
+{
+ struct dbr_time_double * pTD;
+ const dbr_double_t * pValue;
+ unsigned nBytes;
+ unsigned elementCount;
+ char timeString[32];
+ unsigned i;
+ chid chan;
+ double sum;
+ int status;
+
+ if ( argc != 2 ) {
+ fprintf ( stderr, "usage: %s <channel name>", argv[0] );
+ return -1;
+ }
+
+ status = ca_create_channel ( argv[1], 0, 0, 0, & chan );
+ SEVCHK ( status, "ca_create_channel()" );
+ status = ca_pend_io ( 15.0 );
+ if ( status != ECA_NORMAL ) {
+ fprintf ( stderr, "\"%s\" not found.\n", argv[1] );
+ return -1;
+ }
+
+ elementCount = ca_element_count ( chan );
+ nBytes = dbr_size_n ( DBR_TIME_DOUBLE, elementCount );
+ pTD = ( struct dbr_time_double * ) malloc ( nBytes );
+ if ( ! pTD ) {
+ fprintf ( stderr, "insufficent memory to complete request\n" );
+ return -1;
+ }
+
+ status = ca_array_get ( DBR_TIME_DOUBLE, elementCount, chan, pTD );
+ SEVCHK ( status, "ca_array_get()" );
+ status = ca_pend_io ( 15.0 );
+ if ( status != ECA_NORMAL ) {
+ fprintf ( stderr, "\"%s\" didnt return a value.\n", argv[1] );
+ return -1;
+ }
+
+ pValue = & pTD->value;
+ sum = 0.0;
+ for ( i = 0; i < elementCount; i++ ) {
+ sum += pValue[i];
+ }
+
+ epicsTimeToStrftime ( timeString, sizeof ( timeString ),
+ "%a %b %d %Y %H:%M:%S.%f", & pTD->stamp );
+
+ printf ( "The sum of elements in %s at %s was %f\n",
+ argv[1], timeString, sum );
+
+ ca_clear_channel ( chan );
+ ca_task_exit ();
+ free ( pTD );
+
+ return 0;
+}
+
Certain CA client initiated requests asynchronously execute an application @@ -889,17 +964,24 @@ returned. The field "status" will be set to one of the CA error codes in caerr.h and will indicate the status of the operation performed in the IOC. If the status field isn't set to ECA_NORMAL or data isn't normally returned from the operation (i.e. put call back) then you should expect that the field -"dbr" will be set to NULL. The fields "usr", "chid", "type", and "count" are -set to the values specified when the operation was initiated by the -application.
+"dbr" will be set to NULL. The fields "usr", "chid", and "type" are set to +the values specified when the request was made by the application.struct event_handler_args {
- void *usr; /* user argument supplied when event added */
- chid chid; /* channel id */
- long type; /* dbr type of the value returned */
- long count; /* element count of the item(s) returned */
- void *dbr; /* pointer to the value returned */
- int status; /* ECA_XXX status of the op from server */
-};
+ void *usr; /* user argument supplied when event added */
+ chid chid; /* channel id */
+ long type; /* dbr type of the value returned */
+ long count; /* element count of the item(s) returned */
+ const void *dbr; /* pointer to the value returned */
+ int status; /* ECA_XXX status of the op from server */
+};
+
+void myCallback ( struct event_handler_args args )
+{
+ if ( type == DBR_TIME_DOUBLE ) {
+ const struct dbr_time_double * pTD =
+ ( const struct dbr_time_double * ) args.dbr;
+ }
+}
PCHID