2 # It needs Python 2.7 or higher!
5 from multiprocessing
import Process
10 # -------------------------------------------------------------
11 # Preliminary declarations
12 # -------------------------------------------------------------
13 class SIS33_ACQ (Structure
):
14 _fields_
= [("data",POINTER(c_uint16
)),
15 ("nr_samples" , c_uint32
),
16 ("prevticks", c_uint64
),
19 class TIMEVAL (Structure
):
20 _fields_
= [("tv_sec", c_uint32
),
21 ("tv_usec", c_uint32
)]
25 print ('\t SIS3300 Testing program \t')
26 print ('\t for continous acquisition \t')
28 print ('Author: Samuel I. Gonsalvez - BE/CO/HT, CERN ')
29 print ('Version: 1.0')
30 print ('License: 3-clause BSD license.')
34 def check_arguments(lun
, chan
):
35 if chan
< 0 or chan
> 7 :
36 print "Error invalid channel:", chan
39 f
= open('/sys/class/sis33/sis33.' + repr(lun
) + '/description', 'r')
42 if not "SIS3300" in desc
:
43 print "It is not a SIS3300:", desc
47 def config_sis(device
, chan
):
48 libsis
.sis33_set_clock_source(device
, 1) # External clock
49 libsis
.sis33_set_start_auto(device
, 1)
50 libsis
.sis33_set_stop_auto(device
, 1)
51 libsis
.sis33_set_start_delay(device
, 0)
52 libsis
.sis33_set_stop_delay(device
, 0)
54 def acquisition(device
, lun
, chan
, segment
, n_acqs
, path
, num_samp
):
55 puntero
= POINTER(SIS33_ACQ
)
56 libsis
.sis33_acqs_zalloc
.restype
= puntero
57 acqs
= libsis
.sis33_acqs_zalloc(1, num_samp
)
61 s
= '/tmp/sis33loop.' + repr(lun
) +'.ch'+repr(chan
) +'.seg'+repr(segment
)+'.num'+repr(0)+'.dat'
63 print "Using", num_samp
,"samples for each file"
64 print "Start time: ", t1
65 for i
in range(0,n_acqs
/2):
66 if libsis
.sis33_acq_wait(device
, 0, 1, num_samp
) < 0 :
67 libsis
.sis33_perror("sis33_acq_wait")
70 if libsis
.sis33_acq(device
, 1, 1, num_samp
) < 0 :
71 libsis
.sis33_perror("sis33_acq_wait")
74 if libsis
.sis33_fetch(device
, 0, chan
, byref(acqs
[0]), 1, byref(endtime
)) < 0 :
75 libsis
.sis33_perror("sis33_fetch")
78 p
= Process(target
=write_data
, args
=(acqs
[0].data
, 131072, i
, lun
, chan
, 0, path
))
81 if libsis
.sis33_fetch_wait(device
, 1, chan
, byref(acqs
[0]), 1, byref(endtime
)) < 0 :
82 libsis
.sis33_perror("sis33_fetch")
85 p
= Process(target
=write_data
, args
=(acqs
[0].data
, 131072, i
, lun
, chan
, 1, path
))
89 print "Finish time: ", t2
90 print "Acquisition Time:", (t2
- t1
), "seconds"
91 libsis
.sis33_acqs_free(acqs
, 1)
93 def calculate_time(time
, freq
, num_samp
):
95 tmp
= tmp
/ num_samp
+ 1
98 def write_data(data
, size
, num_fich
, lun
, chan
, segment
, path
):
99 s
= path
+'/sis33loop.' + repr(lun
) +'.ch'+repr(chan
) +'.seg'+repr(segment
)+'.num'+repr(num_fich
)+'.dat'
101 f
.write("#event segment " + repr(segment
) + "\n")
102 for i
in range(0, size
-1):
103 s
= hex(data
[i
]) + '\n'
106 def found_error(device
):
107 libsis
.sis33_acq_cancel(device
)
110 def exit_program(device
):
111 libsis
.sis33_close(device
)
114 if __name__
== '__main__' :
116 parser
= optparse
.OptionParser()
117 parser
.add_option("-d", "--device", dest
="lun", type="int",
118 help =("Logical Unit Number of the SIS33xx device. [default: %default]"))
119 parser
.add_option("-c", "--channel", dest
="chan", type="int",
120 help =("Channel to setup the acquisition. [default: %default]"))
121 parser
.add_option("-t", "--time", dest
="time", type="int",
122 help =("Time acquisition in seconds. [default: %default]"))
123 parser
.add_option("-p", "--path", dest
="path", type="str",
124 help =("Path to save the data. [default: %default]"))
125 parser
.add_option("-f", "--frequency", dest
="freq", type="int",
126 help =("Frequency of external clock [Hz]. [default: %default]"))
127 parser
.add_option("-l", "--lib", dest
="lib", type="str",
128 help =("Path to the shared library libsis33.L865.so. [default: %default]"))
129 parser
.add_option("-v", "--version", action
="store_true", dest
="version")
130 parser
.set_defaults(lun
=0, chan
=0, time
=1, version
=0, path
='/tmp', freq
=1000000, lib
="../lib")
131 opts
, args
= parser
.parse_args()
133 s
= opts
.lib
+ '/libsis33.L865.so'
134 libsis
= cdll
.LoadLibrary(s
);
139 check_arguments(opts
.lun
, opts
.chan
)
141 device
= libsis
.sis33_open (opts
.lun
)
142 config_sis(device
, opts
.chan
)
145 n_acqs
= calculate_time(opts
.time
, opts
.freq
, num_samp
)
146 acquisition(device
, opts
.lun
, opts
.chan
, 0, n_acqs
, opts
.path
, num_samp
)