-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpointgrey_utils.py
112 lines (96 loc) · 4.11 KB
/
pointgrey_utils.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import PySpin
def get_serial_number(cam):
return(PySpin.CValuePtr(
cam.GetTLDeviceNodeMap().GetNode('DeviceSerialNumber')).ToString()
)
def set_value(nodemap, nodename, value):
try:
node = nodemap.GetNode(nodename)
nodetype = node.GetPrincipalInterfaceType()
nodeval, typestring = get_nodeval_and_type(node)
assert(PySpin.IsWritable(nodeval), '%s is not writable!' %nodename)
if typestring == 'int' or typestring == 'float':
assert(value <= nodeval.GetMax() and value >= nodeval.GetMin())
if typestring == 'int':
assert(type(value)==int)
if PySpin.IsAvailable(nodeval) and PySpin.IsWritable(nodeval):
nodeval.SetValue(value)
else:
raise ValueError('Node not writable or available: %s' %nodename)
elif typestring == 'float':
assert(type(value)==float)
if PySpin.IsAvailable(nodeval) and PySpin.IsWritable(nodeval):
nodeval.SetValue(value)
else:
raise ValueError('Node not writable or available: %s' %nodename)
elif typestring == 'enum':
assert(type(value)==str)
entry = nodeval.GetEntryByName(value)
if entry is None:
print('Valid entries: ')
entrylist = nodeval.GetEntries()
for entry in entrylist:
print(entry.GetName())
raise ValueError('Invalid entry!: %s' %value)
else:
entry = PySpin.CEnumEntryPtr(entry)
if PySpin.IsAvailable(entry) and PySpin.IsReadable(entry):
nodeval.SetIntValue(entry.GetValue())
else:
raise ValueError('Entry not readable!')
# PySpin.CEnumEntryPtr
elif typestring == 'bool':
assert(type(value)==bool)
if PySpin.IsAvailable(nodeval) and PySpin.IsWritable(nodeval):
nodeval.SetValue(value)
else:
raise ValueError('Node not writable or available: %s' %nodename)
except PySpin.SpinnakerException as e:
raise ValueError('Error: %s' %e)
def turn_strobe_on(nodemap, line, strobe_duration=0.0):
assert(type(line)==int)
assert(type(strobe_duration)==float)
linestr = 'Line%d'%line
# set the line selector to this line so that we change the following
# values for Line2, for example, not Line0
set_value(nodemap, 'LineSelector', linestr)
# one of input, trigger, strobe, output
set_value(nodemap, 'LineMode', 'Strobe')
# enable strobe
set_value(nodemap, 'StrobeEnabled', True)
# set duration, in us I think?
set_value(nodemap, 'StrobeDuration', strobe_duration)
# inverted means low by default, high when strobe is on
set_value(nodemap, 'LineInverter', True)
def print_value(nodemap, nodename):
assert(type(nodename)==str)
node = nodemap.GetNode(nodename)
nodeval, typestring = get_nodeval_and_type(node)
if typestring == 'enum':
# GetCurrentEntry
print(nodename, typestring, nodeval.ToString())
else:
print(nodename, typestring, nodeval.GetValue())
def get_nodeval_and_type(node):
nodetype = node.GetPrincipalInterfaceType()
if nodetype== PySpin.intfIString:
nodeval = PySpin.CStringPtr(node)
typestring = 'string'
elif nodetype== PySpin.intfIInteger:
nodeval = PySpin.CIntegerPtr(node)
typestring = 'int'
elif nodetype== PySpin.intfIFloat:
nodeval = PySpin.CFloatPtr(node)
typestring = 'float'
elif nodetype== PySpin.intfIBoolean:
nodeval = PySpin.CBooleanPtr(node)
typestring = 'bool'
elif nodetype == PySpin.intfIEnumeration:
nodeval = PySpin.CEnumerationPtr(node)
typestring = 'enum'
elif nodetype == PySpin.intfICommand:
nodeval = PySpin.CCommandPtr(node)
typestring = 'command'
else:
raise ValueError('Invalid node type: %s' %nodetype)
return(nodeval, typestring)