docs: Add IO context manager description

Signed-off-by: Sven Sager <akira@narux.de>
This commit is contained in:
2023-11-20 09:04:34 +01:00
parent 01e7109ec9
commit 12a34e7d11

View File

@@ -88,6 +88,17 @@ class IOList(object):
io_del._parentdevice._update_my_io_list() io_del._parentdevice._update_my_io_list()
def __enter__(self): def __enter__(self):
"""
Read inputs on entering context manager and write outputs on leaving.
All entries are read when entering the context manager. Within the
context manager, further .readprocimg() or .writeprocimg() calls can
be made and the process image can be read or written. When exiting,
all outputs are always written into the process image.
When 'autorefresh=True' is used, all read or write actions in the
background are performed automatically.
"""
if self.__modio._looprunning: if self.__modio._looprunning:
raise RuntimeError("can not start multiple mainloop/cycleloop/with sessions") raise RuntimeError("can not start multiple mainloop/cycleloop/with sessions")
self.__modio._looprunning = True self.__modio._looprunning = True
@@ -96,6 +107,12 @@ class IOList(object):
return self return self
def __exit__(self, exc_type, exc_val, exc_tb): def __exit__(self, exc_type, exc_val, exc_tb):
"""
Write outputs to process image before leaving the context manager.
If 'autorefresh=True' is used, this operation is asynchronous. The
outputs are automatically written in the background.
"""
self.__modio.writeprocimg() self.__modio.writeprocimg()
self.__modio._looprunning = False self.__modio._looprunning = False