p4p
p4p copied to clipboard
String unsupported in `NTTable`
NTTable can be initialised with string valued columns, but strings can never be given.
from p4p.server.thread import SharedPV
from p4p.server import Server
from p4p.nt import NTScalar, NTTable
import numpy as np
array_pv = SharedPV(initial=["string 1", "string 2"], nt=NTScalar("as"))
structured_array_type = [("int_field", "i"), ("string_field", "S")]
some_table = np.array([(1, "string1"), (2, "string2")], dtype=structured_array_type)
table_pv = SharedPV(
initial=some_table, nt=NTTable(columns=[("int_field", "i"), ("string_field", "s")])
)
Server.forever(providers=[{"SERVER:ARRAY": array_pv, "SERVER:TABLE": table_pv}])
In the above server the array gives an array of unicode string as we'd expect:
[:)] pvget -v SERVER:ARRAY
SERVER:ARRAY epics:nt/NTScalarArray:1.0
string[] value ["string 1", "string 2"]
However the table has "" values for all of it's strings:
[:)] pvget -v SERVER:TABLE
SERVER:TABLE epics:nt/NTTable:1.0
string[] labels ["int_field", "string_field"]
structure value
int[] int_field [1,2]
string[] string_field ["", ""]
This is the case whether the structured array is ("string_field", "S") or ("string_field", "U"). Putting a value from a client doesn't cause any errors, but the string columns remain "" while the other columns are correctly changed.