DiamondLightSource / pythonSoftIOC

Embed an EPICS IOC in a Python process
Apache License 2.0
34 stars 9 forks source link

Allow `.DISP` to be changed from the ioc side #139

Closed evalott100 closed 11 months ago

evalott100 commented 11 months ago

In pandablocks-ioc we'd like to set the DISP of some PVs so that they can't be changed during HDF5:Capture. The only way to set this with the current pandablocks-ioc is through caput. It'd be nice to be able to set DISP from the ioc side.

AlexanderWells-diamond commented 11 months ago

Summing up a chat I had with @Araneidae:

Araneidae commented 11 months ago

This should be relatively straightforward to implement. I'm no longer set up to actually run pythonIoc anymore, so try the following untested patch:

diff --git a/softioc/device.py b/softioc/device.py
index 4fcb5ad..9f5820b 100644
--- a/softioc/device.py
+++ b/softioc/device.py
@@ -83,6 +83,12 @@ class ProcessDeviceSupportCore(DeviceSupportCore, RecordLookup):
     def _write_value(self, record, value):
         record.write_val(value)

+    def set_field(self, field, value):
+        data = (c_char * 40)()
+        data.value = str(value).encode() + b'\0'
+        db_put_field(
+            self._record.NAME + '.' + field, fields.DBF_STRING, data, 1)
+

 class ProcessDeviceSupportIn(ProcessDeviceSupportCore):
     _link_ = 'INP'