-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathezcaIDL.pro
executable file
·3040 lines (2873 loc) · 95.6 KB
/
ezcaIDL.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;*************************************************************************
; Copyright (c) 2002 The University of Chicago, as Operator of Argonne
; National Laboratory.
; Copyright (c) 2002 The Regents of the University of California, as
; Operator of Los Alamos National Laboratory.
; This file is distributed subject to a Software License Agreement found
; in the file LICENSE that is included with this distribution.
;*************************************************************************
;*****************************************************************************
;+
; NAME:
; Release notes
; Version 2:
; Everything prior to 27-Sep-2001 when I started making release notes!
; Prior to this date there are release notes for each routine but no
; global release notes for the file.
;
; Version 3.0
; 28-Sep-2001, Mark Rivers
; Signficant rewrite. Changed many routines so that we no longer pass
; any string variables with CALL_EXTERNAL or LINKNLOAD. This was done
; to simplify things, since there are now at least 4 different conventions
; for passing strings to shareable libraries (PVWAVE, IDL prior to 5.1 on
; Windows, IDL 5.1-5.4, and IDL 5.5 and later). We now only pass byte
; arrays, not strings. This permits a single shareable library to be used
; for any version of PV-WAVE or IDL.
; There are now 2 constants in ezca_common, MAX_STRING_SIZE and
; MAX_ENUM_STATES. These values are set to 40 and 16 respectively in
; caInit. It is now MANDATORY to call caInit before calling any other
; routine in this file, preferably in the IDL_STARTUP file.
; Reformatted a lot of the code, and used ENDIF and ENDFOR consistently
; rather than simple END statements.
; Added support for unsigned short and unsigned long integer data types.
;-
function call_Ezca, routine, p1, p2, p3, p4, p5
; NAME:
; call_Ezca
;
; PURPOSE:
; This function calls the shareable image which contains the EZCA
; routines, and the short interface routines which call EZCA.
; This routine is intended only to be called internally from the
; routines in this file. This routine is needed in order to make this
; package work with both IDL and PV-WAVE, and with both Unix and VMS.
;
; CATEGORY:
; EPICS Channel Access Interface
;
; CALLING SEQUENCE:
; Status = call_Ezca(routine, p1, p2, p3, p4, p5)
;
; INPUTS:
; routine: The name of the external routine to be called
;
; OPTIONAL INPUT PARAMETERS:
; p1: The first parameter to be passed to the external routine
; p2: The second parameter to be passed to the external routine
; p3: The third parameter to be passed to the external routine
; p4: The fourth parameter to be passed to the external routine
; p5: The fifth parameter to be passed to the external routine
;
; OUTPUTS:
; The function return value of call_Ezca is the value returned from the
; external routine.
;
; COMMON BLOCKS:
; EZCA_COMMON is used to store the name of the program being run,
; the name of the shareable image, a flag which indicates if we
; are currently in an asynchronous group, and various EPICS limits
;
; PROCEDURE:
; This routine calls call_external with IDL or linknload with PV-WAVE.
; The name of the shareable image which it calls must defined with the
; logical name (VMS) or environment variable (Unix) EZCA_IDL_SHARE (for
; IDL) or EZCA_WAVE_SHARE (for PV-WAVE).
;
; MODIFICATION HISTORY:
; Written by: Mark Rivers
; June 28, 1995
; 27-Sep-2001 MLR Rewrote since IDL and PV-WAVE can now use the same
; shareable object, since no longer passing strings.
; The first time through determine if we are running IDL or PV-WAVE and set
; things up accordingly
common ezca_common, program, IDL_object, ingroup, MAX_STRING_SIZE, MAX_ENUM_STATES, MAX_PVNAME_SIZE
if (n_elements(program) eq 0) then begin
if (strpos(strupcase(!dir), 'IDL') ne -1) then program='IDL' else program='PV-WAVE'
IDL_object = getenv('EZCA_IDL_SHARE')
if IDL_object eq "" then begin
if (!version.os eq 'Win32') then base = 'ezcaIDL.dll' else base = 'libezcaIDL.so'
temp = base + '_' + !version.os + '_' + !version.arch
IDL_object = file_which(temp)
endif
;print, 'call_Ezca, shareable library = ', temp
;print, 'call_Ezca, full path = ', IDL_object
; Clear the ingroup flag if it doesn't exist yet
if (n_elements(ingroup) eq 0) then ingroup=0
endif
if (program eq 'PV-WAVE') then goto, wave
; This is for calling IDL
r = routine
case n_params() of
1: return, call_external(IDL_object, r)
2: return, call_external(IDL_object, r, p1)
3: return, call_external(IDL_object, r, p1, p2)
4: return, call_external(IDL_object, r, p1, p2, p3)
5: return, call_external(IDL_object, r, p1, p2, p3, p4)
6: return, call_external(IDL_object, r, p1, p2, p3, p4, p5)
endcase
wave:
; This is for calling PV-WAVE
r = routine
case n_params() of
1: return, linknload(IDL_object, r)
2: return, linknload(IDL_object, r, p1)
3: return, linknload(IDL_object, r, p1, p2)
4: return, linknload(IDL_object, r, p1, p2, p3)
5: return, linknload(IDL_object, r, p1, p2, p3, p4)
6: return, linknload(IDL_object, r, p1, p2, p3, p4, p5)
endcase
end
function ezcaStringToByte, str, num
;+
; NAME:
; ezcaStringToByte
;
; PURPOSE:
; This function converts an array of strings to a 2-D byte array
;
; CATEGORY:
; EPICS Channel Access Interface
;
; CALLING SEQUENCE:
; byt = ezcaStringToByte(Str, Num)
;
; INPUTS:
; Str: A 1-D array of strings. Do not use this function for EPICS PV names, use ezcaPVNameToByte below.
;
; OUTPUTS:
; This function returns a 2-D byte array [MAX_STRING_SIZE, n_elements(Str)] which
; is the input string array converted to fixed-length byte arrays.
;
; Num: Returns n_elements(Str) as a short integer
;
; COMMON BLOCKS:
; ezca_common holds the value of MAX_STRING_SIZE.
;
; EXAMPLE:
; IDL> str = ['a', 'b', 'c']
; IDL> byt = ezcaStringToByte(str, num)
; IDL> help, byt, num
; BYT BYTE = Array[40, 3]
; NUM INT = 3
;
; MODIFICATION HISTORY:
; Written by: Mark Rivers, 26-Sep-2001
; MLR 28-Nov-2001 Previous version replaced null string ("") with a single
; blank character. This was bad, unused scan record PVs were
; coming up unable to connect. Removed this replacement.
;-
common ezca_common
num = fix(n_elements(str))
byt = bytarr(MAX_STRING_SIZE, num)
for i=0,num-1 do begin
byt[0, i] = byte(str[i])
; Make sure string is null terminated
byt[MAX_STRING_SIZE-1, i] = 0
endfor
return, byt
end
function ezcaPVNameToByte, str, num
;+
; NAME:
; ezcaPVNameToByte
;
; PURPOSE:
; This function converts an array of PV names to a 2-D byte array
;
; CATEGORY:
; EPICS Channel Access Interface
;
; CALLING SEQUENCE:
; byt = ezcaPVNameToByte(Str, Num)
;
; INPUTS:
; Str: A 1-D array of EPICS PV names.
;
; OUTPUTS:
; This function returns a 2-D byte [MAX_PVNAME_SIZE, n_elements(Str)] which
; is the input string array converted to fixed-length byte arrays.
;
; Num: Returns n_elements(Str) as a short integer
;
; COMMON BLOCKS:
; ezca_common holds the value of MAX_PVNAME_SIZE.
;
; EXAMPLE:
; IDL> str = ['a', 'b', 'c']
; IDL> byt = ezcaStringToByte(str, num)
; IDL> help, byt, num
; BYT BYTE = Array[61, 3]
; NUM INT = 3
;
; MODIFICATION HISTORY:
; Written by: Mark Rivers, 11-Dec-2012. This function was added and all routines
; that previously called ezcaStringToByte for PV names were changed to use
; this function because it allows 60 character names, rather than 40.
;-
common ezca_common
num = fix(n_elements(str))
byt = bytarr(MAX_PVNAME_SIZE, num)
for i=0,num-1 do begin
byt[0, i] = byte(str[i])
; Make sure string is null terminated
byt[MAX_PVNAME_SIZE-1, i] = 0
endfor
return, byt
end
function ezcaType, value
; NAME:
; ezcaType
;
; PURPOSE:
; This function returns the EZCA data type corresponding to an IDL
; variable. It is called by caPut to determine the "type" parameter
; to be passed to ezcaPut().
;
; CATEGORY:
; EPICS Channel Access Interface
;
; CALLING SEQUENCE:
; type = ezcaType(value)
;
; INPUTS:
; value: The IDL variable whose corresponding EZCA data type is to
; be determined.
;
; OUTPUTS:
; The function returns the EZCA data type (0-5) which corresponds to the
; data type of the IDL variable. If the IDL variable is not of an allowed
; type then ezcaType() returns -1.
;
; PROCEDURE:
; Simple lookup table.
;
; RESTRICTIONS:
; The IDL variable cannot be of data type complex (6), double precision
; complex (9) or structure (8). This is because channel access has no
; equivalents for these data types.
;
; EXAMPLE:
; IDL> test1 = 0.
; IDL> type = ezcaType(test1)
; IDL> print, type
; 4
;
; MODIFICATION HISTORY:
; Written by: Mark Rivers
; June 28, 1995
type= size(value)
type = type[type[0]+1]
case type of
1: ezca_type = 0 ; Byte
2: ezca_type = 2 ; Short
3: ezca_type = 3 ; Long
4: ezca_type = 4 ; Float
5: ezca_type = 5 ; Double
7: ezca_type = 1 ; String
12: ezca_type = 2 ; Unsigned short
13: ezca_type = 2 ; Unsigned long
else: ezca_type = -1 ; Anything else
endcase
return, ezca_type
end
function caGetCountAndType, pvname, count, type
;+
; NAME:
; caGetCountAndType
;
; PURPOSE:
; This function returns the number of elements and data type of a
; Channel Access process variable.
;
; CATEGORY:
; EPICS Channel Access Interface
;
; CALLING SEQUENCE:
; Status = caGetCountAndType(pvname, count, type)
;
; INPUTS:
; pvname: The name of the process variable for which information is to
; be returned.
;
; OUTPUTS:
; count: The number of elements in the process variable. This is 1 for
; scalar process variables and more than 1 for arrays.
;
; type: This is a 3 element array containing information about the data
; type of the process variable.
; type[0] = Channel access data type as defined in "cadef.h"
; type[1] = EZCA data type as defined in "ezca.h"
; type[2] = IDL/PV-WAVE data type as defined in size()
; These data types are as follows:
;
; Name Channel Access EZCA IDL/PVWAVE
; String 0 1 7
; Short 1 2 2
; Float 2 4 4
; Enum 3 2 (short) 2 (short)
; Byte 4 0 1
; Long 5 3 3
; Double 6 5 5
;
; The function return value of caGetCountAndType is a status value. The
; status is 0 if the routine was successful (i.e. the process variable exists)
; and non-zero if the routine failed.
;
; SIDE EFFECTS:
; This routine will cause a Channel Access search to take place if this is
; the first time this process variable has been referenced.
;
; RESTRICTIONS:
; The channel access data type enum is mapped to EZCA and IDL short
; data types. However, application programs can use this routine to
; determine if the native channel access data type is enum, and then
; use caGet(pvname, value, /string) to read the string equivalent of the
; process variable. Programs can also use
; caGetEnumStrings(pvname, strings) to read the strings for the all of
; the possible values of an enum process variable.
;
; PROCEDURE:
; This routine uses ezcaPvToChid() and then ca_element_count() and
; ca_field_type().
; Note that this routine always returns its values "immediately", even
; if it is called between a caStartGroup and caEndGroup.
;
; EXAMPLE:
; IDL> status = caGetCountAndType('test_mca1.VAL', count, type)
; IDL> print, status
; 0 ; Status = success
; IDL> print, count
; 2048 ; Array with 2048 elements
; IDL> print, type
; 5 3 3 ; Long data type
; MODIFICATION HISTORY:
; Written by: Mark Rivers
; June 28, 1995
;-
ca_type = 0B
count = 0L
status = call_ezca('ezcaIDLGetCountAndType', ezcaPVNameToByte(pvname), $
count, ca_type)
if (status ne 0) then return, status
case ca_type of
0: begin ; String
wave_type = 7
ezca_type = 1
end
1: begin ; Short
wave_type = 2
ezca_type = 2
end
2: begin ; Float
wave_type = 4
ezca_type = 4
end
3: begin ; Enum
wave_type = 2 ; Short
ezca_type = 2 ; Short
end
4: begin ; Byte
wave_type = 1
ezca_type = 0
end
5: begin ; Long
wave_type = 3
ezca_type = 3
end
6: begin ; Double
wave_type = 5
ezca_type = 5
end
else: begin
wave_type = -1
ezca_type = -1
status = -1
end
endcase
type = [ca_type, wave_type, ezca_type]
return, status
end
function caGet, pvname, val, string=string, maximum_elements=max
;+
; NAME:
; caGet
;
; PURPOSE:
; This function reads the value of a Channel Access process variable.
;
; CATEGORY:
; EPICS Channel Access Interface
;
; CALLING SEQUENCE:
; Status = caGet(pvname, value, /string, max=n)
;
; INPUTS:
; pvname: The name of the process variable for which the value is to
; be returned.
;
; KEYWORD PARAMETERS:
; STRING: Set this flag to force caGet to return a string, rather than
; a number. This flag is particularly useful when the native
; channel access data type is ENUM (3), since the string is
; more descriptive than the number.
;
; MAX_ELEMENTS: This keyword parameter is used to limit the number of
; values returned by caGet. caGet normally returns the native
; element count for a process variable. Setting MAX to a
; number less than this will cause caGet to return only the
; first MAX values in the array.
;
; OUTPUTS:
; value: The value of the process variable. By default, caGet returns
; "value" with the native data type and number of elements
; of the process variable. It determines this information by
; calling caGetCountAndType(). Note that if caGet is called
; after calling caStartGroup but before calling caEndGroup then
; the IDL variable "value" is created, but will not actually
; contain the data until caEndGroup is called.
;
; The function return value of caGet is a status value. The
; status is 0 if the routine was successful (i.e. the process variable
; exists) and non-zero if the routine failed. If caGet is called from
; within an asynchronous group then the status return only indicates
; whether the operation was successfully queued.
;
; COMMON BLOCKS:
; EZCA_COMMON contains a flag (ingroup) which indicates if we
; are currently in an asynchronous group. This routine tests that flag.
;
; SIDE EFFECTS:
; This routine will causes a channel access search to take place if
; this is the first time this process variable has been referenced. It
; performs a ca_get, unless called as part of an asynchronous group.
;
; RESTRICTIONS:
; There are two important restrictions which must be kept in mind when
; calling caGet from inside a "group", i.e. after calling caStartGroup
; and before calling caEndGroup.
;
; 1) The IDL "value" variable (i.e. the second parameter
; passed to caGet) must not be "re-used" or deleted before the call to
; caEndGroup. The reason for this is that EZCA has been passed the
; address of this variable as the location in which the data is to be
; copied when caEndGroup is called. Thus, this location must still
; point to a valid memory location when caEndGroup is called.
; If the "value" variable is re-used then IDL's behavior is
; unpredictable, and bus errors/access violations could occur.
;
; 2) When using caGet to read strings, the data type returned will be
; a byte array, rather than a string. The reason has to do with the
; manner in which IDL passes strings, which requires that EZCA actually
; be passed pointers to byte arrays. When caGet is called outside of a
; group it automatically converts the byte array to a string before
; returning the value. However when caGet is called inside of a group
; it cannot perform this conversion, since it cannot be done until after
; the data is read, which does not occur until caEndGroup is called.
; Thus, it is the user's responsibility to convert the data from a byte
; array to a string after calling caEndGroup. This is done very simply
; with the string() function. For more information see the example below.
;
; PROCEDURE:
; This routine uses ezcaGet().
;
; EXAMPLES:
; IDL> ; The following is an example of a single caGet
; IDL> status = caGet('test_mca1.VAL', value)
;
; IDL> ; The following is an example of a valid grouped operation
; IDL> ; It also shows how to handle strings.
; IDL> caStartGroup
; IDL> status = caGet('test_mca1.VAL', mca_value)
; IDL> status = caGet('test_vme1.DESC', vme_desc) ; This is a string PV
; IDL> status = caEndGroup()
; IDL> vme_desc = string(vme_desc) ; Convert from byte array to string
;
; IDL> ; The following is an example of an INVALID grouped operation
; IDL> caStartGroup
; IDL> status = caGet('test_mca1.VAL', mca_value)
; IDL> status = caGet('test_vme1.VAL', vme_value)
; IDL> mca_value=0
; IDL> ; We have redefined mca_value, so the previous location is
; IDL> ; undefined. NO NOT DO THIS!
; IDL> status = caEndGroup()
;
; MODIFICATION HISTORY:
; Written by: Mark Rivers
; June 28, 1995
;-
common ezca_common
status = caGetCountAndType(pvname, nelem, type)
if (status ne 0) then return, status
type = type[2] ; The EZCA data type
if (n_elements(max) gt 0) then nelem = nelem < max
if (nelem eq 1) then begin
if (keyword_set(string)) then begin
type = 1
val = bytarr(MAX_STRING_SIZE)
endif else begin
case type of
0: val = 0B ; Byte
1: val = bytarr(MAX_STRING_SIZE) ; String
2: val = 0 ; Short
3: val = 0L ; Long
4: val = 0. ; Float
5: val = 0.D0 ; Double
endcase
endelse
endif else begin
case type of
0: val = bytarr(nelem) ; Byte
1: val = bytarr(MAX_STRING_SIZE, nelem) ; String
2: val = intarr(nelem) ; Short
3: val = lonarr(nelem) ; Long
4: val = fltarr(nelem) ; Float
5: val= dblarr(nelem) ; Double
endcase
endelse
status = call_ezca('ezcaIDLGet', ezcaPVNameToByte(pvname), byte(type), $
long(nelem), val)
if ((not ingroup) and (type eq 1)) then val = string(val)
return, status
end
function caGetTimeout
;+
; NAME:
; caGetTimeout
;
; PURPOSE:
; This function returns the value of the EZCA Timeout parameter. This
; value determines the time parameter passed to ca_pend_io() in EZCA.
; In conjunction with the EZCA RetryCount parameter it determines how
; long EZCA will try to connect to a process variable before giving up.
;
; CATEGORY:
; EPICS Channel Access Interface
;
; CALLING SEQUENCE:
; timeout = caGetTimeout()
;
; INPUTS:
; None.
;
; OUTPUTS:
; The function return value of caGetTimeout is the floating point
; value of the EZCA Timeout parameter, in seconds.
;
; PROCEDURE:
; This routine uses ezcaGetTimeout().
;
; EXAMPLES:
; IDL> print, caGetTimeout()
; 0.0500000
;
; MODIFICATION HISTORY:
; Written by: Mark Rivers
; June 28, 1995
;-
timeout = 0.
status = call_ezca('ezcaIDLGetTimeout', timeout)
return, timeout
end
pro caSetTimeout, timeout
;+
; NAME:
; caSetTimeout
;
; PURPOSE:
; This procedure sets the value of the EZCA Timeout parameter. This
; value determines the time parameter passed to ca_pend_io() in EZCA.
; In conjunction with the EZCA RetryCount parameter it determines how
; long EZCA will try to connect to a process variable before giving up.
;
; CATEGORY:
; EPICS Channel Access Interface
;
; CALLING SEQUENCE:
; caSetTimeout, timeout
;
; INPUTS:
; Timeout: The timeout value in seconds (floating point).
;
; OUTPUTS:
; None
;
; PROCEDURE:
; This routine uses ezcaSetTimeout().
;
; EXAMPLES:
; IDL> caSetTimeout, .001
;
; MODIFICATION HISTORY:
; Written by: Mark Rivers
; June 28, 1995
;-
status = call_ezca('ezcaIDLSetTimeout', float(timeout))
end
function caGetRetryCount
;+
; NAME:
; caGetRetryCount
;
; PURPOSE:
; This function returns the value of the EZCA retry count parameter.
; In conjunction with the EZCA Timeout parameter it determines how
; long EZCA will try to connect to a process variable before giving up.
;
; CATEGORY:
; EPICS Channel Access Interface
;
; CALLING SEQUENCE:
; RetryCount = caGetRetryCount()
;
; INPUTS:
; None.
;
; OUTPUTS:
; The function return value of caGetRetryCount is the integer
; value of the EZCA RetryCount parameter.
;
; PROCEDURE:
; This routine uses ezcaGetRetryCount().
;
; EXAMPLES:
; IDL> print, caGetRetryCount()
; 599
;
; MODIFICATION HISTORY:
; Written by: Mark Rivers
; June 28, 1995
;-
count = 0L
status = call_ezca('ezcaIDLGetRetryCount', count)
return, count
end
pro caSetRetryCount, retryCount
;+
; NAME:
; caSetRetryCount
;
; PURPOSE:
; This procedure sets the value of the EZCA RetryCount parameter.
; In conjunction with the EZCA Timeout parameter it determines how
; long EZCA will try to connect to a process variable before giving up.
;
; CATEGORY:
; EPICS Channel Access Interface
;
; CALLING SEQUENCE:
; caSetRetryCount, retrycount
;
; INPUTS:
; RetryCount: The integer retry count.
;
; OUTPUTS:
; None
;
; PROCEDURE:
; This routine uses ezcaSetRetryCount().
;
; EXAMPLES:
; IDL> caSetRetryCount, 100
;
; MODIFICATION HISTORY:
; Written by: Mark Rivers
; June 28, 1995
;-
status = call_ezca('ezcaIDLSetRetryCount', long(retryCount))
end
function caPut, name, value, wait=wait
;+
; NAME:
; caPut
;
; PURPOSE:
; This procedure writes a new value to a channel access process variable.
;
; CATEGORY:
; EPICS Channel Access Interface
;
; CALLING SEQUENCE:
; status = caPut(pvname, value)
;
; INPUTS:
; pvname: The name of the process variable for which the new value
; is to be written
;
; value: The new value to be written. In general this can be a scalar
; or array of any data type. There are of course restrictions
; in that certain strings cannot be written to certain process
; variables, and some process variables cannot be passed arrays.
;
; KEYWORD PARAMETERS:
; WAIT: Set this flag to force caPut to wait for a channel access
; callback. The default is not to wait for a callback, using the
; ezca function ezcaPutOldCa. The WAIT keyword results in a
; call to ezcaPut, which uses channel access callbacks.
;
; OUTPUTS:
; The function return value of caPut is a status value. The
; status is 0 if the routine was successful (i.e. the process variable
; exists and a valid value was written) and non-zero if the routine
; failed.
;
; PROCEDURE:
; This routine uses ezcaPut() if /WAIT is specified, and ezcaPutOldCa if
; /WAIT is not specified. The "nelem" and "type" parameters passed
; to ezcaPut are determined from the IDL data type and number of elements
; of the "value" parameter passed to caPut(). Strings are converted to
; to byte arrays before being passed.
;
; RESTRICTIONS:
; None. caPut can be called inside a group, i.e. after calling
; caStartGroup and before calling caEndGroup. The "value"
; variable passed to caPut can be immediately re-used when
; inside a group, since EZCA copies it to a private location.
;
; EXAMPLES:
; IDL> ; Put a linear ramp (findgen()) to a waveform process variable.
; IDL> status = caPut('my_waveform.VAL', findgen(100))
;
; MODIFICATION HISTORY:
; Written by: Mark Rivers
; June 28, 1995
; Sept. 16, 1998 Mark Rivers Added WAIT keyword, made non-callback
; version of caput the default
;-
common ezca_common
nelem = n_elements(value)
if (nelem eq 0) then return, -1 ; Variable not defined
type = ezcatype(value)
if (type eq 1) then begin ; Convert strings to byte arrays
temp = ezcaStringToByte(value)
if (keyword_set(wait)) then begin
status = call_ezca('ezcaIDLPut', ezcaPVNameToByte(name), $
byte(type), long(nelem), temp)
endif else begin
status = call_ezca('ezcaIDLPutOldCa', ezcaPVNameToByte(name), $
byte(type), long(nelem), temp)
endelse
endif else begin
if (keyword_set(wait)) then begin
status = call_ezca('ezcaIDLPut', ezcaPVNameToByte(name), $
byte(type), long(nelem), value)
endif else begin
status = call_ezca('ezcaIDLPutOldCa', ezcaPVNameToByte(name), $
byte(type), long(nelem), value)
endelse
endelse
return, status
end
pro caStartGroup
;+
; NAME:
; caStartGroup
;
; PURPOSE:
; This procedure starts an "asynchronous group". Within an asynchronous
; group all calls to caGet and caPut are asynchronous, i.e. they queue
; a request and return immediately without waiting for a reply from
; the channel access servers. Calling caEndGroup causes the queue to be
; flushed and waits for the replies. The use of asynchronous
; groups can greatly improve the efficiency of channel access. The user
; must be aware of the restrictions on caGet outlined under the
; description of that routine.
;
; CATEGORY:
; EPICS Channel Access Interface
;
; CALLING SEQUENCE:
; caStartGroup
;
; INPUTS:
; None.
;
; OUTPUTS:
; None
;
; COMMON BLOCKS:
; EZCA_COMMON contains a flag (ingroup) which indicates if we
; are currently in an asynchronous group. This routine sets that flag.
;
; PROCEDURE:
; This routine uses ezcaStartGroup().
;
; EXAMPLES:
; IDL> caStartGroup
; IDL> status = caget('test_ao1.SCAN', scan)
; IDL> status = caget('test_mca1.ERTM', ertm)
; IDL> ; Print out values - they will be zero.
; IDL> help, scan, ertm
; IDL> status = caEndGroup()
; IDL> ; Print out values after executing caEndGroup, they are non-zero
; IDL> help, scan, ertm
; Output:
; SCAN INT = 0
; ERTM FLOAT = 0.000000
; SCAN INT = 6
; ERTM FLOAT = 7.10000
;
; MODIFICATION HISTORY:
; Written by: Mark Rivers
; June 28, 1995
;-
common ezca_common
ingroup = 1
status = call_ezca('ezcaIDLStartGroup')
end
function caEndGroup, status
;+
; NAME:
; caEndGroup
;
; PURPOSE:
; This function ends an "asynchronous group". See caStartGroup for more
; information on asynchronous groups.
; caEndGroup flushes the queue of caGet and caPut calls and waits for
; replies from the channel access servers.
;
; CATEGORY:
; EPICS Channel Access Interface
;
; CALLING SEQUENCE:
; stat = caEndGroup(status)
;
; INPUTS:
; None.
;
; OUTPUTS:
; The function return value is 0 if the operation was successful,
; otherwise it is the first encountered non-successful return code.
; The optional status parameter can be used to return the status code
; of each operation in the group.
;
; OPTIONAL OUTPUT PARAMETERS:
; status: If this optional parameter is present then it returns a
; array of status information, one for each channel access
; call in the group.
;
; COMMON BLOCKS:
; EZCA_COMMON contains a flag (ingroup) which indicates if we
; are currently in an asynchronous group. This routine clears that flag.
;
; PROCEDURE:
; If the status parameter is present then this routine uses
; ezcaEndGroupWithReport(). If the parameter is not present then
; the routine calls ezcaEndGroup().
;
; RESTRICTIONS:
; When the status parameter is present, and ezcaEndGroupWithReport() is
; called, there is no way to know in advance how many status values
; will be returned. This routine passes a status array with 1024
; elements, and then truncates it to the actual length. The maximum
; number of status values which can be retrieved is thus 1024. No errors
; will occur if an asynchronous group has more than 1024 calls, but
; only the first 1024 status values can be obtained.
; This is probably sufficient for most applications!
;
; EXAMPLES:
; IDL> caStartGroup
; IDL> status = caget('test_ao1.SCAN', scan)
; IDL> status = caget('test_mca1.ERTM', ertm)
; IDL> ; Print out values - they will be zero.
; IDL> help, scan, ertm
; IDL> status = caEndGroup()
; IDL> ; Print out values after executing caEndGroup, they are non-zero
; IDL> help, scan, ertm
; Output:
; SCAN INT = 0
; ERTM FLOAT = 0.000000
; SCAN INT = 6
; ERTM FLOAT = 7.10000
;
; MODIFICATION HISTORY:
; Written by: Mark Rivers
; June 28, 1995
;-
common ezca_common
ingroup = 0
if (n_params() eq 0) then begin
return, call_ezca('ezcaIDLEndGroup')
endif else begin
nvals = 1024L
status = lonarr(nvals)
stat = call_ezca('ezcaIDLEndGroupWithReport', nvals, status)
status = status[0:nvals-1]
return, stat
endelse
end
function caSetMonitor, pvname, count
;+
; NAME:
; caSetMonitor
;
; PURPOSE:
; This procedure sets a monitor on the specified process variable.
; This causes a channel access callback to execute whenever the value
; of that process variable changes. Subsequent calls to caGet() after
; calling caSetMonitor will read the values provided by the callbacks,
; rather than reading from the IOC.
;
; CATEGORY:
; EPICS Channel Access Interface
;
; CALLING SEQUENCE:
; status = caSetMonitor(pvname)
;
; INPUTS:
; pvname: The name of the process variable on which to set the monitor.
; count: The maximum number of elements to monitor. Default (0) is native element count
;
; OUTPUTS:
; The function return value of caSetMonitor is a status value. The
; status is 0 if the routine was successful (i.e. the process variable
; exists) and non-zero if the routine failed.
;
; PROCEDURE:
; This routine uses ezcaSetMonitor(). The "type" parameter required
; by ezcaSetMonitor is the native EZCA data type as determined
; by caGetCountAndType().
;
; EXAMPLES:
; IDL> status = caSetMonitor('test_ao1')
; IDL> status = caGet('test_ao1', value)
;
; MODIFICATION HISTORY:
; Written by: Mark Rivers
; June 28, 1995
;-
status = caGetCountAndType(pvname, cnt, type)
if (n_elements(count) eq 0) then count = 0
if (status ne 0) then return, status
status = call_ezca('ezcaIDLSetMonitor', ezcaPVNameToByte(pvname), $
byte(type[2]), long(count))
return, status
end