Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2: Initial support for NTNDArray and correct timestamp -> timeStamp #1148

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ophyd/v2/_p4p.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def make_converter(datatype: Optional[Type], values: Dict[str, Any]) -> PvaConve
if datatype and datatype != Sequence[str]:
raise TypeError(f"{pv} has type [str] not {datatype.__name__}")
return PvaArrayConverter()
elif "NTScalarArray" in typeid:
elif "NTScalarArray" in typeid or "NTNDArray" in typeid:
pv_dtype = get_unique(
{k: v["value"].dtype for k, v in values.items()}, "dtypes"
)
Expand Down Expand Up @@ -215,7 +215,7 @@ async def get_descriptor(self) -> Descriptor:

async def get_reading(self) -> Reading:
value = await self.ctxt.get(
self.read_pv, request="field(value,alarm,timestamp)"
self.read_pv, request="field(value,alarm,timeStamp)"
callumforrester marked this conversation as resolved.
Show resolved Hide resolved
)
return self.converter.reading(value)

Expand All @@ -233,7 +233,7 @@ async def async_callback(v):
callback(self.converter.reading(v), self.converter.value(v))

self.subscription = self.ctxt.monitor(
self.read_pv, async_callback, request="field(value,alarm,timestamp)"
self.read_pv, async_callback, request="field(value,alarm,timeStamp)"
)
else:
if self.subscription:
Expand Down
28 changes: 28 additions & 0 deletions ophyd/v2/tests/test_epics.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,34 @@ async def test_pva_table(ioc: IOC) -> None:
q.close()


async def test_pva_ntdarray(ioc: IOC):
if ioc.protocol == "ca":
# CA can't do ndarray
return
initial = np.zeros(4, np.int64)
put = np.ones_like(initial)

descriptor = dict(dtype="array", shape=[4])

for i, p in [(initial, put), (put, initial)]:
backend = await ioc.make_backend(npt.NDArray[np.int64], "ntndarray")
# Make a monitor queue that will monitor for updates
q = MonitorQueue(backend)
try:
# Check descriptor
assert (
dict(source=backend.source, **descriptor)
== await backend.get_descriptor()
)
# Check initial value
await q.assert_updates(pytest.approx(i))
# Put to new value and check that
await backend.put(p)
await q.assert_updates(pytest.approx(p))
finally:
q.close()


async def test_non_existant_errors(ioc: IOC):
backend = await ioc.make_backend(str, "non-existant", connect=False)
# Can't use asyncio.wait_for on python3.8 because of
Expand Down
21 changes: 20 additions & 1 deletion ophyd/v2/tests/test_records.db
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,23 @@ record(waveform, "$(P)table:enum")
"": {"+type": "meta", "+channel": "VAL"}
}
})
}
}

record(waveform, "$(P)ntndarray")
{
field(FTVL, "INT64")
field(NELM, "4")
field(INP, {const:[0, 0, 0, 0]})
field(PINI, "YES")
info(Q:group, {
"$(P)ntndarray":{
+id:"epics:nt/NTNDArray:1.0",
"value":{
+type:"any",
+channel:"VAL",
+trigger:"*",
},
"": {+type:"meta", +channel:"VAL"}
}
})
}
Loading