Skip to content

Commit 76a6364

Browse files
committed
Added pulldata option to allow cockpit to pull data from valuelogger devices
1 parent a921847 commit 76a6364

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

microscope/abc.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1696,13 +1696,17 @@ class ValueLogger(DataDevice, metaclass=abc.ABCMeta):
16961696
numSensors: total number of measurements.
16971697
16981698
"""
1699-
def __init__(self, numSensors: int, **kwargs) -> None:
1699+
1700+
def __init__(self, numSensors: int, pullData: bool, **kwargs) -> None:
17001701
super().__init__(**kwargs)
17011702
if numSensors < 1:
17021703
raise ValueError(
17031704
"NumSensors must be a positive number (was %d)" % numSensors
17041705
)
17051706
self._numSensors = numSensors
1707+
#if pull data is True data will be pulled from the server if False
1708+
# data will be pushed from microsocpe (default)
1709+
self.pullData = pullData
17061710

17071711
@abc.abstractmethod
17081712
def initialize(self):
@@ -1712,3 +1716,8 @@ def initialize(self):
17121716
def get_num_sensors(self):
17131717
"""Returns the number of sensors lines present in this instance."""
17141718
return self._numSensors
1719+
1720+
@abc.abstractmethod
1721+
def getValues(self):
1722+
"""Returns values from all sensors"""
1723+
raise NotImplementedError()

microscope/simulators/__init__.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -551,18 +551,21 @@ def initialize(self):
551551
# functions required as we are DataDevice returning data to the server.
552552
def _fetch_data(self):
553553
if (time.time() - self.lastDataTime) > 5.0:
554-
for i in range(self._numSensors):
555-
self._cache[i] = (
556-
19.5
557-
+ i
558-
+ 5 * math.sin(self.lastDataTime / 100)
559-
+ random.random()
560-
)
561-
_logger.debug("Sensors %d returns %s" % (i, self._cache[i]))
562554
self.lastDataTime = time.time()
563-
return self._cache
555+
return self.getValues()
564556
return None
565557

558+
def getValues(self):
559+
for i in range(self._numSensors):
560+
self._cache[i] = (
561+
19.5
562+
+ i
563+
+ 5 * math.sin(self.lastDataTime / 100)
564+
+ random.random()
565+
)
566+
_logger.debug("Sensors %d returns %s" % (i, self._cache[i]))
567+
return self._cache
568+
566569
def abort(self):
567570
pass
568571

0 commit comments

Comments
 (0)