-
Notifications
You must be signed in to change notification settings - Fork 0
/
storable.py
65 lines (48 loc) · 1.47 KB
/
storable.py
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
#
#
# data store
# from motionProgram import motionProgram
import pickle
import hal
# from ioProgram import *
FILENAME = "./machineSettings.pkl"
class storable():
def __init__(self):
# create store for all programs on the 'hmi'
self.programs = []
#
# create 1 default program so there is never an empty list
# self.programs.append(motionProgram())
# plus other things we might need to keep
# track here....
self.currentIndex = 0
self.language = ""
self.halComp = hal.component("persistent")
self.halComp.newpin("axis.0.gain", hal.HAL_FLOAT, hal.HAL_IO)
self.halComp.newpin("axis.0.offset", hal.HAL_FLOAT, hal.HAL_IO)
self.halComp.newpin("axis.1.gain", hal.HAL_FLOAT, hal.HAL_IO)
self.halComp.newpin("axis.1.offset", hal.HAL_FLOAT, hal.HAL_IO)
self.halComp.ready()
def remove(self, index):
pass
def getPrograms(self):
return self.programs
def saveState(self):
self.pickleData()
def loadState(self):
self.unPickleData()
def pickleData(self):
# store the storable to disk
# TODO: we could have a time stamped file here in case of corruption
file = open(FILENAME, "wb")
pickle.dump(self.__dict__, open(FILENAME, "wb"))
file.close()
def unPickleData(self):
# get the storable back from disk
try:
file = open(FILENAME, "rb")
tempDict = pickle.load(file)
self.__dict__.update(tempDict)
file.close()
except:
print "STORAGE: No file %s found" % FILENAME