paulscherrerinstitute / pcaspy

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

PVInfo._checkNumericAlarm does not work properly with arrays #52

Closed fernandohds564 closed 6 years ago

fernandohds564 commented 6 years ago

If a PV array such as this one:

'TEST': {
        'type': 'int', 'count': 30, 'value': 30*[1],
        'low': 0, 'lolo': 0, 'lolim': 0,
        'high': 9, 'hihi': 9, 'hilim': 9
        }

is defined in the database, the application crashes after the first attempt of setting the PV. This happens due to the limit checking made in the method _checkNumericAlarm of the class PVInfo, where the code tries to compare the list containing the new values with the integer defined in the limits.

This is the error message that I get after a simple caput:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/pcaspy/driver.py", line 476, in write
    self.writeValue(value)
  File "/usr/local/lib/python3.6/site-packages/pcaspy/driver.py", line 459, in writeValue
    success = driver.write(self.info.reason, gddValue.get())
  File "./test_ioc.py", line 21, in write
    self.setParam(reason, value)
  File "/usr/local/lib/python3.6/site-packages/pcaspy/driver.py", line 147, in setParam
    alarm, severity = self._checkAlarm(reason, value)
  File "/usr/local/lib/python3.6/site-packages/pcaspy/driver.py", line 289, in _checkAlarm
    return self._checkNumericAlarm(info, value)
  File "/usr/local/lib/python3.6/site-packages/pcaspy/driver.py", line 299, in _checkNumericAlarm
    if info.valid_low_high and value <= info.low:
TypeError: '<=' not supported between instances of 'list' and 'int'
xiaoqiangwang commented 6 years ago

Thanks for the report. Here are the possible fixes:

What's your opinion? Do you use the alarm for array types?

fernandohds564 commented 6 years ago

Hi @xiaoqiangwang! Thank you for the quick reply!

That is a difficult question. It would be useful for us to have alarms for this type of PV, but we understand that this a deviation from the default behavior of EPICS waveform record and if you want to maintain compatibility it will be OK for us.

Whichever direction you decide to go, we will adapt yourselves. Thank you!

xiaoqiangwang commented 6 years ago

I add the alarm limits checking for array type in commit ad08df9. I have checked in the alarm_severity.py example. Would you verify that?

fernandohds564 commented 6 years ago

It is working perfectly, @xiaoqiangwang. Thank you!