-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlecroywf.py
More file actions
executable file
·102 lines (71 loc) · 2.57 KB
/
lecroywf.py
File metadata and controls
executable file
·102 lines (71 loc) · 2.57 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
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
#!/usr/bin/python
# LeCroy Scope Parser
#
# Reads a LeCroy-Serial Output Trace from a file and converts it to
# a .csv-File on stdout.
#
# Lizensiert als http://creativecommons.org/licenses/by-sa/4.0/
#
# TODO: Read a file from stdin or from a given filename
import array
from binascii import *
import struct
def unp_word(data, start):
"Extracts a word from binary data"
return int(struct.unpack(">h", data[start:(start+2)])[0])
def unp_long(data, start):
"Extracts a long from binary data"
return int(struct.unpack(">i", data[start:(start+4)])[0])
def unp_string(data, start):
"Reads a String until first nullbyte"
return data[start:].split("\x00",1)[0]
def unp_float(data, start):
"Extracts a float from binary data"
return float(struct.unpack(">f", data[start:(start+4)])[0])
#Magic Strings
magicHead = 'WF ALL,#'
moreMagic = "WAVEDESC"
myfile = open ("ch1.1", "r")
data=myfile.read()
#Suche Anfang
endOfHead = data.find(magicHead)+ len(magicHead)
data = data[endOfHead:].strip(' ').strip('\r').strip('\n')
print "Lecroy-Parser;"
print "Header-Version;1"
print "Generated With;https://github.com/SmithChart/lecroy-parser;"
hexdata = unhexlify(data)
#print "Bytes gelesen: " + str(len(hexdata))
hexdata = hexdata[hexdata.find(moreMagic):]
#print "Magic String: " + repr((hexdata[:50]))
comm_type = unp_word(hexdata, 32)
#print "COMM_TYPE:" + str(comm_type)
comm_order = unp_word(hexdata, 34)
#print "COMM_ORDER:" + str(comm_order)
WAVE_DESCRIPTOR_len = unp_long(hexdata, 36)
#print "WAVE_DESCRIPTOR length: " + str(WAVE_DESCRIPTOR_len)
USER_TEXT_len = unp_long(hexdata, 40)
#print "USER_TEXT length:" + str(USER_TEXT_len)
WAVE_ARRAY_1 = unp_long(hexdata, 60)
print "WAVE_ARRAY_1 (Number of bytes for the waveform);" + str(WAVE_ARRAY_1)
print "Instrument name;" + unp_string(hexdata,76)
print "Trace label;" + unp_string(hexdata,96)
HORIZ_INTERVAL = unp_float(hexdata, 176)
print "HORIZ_INTERVAL;" + str(HORIZ_INTERVAL)
TIMEBASE = unp_word(hexdata, 324)
print "TIMEBASE;" + str(TIMEBASE)
VERT_COUPLING = unp_word(hexdata, 326)
print "VERT_COUPLING;" + str(VERT_COUPLING)
FIXED_VERT_GAIN = unp_word(hexdata, 332)
print "FIXED_VERT_GAIN;" + str(FIXED_VERT_GAIN)
VERT_GAIN = unp_float(hexdata, 156)
VERT_OFFSET = unp_float(hexdata, 160)
print "VERT_GAIN;" + str(VERT_GAIN)
print "VERT_OFFSET;" + str(VERT_OFFSET)
print "Resulting Gain;" + str(VERT_GAIN/VERT_OFFSET)
#Start of waveform array
i = 346 + USER_TEXT_len
t = 0.
while i<len(hexdata) and i < (346 + USER_TEXT_len + WAVE_ARRAY_1):
print str(t) + ";" + str(VERT_GAIN * float(unp_word(hexdata,i)) + VERT_OFFSET)
i += 2
t += HORIZ_INTERVAL