paulscherrerinstitute / pcaspy

Portable Channel Access Server in Python
BSD 3-Clause "New" or "Revised" License
32 stars 24 forks source link

Array size does not change in clients #56

Closed fernandohds564 closed 5 years ago

fernandohds564 commented 5 years ago

I have noticed that when the driver sets a PV value with a number of elements lower than the one defined in the 'count' property of the database definition, the clients receive an array with the same number of elements of the 'count' property, where the extra elements are all equal to zero.

I do not know if this is the expected behavior, but it seems inconvenient if we are dealing with images where the ROI size can change.

It is possible to reproduce this behavior changing the example get_random.py with the following patch:

diff --git a/example/get_random.py b/example/get_random.py
index d25c7b9..3686529 100644
--- a/example/get_random.py
+++ b/example/get_random.py
@@ -18,7 +18,8 @@ class myDriver(Driver):

     def read(self, reason):
         if reason == 'RAND':
-            value = [random.random() for i in range(10)]
+            n = random.randint(0, 10)
+            value = [random.random() for i in range(n)]
         else:
             value = self.getParam(reason)
         return value

With the IOC running, possible outputs of caget are:

lnls452-linux:~$ caget MTEST:RAND
MTEST:RAND 10 0.971484 0.711447 0.980408 0.495766 0 0 0 0 0 0
lnls452-linux:~$ caget MTEST:RAND
MTEST:RAND 10 0.96103 0.294974 0.301912 0.175557 0.0568544 0.97526 0.226363 0.992679 0.963792 0.917573
lnls452-linux:~$ caget MTEST:RAND
MTEST:RAND 10 0.155272 0 0 0 0 0 0 0 0 0

I am using the master branch of pcaspy and epics base-3.14.12.5.

xiaoqiangwang commented 5 years ago

caget by default always gets the total number of elements. Only if used with callback and pass 0 as requested count, it returns the actual number of elements.

$ caget -c -#0   MTEST:RAND
MTEST:RAND 6 0.606816 0.699592 0.462241 0.406177 0.181509 0.384086
$ caget -c -#0   MTEST:RAND
MTEST:RAND 2 0.13039 0.947962

The same as in camonitor,

$ camonitor -#0 MTEST:RAND
MTEST:RAND 2018-10-04 22:50:05.591769 0.528744 UDF INVALID
MTEST:RAND 2018-10-04 22:50:06.592780 0.904841 UDF INVALID
MTEST:RAND 2018-10-04 22:50:07.595589 7 0.418804 0.297873 0.500077 0.265413 0.150005 0.104315 0.67004 UDF INVALID
MTEST:RAND 2018-10-04 22:50:08.600529 10 0.644775 0.557583 0.755453 0.246449 0.456582 0.56066 0.637844 0.453388 0.295927 0.315301 UDF INVALID
fernandohds564 commented 5 years ago

@xiaoqiangwang, this is what I get as result:

$ camonitor -#0 MTEST:RAND
MTEST:RAND 2018-10-04 19:02:32.673686 10 0.982232 0.582003 0 0 0 0 0 0 0 0  
MTEST:RAND 2018-10-04 19:02:33.674988 10 0.667471 0.890257 0.192961 0.69467 0.611214 0.880522 0.0511692 0.0791224 0.991101 0.086747  
MTEST:RAND 2018-10-04 19:02:34.676667 10 0.247192 0.394579 0.856976 0.0156558 0.773668 0.51518 0.894203 0.67066 0 0  
MTEST:RAND 2018-10-04 19:02:35.678365 10 0.362839 0.993292 0.892241 0.888306 0.796212 0.206696 0.935661 0 0 0  
MTEST:RAND 2018-10-04 19:02:36.680024 10 0 0 0 0 0 0 0 0 0 0  

even with the -#0 flag I still get the trailing zeros

I only used caget as an example before, my real problem happens when the client is pyepics and I think pyepics always returns the actual number of elements (?).

xiaoqiangwang commented 5 years ago

I just looked up the epics-base release notes, the support of variable length array is added in base-3.14.12.6. My test is on 3.14.12.7. https://epics.anl.gov/base/R3-14/12-docs/RELEASE_NOTES.html

fernandohds564 commented 5 years ago

@xiaoqiangwang, thank you for the help. I installed epics base-3.14.12.6 and it still doesn't work. I also tried base-3.15.5 without success...

But it is clear now that the problem is not related to pcaspy. Sorry for creating this issue.

Thank you again for the fast reply and all the help!

fernandohds564 commented 5 years ago

@xiaoqiangwang my mistake.

After I installed the newer version of epics I forgot to recompile the library used by pcaspy. Now everything is working!

Thanks again!