paulscherrerinstitute / pcaspy

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

Fail to set PV attributes. #71

Closed sumqzm closed 3 years ago

sumqzm commented 3 years ago

I published some PVs follwing the forms in examples, and also added some attributes for PVs, like 'type', 'value', 'prec' and 'lolo'. However, I found that some settings came into effect ('type' & 'value') but some not ('prec' & 'lolo'). I was not sure what I did wrong. BTW, I have tried the codes with python2.7.18 and python3.9.0. I'm not sure if python versions would effect the result. Part of my codes can be seen as follows. With setting 'prec' to be 3, I can still set PV value as ‘x.xxxxxxxxx’. Another question is that how can I read all these PV attributes through cmd? Is there any specific codes or forms? from pcaspy import Driver, SimpleServer, Alarm, Severity

Rule_Total: Total fault status

prefix_final = 'MPS_Soft:' pvdb0 = {

Total status

'TOTAL:STATUS' : {
    'type' : 'int',
    'lolo' : 0
},
#Total protection
'TOTAL:OUTPUT' : {
    'type' : 'int'
},
pvdb1 = {
#Duty limit
'DUTY:LIMIT' : {
    'prec' : 3
}

}

class myDriver(Driver):

def  __init__(self):

    super(myDriver, self).__init__()

if name == 'main':

server = SimpleServer()

server.createPV(prefix_final, pvdb0)

driver = myDriver()

# process CA transactions

while True:

    server.process(0.5)
xiaoqiangwang commented 3 years ago

prec field gives the hint to graphics display (MEDM, EDM ...) to round the number. With "prec":3, it displays 0.000.

lolo/hihi and low/high are to define the ranges and when the number is out of range, alarm/severity changes. The values are default 0, So "lolo": 0 itself does not define a valid range. Add "hihi": 10 for example and the number will goto alarm state if >=10 or <=0.

$ caput MPS_Soft:TOTAL:STATUS 12
$ caget -d DBR_STS_LONG  MPS_Soft:TOTAL:STATUS
MPS_Soft:TOTAL:STATUS
    Native data type: DBF_LONG
    Request type:     DBR_STS_LONG
    Element count:    1
    Value:            12
    Status:           HIHI
    Severity:         MAJOR

These information can be requested using graphics type, e.g. _DBR_GRDOUBLE

$ caget -d DBR_GR_DOUBLE MPS_Soft:DUTY:LIMIT
MPS_Soft:DUTY:LIMIT
    Native data type: DBF_DOUBLE
    Request type:     DBR_GR_DOUBLE
    Element count:    1
    Value:            1.23445
    Status:           NO_ALARM
    Severity:         NO_ALARM
    Units:            
    Precision:        3
    Lo disp limit:    0
    Hi disp limit:    0
    Lo alarm limit:   0
    Lo warn limit:    0
    Hi warn limit:    0
    Hi alarm limit:   0
sumqzm commented 3 years ago

Thanks for your comments. Question 1 is when I put a number like '0.123456' to the PV, which I have already set its 'prec' to 3, it still display as '0.123456', rather than '0.123'. Question 2 is that how can I get every attribute respectively, like 'lolo', 'status', or 'severity'?

xiaoqiangwang commented 3 years ago

Question 1 is when I put a number like '0.123456' to the PV, which I have already set its 'prec' to 3, it still display as '0.123456', rather than '0.123'.

It depends on the client whether to honor 'prec' or not. Most display manager will do by default. But be aware caget -s, instead of doing local formatting, requests a string conversion on the server. That request seems to result in a fixed 4 digits precision.

Question 2 is that how can I get every attribute respectively, like 'lolo', 'status', or 'severity'?

Use DBR_GR_DOUBLE request type, see previous comments.