Hi all,
I am trying to use the P4P python module ( https://mdavidsaver.github.io/p4p/index.html#) in Matlab for EPICS NTTable
PVs.
Versions that I use:
Python: 3.8.13
P4P: 4.1.3
Matlab: 2020a
First, I tested pvget and pvput in linux terminal, then moved to python and Matlab for each step. It works without problem for the NTScalar and NTScalarArray types. But I don't know how to implement for NTTable type. I will put more
information below.
Python script to run an NTTable PV for the test,
# Python script to generate NTTable
from p4p.nt import NTTable, NTScalar
from p4p.server import Server, ServerOperation
from p4p.server.thread import SharedPV
import numpy as np
class Handler(object):
""" A handler for dealing with put requests to our test PVs """
def put(self, pv: SharedPV, op: ServerOperation) -> None:
""" Called each time a client issues a put operation on the channel using this handler """
pv.post(op.value())
op.done()
table_type = NTTable([("name", "s"), ("number", "d")])
table_rows = []
table_rows.append({"name": "device_1", "number": 1.1})
table_rows.append({"name": "device_2", "number": 1.2})
initial_table = table_type.wrap(table_rows)
table_pv = SharedPV(nt=table_type, initial=initial_table, handler=Handler())
server = Server.forever(providers=[{"TEST:TBL": table_pv}])
In the Linux terminal, pvget and pvput work as expected,
$ pvget TEST:TBL
TEST:TBL 2022-10-25 13:36:05.662
name number
device_1 1.1
device_2 1.2
$ pvput TEST:TBL value.name="[test1, test2]" value.number="[10, 20]"
Old : 2022-10-25 13:36:05.662
name number
device_1 1.1
device_2 1.2
New : 2022-10-25 14:18:32.990
name number
test1 10
test2 20
In the Python command line, work fine; but pvget doesn't show a whole table.
>>> from p4p.client.thread import Context
>>> MatP4P = Context('pva')
>>> MatP4P.get('TEST:TBL')
Value(id:epics:nt/NTTable:1.0, Value(['device_1', 'device_2'])) # <== P4P doesn't show whole information such as in linux terminal
>>> MatP4P.put('TEST:TBL', {'value.name':['test1', 'test2'],'value.number':[10,20]})
>>> MatP4P.get('TEST:TBL')
Value(id:epics:nt/NTTable:1.0, Value(['test1', 'test2']))
In Matlab command line, pvput shows error message. Due to the colon operator.
>> MatP4P = py.p4p.client.thread.Context('pva')
MatP4P =
Python Context with properties:
conf: [1×1 py.builtin_function_or_method]
hurryUp: [1×1 py.builtin_function_or_method]
name: [1×3 py.str]
<p4p.client.thread.Context object at 0x7f137bbbff40>
>> MatP4P.get('TEST:TBL')
ans =
Python Value with no properties.
struct "epics:nt/NTTable:1.0" {
string[] labels = {2}["name", "number"]
struct {
string[] name = {2}["device_1", "device_2"]
double[] number = {2}[1.1, 1.2]
} value
string descriptor = ""
struct "alarm_t" {
int32_t severity = 0
int32_t status = 0
string message = ""
} alarm
struct "time_t" {
int64_t secondsPastEpoch = 1666730165
int32_t nanoseconds = 662142992
int32_t userTag = 0
} timeStamp
}
>> MatP4P.put('TEST:TBL', {'value.name': ['test1', 'test2'], 'value.number': [10, 20]})
Warning: Colon operands must be real scalars.
Error using :
For colon operator with char operands, first and last operands must be char.
Does anybody have a similar experience to mine? Any comments or advice will be appreciated. Since my Matlab version is 2020a, I cannot use pyrun or pyrunfile for now. Thank you.
Best regards,
Kuktae
|