paulscherrerinstitute / pcaspy

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

ca_array_get_callback with `0` request count always returns 11 elements #43

Closed xiaoqiangwang closed 7 years ago

xiaoqiangwang commented 7 years ago

Use the dummy.py example,

$ python dummy.py

And then run the following script, using the tip of caffi module. Notice that the "get with callback" version prints an array of 11 elements, while the other 2 prints a scalar value.

from caffi import ca
from pprint import pprint

status, chid = ca.create_channel('MTEST:RAND')
assert status == ca.ECA.NORMAL

status = ca.pend_io(3)
assert status == ca.ECA.NORMAL

def getCB(args):
    print('=== get with callback ===')
    pprint(args['value'])

# get with callback
status, dbr = ca.get(chid, chtype=ca.DBR_CTRL_DOUBLE, count=0, callback=getCB)
assert status == ca.ECA.NORMAL

ca.pend_event(2)

# get without callback
status, dbr = ca.get(chid, chtype=ca.DBR_CTRL_DOUBLE, count=0)
assert status == ca.ECA.NORMAL

status = ca.pend_io(3)
assert status == ca.ECA.NORMAL

print('=== get w/o callback ===')
pprint(dbr.get())

def monCB(args):
    print('=== monitor callback ===')
    pprint(args['value'])

# monitor
status, evid = ca.create_subscription(chid, chtype=ca.DBR_CTRL_DOUBLE, count=0, callback=monCB)
assert status == ca.ECA.NORMAL

ca.pend_event(2)
xiaoqiangwang commented 7 years ago

This commit in pcas module has fixed the issue.

This is the same fix when the requested count is 0 in ca_create_subscription.

This problem has not been discovered so far probably because it is seldom to pass 0 to ca_array_get_callback. And it results error when calling ca_array_get.

xiaoqiangwang commented 7 years ago

0.6.5 has been released with binary packages updated on PyPI and Anaconda.