ChimeraTK-ApplicationCore 04.08.00
Loading...
Searching...
No Matches
testPythonPollInputRead.py
Go to the documentation of this file.
1#!/usr/bin/python3
2
3import sys
4import os
5import traceback
6
7# fmt: off
8sys.path.insert(0, os.path.abspath(os.path.join(os.curdir, "..")))
9import PyApplicationCore as ac # NOQA
10# fmt: on
11
12
13class PollInputTestMod(ac.ApplicationModule):
14
15 def __init__(self, owner, name, description):
16 super().__init__(owner, name, description)
17
18 # Scalar poll input — read() should delegate to readLatest() and never block
19 self.scalarPollIn = ac.ScalarPollInput(
20 ac.DataType.int32, self, "/ScalarPollIn", "", "")
21
22 # Array poll input — read() should delegate to readLatest() and never block
23 self.arrayPollIn = ac.ArrayPollInput(
24 ac.DataType.int32, self, "/ArrayPollIn", "", 5, "")
25
26 # Trigger to step the mainLoop
27 self.end = ac.ScalarPushInput(
28 ac.DataType.int32, self, "/End", "", "")
29
30 # Error reporting
31 self.testError = ac.ScalarOutput(
32 ac.DataType.string, self, "/TestError", "", "")
33
34 def mainLoop(self):
35 while True:
36 try:
37 # read() on poll inputs must NOT block even if no new data is available.
38 # These calls should return immediately by delegating to readLatest().
39 self.scalarPollIn.read()
40 self.arrayPollIn.read()
41
42 self.testError.setAndWrite("")
43 except Exception as e:
44 self.testError.setAndWrite("\n".join(traceback.format_exception(e)))
45
46 self.end.readAndGet()
47
48
49ac.app.pollInputTestMod = PollInputTestMod(
50 ac.app, "PollInputTestModule", "Test ScalarPollInput and ArrayPollInput read() delegation")
void mainLoop() override