-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystem.py
More file actions
70 lines (58 loc) · 2.76 KB
/
Copy pathSystem.py
File metadata and controls
70 lines (58 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# This Device represents a computer, typically the one everything is being
# run on. Currently, most of the explicit timing is run through a System.
# Only import 'basic' python packages up here. All others should be imported
# within the methods.
import time
from Devices import Device
class System(Device):
def __init__(self, name):
# Run the Device initialization.
Device.__init__(self,name)
# Run simulation is controlled by its own
# Append relevant descriptors
self.descriptors.append('system')
# Defining the elemental procedures
self.requirements['Dwell'] = {}
self.requirements['Dwell']['dtime'] = {'value': '', 'source': 'apparatus', 'address': '', 'desc': 'time to wait in seconds'}
self.requirements['Run'] = {}
self.requirements['Run']['address'] = {'value': '', 'source': 'direct', 'address': '', 'desc': 'address of the program or pointer to it'}
self.requirements['Run']['addresstype'] = {'value': '', 'source': 'direct', 'address': '', 'desc': 'type of address'}
self.requirements['Run']['arguments'] = {'value': '', 'source': 'apparatus', 'address': '', 'desc': 'list of the arguments for the program in order. Will be decomposed with * operator'}
def Dwell(self, dtime=''):
if not self.simulation and dtime != '':
time.sleep(dtime)
self.addlog(self.name + ' waited ' + str(dtime) + ' s.')
return self.returnlog()
def Run(self, address='', addresstype='pointer', arguments=[]):
# This elemental procedure runs a function but does not capture its
# return.
# The address and address type allow targeting a specific function.
# The arguments are decomposed from a list, therefore, there is order
# dependence.
# THESE WILL RUN IN SIMULATION MODE!!
if addresstype == 'pointer':
address(*arguments)
progdesc = str(address)
self.addlog(self.name + ' ran a program, ' + progdesc)
return self.returnlog()
if __name__ == '__main__':
def testFunction(message):
print(message)
print('Demonstrating "real" mode')
mySystem = System('mySystem')
log = ''
log += mySystem.Connect()
log += mySystem.Dwell(dtime=1)
log += mySystem.Run(address=testFunction, addresstype='pointer', arguments=['test message'])
log += mySystem.Disconnect()
print('... and the resulting log.')
print(log)
print('Demonstrating "simulation" mode')
mySystem.simulation = True
log = ''
log += mySystem.Connect()
log += mySystem.Dwell(dtime=1)
log += mySystem.Run(address=testFunction, addresstype='pointer', arguments=['test message'])
log += mySystem.Disconnect()
print('... and the resulting log.')
print(log)