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

Ticket 6556 khly2700 added emulator and test #10

Merged
merged 79 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
22ba8ba
Rename plankton_emulators to lewis_emulators because framework name h…
Jan 6, 2017
6f425de
Update __init__.py
Jun 1, 2017
966314a
Merge pull request #17 from ISISComputingGroup/Ticket2371_EOL_fixes
FreddieAkeroyd Jun 2, 2017
91fdfb6
Tidied up the formatting for a lot of files
Jun 8, 2017
698b0ed
Merge pull request #18 from ISISComputingGroup/Ticket2379_Create_TPG2…
Jun 8, 2017
473f733
keithely2700 tests
Sep 13, 2017
815d310
Pin emulators to latest version
Sep 25, 2017
e4654f3
changed formatting of assert_pv_is.. functions
esouthren Feb 26, 2018
ec86a70
Moved commit from master to branch
esouthren Feb 26, 2018
efd66c6
Delete keithley_2700.py
esouthren Feb 27, 2018
88d0bcf
cody tidy
esouthren Mar 22, 2018
f554372
Upgrade Lewis
davidkeymer Mar 23, 2018
45128f5
Update lewis_versions.py
esouthren Apr 3, 2018
54bf02f
Merge pull request #55 from ISISComputingGroup/Ticket2386_Upgrade_Lewis
esouthren Apr 3, 2018
0b8fff9
updated branch with master files/lewis update
esouthren Apr 4, 2018
32871a4
update for lewis upgrade
esouthren Apr 4, 2018
ff485e9
added readback commands
esouthren Apr 5, 2018
842decf
rework tidy
esouthren Apr 6, 2018
4504242
split alarm tests
esouthren Apr 9, 2018
6ad6b69
Pre review tidy, adapted new :MEASUREMENT return value from support f…
esouthren Apr 9, 2018
436411a
Merge remote-tracking branch 'origin/master' into Ticket647_Keithley_…
Tom-Willemsen Apr 11, 2018
35aa7f9
Pre-review code tidy
esouthren Apr 19, 2018
6544c60
changed all device variables to enum values, added dictionaries to ma…
esouthren Apr 19, 2018
184de6c
Changed module name and updated emulator to pass temp test.
Jun 1, 2018
e16e1e9
Refactored using process_pv function.
Jun 1, 2018
f563e8d
Re-add lost init file, with comment saying do not delete.
Tom-Willemsen Jun 15, 2018
7fff59b
Convert docs to new style. Make assertion names consistent.
Tom-Willemsen Jun 20, 2018
3635eec
Updated stream interface for Keithley 2001 some more
Sep 17, 2018
3b0a1ff
Reverted back to master version of Keithley2700 files
Oct 23, 2018
cdc99e4
Altered test data and added more tests
LiamPanchaud Nov 5, 2018
e472148
Large refactoring of emulator
LiamPanchaud Nov 14, 2018
0eba559
Test data now uses real logged data
LiamPanchaud Nov 15, 2018
57b3b2c
added more tests, refactored to no longer use indices
LiamPanchaud Dec 4, 2018
958ded3
refactored reading retrieval
LiamPanchaud Dec 4, 2018
91c43e1
bug fixing
LiamPanchaud Dec 4, 2018
8b1a73c
Various refactoring
LiamPanchaud Dec 11, 2018
9481e25
Altered buffer full logic
LiamPanchaud Dec 11, 2018
8575e19
Added more tests
LiamPanchaud Dec 17, 2018
51e178a
Changed log line location
LiamPanchaud Dec 17, 2018
3e0f029
Removed control mode attribute
LiamPanchaud Jan 3, 2019
e97ffdc
Sanitisation and refactoring some tests
LiamPanchaud Jan 3, 2019
9d16f6b
Changed terminator, added multicommand
LiamPanchaud Jan 8, 2019
f98035b
Modified commands to use ignore case flag
LiamPanchaud Jan 8, 2019
c032b3b
Reformatted commands, removed dead code
LiamPanchaud Jan 30, 2019
f1d2528
Removed unused channel objects and device attributes
LiamPanchaud Jan 30, 2019
142614c
Extracted repeated methods
LiamPanchaud Jan 30, 2019
f2b64d5
Review changes plus extra alarm test
LiamPanchaud Jan 30, 2019
a57f59f
Added comment to explain
LiamPanchaud Jan 30, 2019
f165f58
Merge branch 'master' into Ticket2994_keithley_2700
LiamPanchaud Mar 13, 2019
ec927b5
Added previously removed attributes
LiamPanchaud Mar 14, 2019
13e085e
Merge branch 'Ticket2994_keithley_2700' of https://github.com/ISISCom…
LiamPanchaud Mar 14, 2019
ee82aca
Skip k2700 tests to be fixed in ticket3939
LiamPanchaud Apr 23, 2019
f57c58d
Removed skip annotations
LiamPanchaud Apr 23, 2019
18cafbc
Changed device emulator to match protocol
Alistair-McGann-Tessella May 1, 2019
43e3da9
Updated lewis version
DominicOram Sep 25, 2019
aafac49
Merge pull request #54 from ISISComputingGroup/Ticket4775_upgrade_lew…
Tom-Willemsen Sep 25, 2019
c34b3fd
renamed to cryogenic_sms/CRYOSMS
LilithCole Oct 15, 2019
d657cf6
merge master
LilithCole Oct 15, 2019
8f0b697
Switch assertion orders, fix wm323 test names
Tom-Willemsen Nov 8, 2019
2bcf6a9
Merge pull request #257 from ISISComputingGroup/fix_assertion_order
John-Holt-Tessella Nov 11, 2019
01cc85a
Merge branch 'master' into Ticket5259_switch_rates_mid_ramp
LilithCole Mar 13, 2020
82356d2
continually add readings into the buffer unless otherwise specified
LilithCole Apr 7, 2020
2b79ac7
Keithley tests modified to work with emulator additions
LilithCole Apr 7, 2020
19f8ea2
remove change on wrong branch
LilithCole Apr 9, 2020
616fd99
Updated lewis version to 1.2.2
DominicOram Jun 1, 2020
a22ceee
Fixed variable name for lewis version number
aaron-long Sep 16, 2020
75c85c2
Merge pull request #87 from ISISComputingGroup/Ticket4889_convert_dev…
rerpha Sep 24, 2020
aa575da
Merge branch 'master' into Ticket5259_switch_rates_mid_ramp
LilithCole Oct 19, 2020
a95671b
Updated to use latest lewis version and convert strings correctly
DominicOram Nov 10, 2020
eb11a0d
Update lewis version
DominicOram Nov 30, 2020
9776d95
Fix python 3 errors
DominicOram Mar 9, 2021
fb81cc6
Speed up tests and clear buffer as final thing in set up
DominicOram Mar 9, 2021
83239bb
Added logging to when simulated values are turned off
DominicOram Mar 9, 2021
7b953e4
Merge pull request #107 from ISISComputingGroup/fix_keithley_2700
Tom-Willemsen Mar 9, 2021
4e5ed6b
Merge pull request #435 from ISISComputingGroup/fix_keithley_2700
Tom-Willemsen Mar 9, 2021
e995c27
Moved utils into lewis itself
DominicOram Jun 10, 2021
d2a271d
Merge branch 'master' of C:/Instrument/Dev/EPICS-IOC_Test_Framework i…
Adam-Szw Apr 22, 2022
885cc1f
Merge branch 'master' of C:\Instrument\Dev\EPICS-DeviceEmulator into …
Adam-Szw Apr 22, 2022
54b8b37
added emulator and tests
Adam-Szw Apr 22, 2022
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ runIOC.sh
relPaths.sh
.project
/test-reports
__pycache__/
*.py[cod]
*$py.class
test-reports/
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ DIRS += $(wildcard *[Aa]pp)
DIRS += $(wildcard ioc[Bb]oot)

include $(TOP)/configure/RULES_TOP

ioctests:
.\system_tests\run_tests.bat
2 changes: 2 additions & 0 deletions system_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DO NOT DELETE THIS FILE - LEWIS FRAMEWORK REQUIRES THE DIRECTORY TO BE IMPORTABLE
from __future__ import absolute_import
2 changes: 2 additions & 0 deletions system_tests/lewis_emulators/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DO NOT DELETE THIS FILE - LEWIS FRAMEWORK REQUIRES THE DIRECTORY TO BE IMPORTABLE
from __future__ import absolute_import
3 changes: 3 additions & 0 deletions system_tests/lewis_emulators/keithley_2700/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .device import SimulatedKeithley2700

__all__ = ['SimulatedKeithley2700']
126 changes: 126 additions & 0 deletions system_tests/lewis_emulators/keithley_2700/device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
from collections import OrderedDict
from lewis.core.logging import has_log
from .states import DefaultState
from lewis.devices import StateMachineDevice
from random import randint
import time
import threading

MAX_READ = 1500
MIN_READ = 1000


class BufferReading(object):
def __init__(self, reading, timestamp, channel):
self.reading = reading
self.timestamp = timestamp
self.channel = channel


@has_log
class SimulatedKeithley2700(StateMachineDevice):
"""
Simulated Keithley2700 Multimeter
"""

def _simulate_readings_thread(self):
"""
Generates random simulated data to put insert into the buffer.
"""

def i_to_channel(i):
"""
formats index as channel number, 101 to 110, 201 to 210
"""
if i < 10:
return 101 + i
else:
return 191 + i

i = 0
while self.simulate_readings:
resistance = randint(1000, 2000)
timestamp = time.time() - self.start_time
self.insert_mock_data(["+{},{},+{}".format(resistance, timestamp, i_to_channel(i))])
i = (i + 1) % 20
time.sleep(0.1)

@property
def simulate_readings(self):
return self._simulate_readings

@simulate_readings.setter
def simulate_readings(self, new_value):
self.log.info(f"Setting simulate readings to {new_value}")
self._simulate_readings = new_value

def _initialize_data(self):
"""
Initialize the device's attributes necessary for testing.
"""
self.idn = "KEITHLEY" # Device name
self.buffer = [] # The buffer in which samples are stored
self.buffer_autoclear_on = False # when false, new readings appended to old readings in buffer
self.buffer_size = 1000 # size of buffer which holds read data default 1000
# The below attributes are not used but are needed for the stream interface
self.bytes_available = 0
self.bytes_used = 0
self.start_time = time.time()
self.simulate_readings = True
thread = threading.Thread(group=None, target=self._simulate_readings_thread)
thread.daemon = True
thread.start()

def get_next_buffer_location(self):
if not self.is_buffer_full():
return len(self.buffer)
else:
return 0 # Buffer full so next loc is 0 after a clear

def is_buffer_full(self):
return len(self.buffer) >= self.buffer_size # -1 because buffer is 0 indexed

def insert_mock_data(self, data):
"""
Allows the insertion of specific, defined readings into the buffer
:param data: a list containing string representations of buffer readings
"""
self.log.info("Inserting mock data into buffer: {}".format(data))
for item in data:
reading, timestamp, channel = item.split(",")
if self.is_buffer_full() and self.buffer_autoclear_on:
self.clear_buffer()
self.buffer.append(BufferReading(reading, timestamp, channel))

def check_buffer_data(self):
"""
Gets values contained in self.buffer
:return: List of comma separated string representations of readings in the buffer
"""
return [",".join((reading.reading, reading.timestamp, reading.channel))
.encode("utf-8") for reading in self.buffer]

def clear_buffer(self):
"""
Clears all buffer entries
"""
self.buffer = []
self.log.info("=== Cleared Buffer ===")

def _get_state_handlers(self):
"""
Returns: states and their names
"""
return {DefaultState.NAME: DefaultState()}

def _get_initial_state(self):
"""
Returns: the name of the initial state
"""
return DefaultState.NAME

def _get_transition_handlers(self):
"""
Returns: the state transitions
"""
return OrderedDict()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .stream_interface import Keithley2700StreamInterface

__all__ = ['Keithley2700StreamInterface']
Loading