Common Types¶
Helpers for creating standardized Type
instances.
as defined by http://epics-pvdata.sourceforge.net/alpha/normativeTypes/normativeTypes.html
.
Automatic Value unwrapping¶
Automatic transformation can be performed. between Value
and more convenient types.
Transformation may be performed at the following points:
The result of
p4p.client.thread.Context.get()
,The argument the callable passed to
p4p.client.thread.Context.monitor()
The argument of
p4p.client.thread.Context.put()
The argument of
p4p.client.thread.Context.rpc()
The argument of
p4p.server.thread.SharedPV.open()
The argument of
p4p.server.thread.SharedPV.post()
The result of
p4p.server.thread.SharedPV.current()
Controlling (Un)wrapping¶
Client p4p.client.thread.Context
accepts an argument nt= which may be
None
to sure some reasonable defaults. False
disables wrapping,
and always works with Value
. nt= may also be passed a dictionary
keyed by top level structure IDs mapped to callables returning objects
conforming to WrapperInterface
.
The unwrap argument is legacy which functions like nt= but mapping to plain functions instead of wrapper objects.
from p4p.client.thread import Context
ctxt=Context('pva', nt=False) # disable (un)wrap. All methods use Value
Server p4p.server.thread.SharedPV
accepts an argument nt= which
is an instance of an object conforming to WrapperInterface
.
from p4p.server.thread import SharedPV
from p4p.nt import NTScalar
pv1 = SharedPV() # pv1.open() expects a Value
pv2 = SharedPV(nt=NTScalar('d'))
pv2.open(4.2) # NTScalar automatically wraps this float into a Value
Conforming objects include NTScalar
, NTNDArray
, and others listed below.
NT wrap/unwrap interface¶
-
class
p4p.nt.
WrapperInterface
¶ - Since
3.1.0
-
__init__
()¶ Each time the type ID of a Channel changes, a new wrapper will be instantiated if available.
-
unwrap
(Value) → object¶ Called with a
Value
and may return an arbitrary object.Called by both clients and servers. eg. during
p4p.client.thread.Context.get()
andp4p.server.thread.SharedPV.current()
.
-
wrap
(object) → Value¶ Called with an arbitrary object which it should try to translate into a
Value
.Called by servers. eg. during
p4p.server.thread.SharedPV.post()
.
-
assign
(Value, object)¶ Called to update a
Value
based on an arbitrary object.Called by clients. eg. during
p4p.client.thread.Context.put()
, where the get= argument effects the state of theValue
passed in.
API Reference¶
-
class
p4p.nt.
NTScalar
(valtype='d', **kws)[source]¶ Describes a single scalar or array of scalar values and associated meta-data
>>> stype = NTScalar('d') # scalar double >>> V = stype.wrap(4.2) >>> assert isinstance(V, Value)
>>> stype = NTScalar.buildType('ad') # vector double >>> V = Value(stype, {'value': [4.2, 4.3]})
The result of
wrap()
is an augmented value object combiningntwrappercommon
and a python value type (str
,int
,float
,numpy.ndarray
).Agumented values have some additional attributes including:
.timestamp - The update timestamp is a float representing seconds since 1 jan 1970 UTC.
.raw_stamp - A tuple of (seconds, nanoseconds)
.severity - An integer in the range [0, 3]
.raw - The complete underlying
Value
-
static
buildType
(valtype, extra=[], display=False, control=False, valueAlarm=False)[source]¶ Build a Type
- Parameters
valtype (str) – A type code to be used with the ‘value’ field. See Type definitions
extra (list) – A list of tuples describing additional non-standard fields
display (bool) – Include optional fields for display meta-data
control (bool) – Include optional fields for control meta-data
valueAlarm (bool) – Include optional fields for alarm level meta-data
- Returns
A
Type
-
class
p4p.nt.
NTNDArray
(**kws)[source]¶ Representation of an N-dimensional array with meta-data
Translates into
ntndarray
-
class
p4p.nt.
NTTable
(columns=[], extra=[])[source]¶ A generic table
>>> table = NTTable.buildType(columns=[ ('columnA', 'ai'), ('columnB', 'as'), ])
-
static
buildType
(columns=[], extra=[])[source]¶ Build a table
- Parameters
columns (list) – List of column names and types. eg [(‘colA’, ‘d’)]
extra (list) – A list of tuples describing additional non-standard fields
- Returns
A
Type
-
static
-
class
p4p.nt.
NTURI
(args)[source]¶
-
class
p4p.nt.
NTMultiChannel
[source]¶ Describes a structure holding the equivalent of a number of NTScalar
-
class
p4p.nt.scalar.
ntfloat
(x=0, /)[source]¶ Augmented float with additional attributes
.severity
.status
.timestamp - Seconds since 1 Jan 1970 UTC as a float
.raw_stamp - A tuple (seconds, nanoseconds)
.raw - The underlying
p4p.Value
.
-
class
p4p.nt.scalar.
ntint
[source]¶ Augmented integer with additional attributes
.severity
.status
.timestamp - Seconds since 1 Jan 1970 UTC as a float
.raw_stamp - A tuple (seconds, nanoseconds)
.raw - The underlying
p4p.Value
.
-
class
p4p.nt.scalar.
ntstr
[source]¶ Augmented string with additional attributes
.severity
.status
.timestamp - Seconds since 1 Jan 1970 UTC as a float
.raw_stamp - A tuple (seconds, nanoseconds)
.raw - The underlying
p4p.Value
.
-
class
p4p.nt.scalar.
ntnumericarray
[source]¶ Augmented numpy.ndarray with additional attributes
.severity
.status
.timestamp - Seconds since 1 Jan 1970 UTC as a float
.raw_stamp - A tuple (seconds, nanoseconds)
.raw - The underlying
p4p.Value
.