Skip to content

Commit

Permalink
Added support for *.csv files with fixed-point values like 1,234 and … (
Browse files Browse the repository at this point in the history
#2)

* Added support for *.csv files with fixed-point values like 1,234 and column-seperator ';'.
Switchable by button.

* corrected spelling mistakes

* added some urls
  • Loading branch information
yasdfgr authored Feb 18, 2024
1 parent 66c6079 commit 3034522
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# csv2vcd
A Tool that can convert Picoscope waveform to Pulseview and keep analog wave.

Picoscope software can be found here:
https://www.picotech.com/downloads
Pulseview, the analyzer software of sigrok project, can be found here:
https://sigrok.org/wiki/Downloads

After imported to PulseView, Its hightly recommand to save as a *.sr file that can reduce file size and open fast.
You can Convert analog to digital via threshould or schmitt-trigger in Pulseview.
A 2GB csv file need about 12min to finish convert in my computer(i7-8750H).
Expand Down
31 changes: 26 additions & 5 deletions csv2vcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,47 @@ def __init__(self):

self.sourcefile=''
self.outputfile=''
self.separator=','
self.triggervoltage=1.8

my_font1=('times', 18, 'bold')
self.l1 = tk.Label(self.tw,text='Picoscope csv to Pulseview vcd',width=30,font=my_font1).pack()

self.b1 = tk.Button(self.tw, text='Select File', width=20,command = self.select_file).pack()
self.sourcefilevar = tk.StringVar()
self.sourcefilevar.set("Please Select Source file.")
self.w1 = tk.Label(self.tw, textvariable=self.sourcefilevar).pack()

self.b2 = tk.Button(self.tw, text='Select Output', width=20,command = self.save_file).pack()
self.outputfilevar = tk.StringVar()
self.outputfilevar.set("Please Select Output file.")
self.w2 = tk.Label(self.tw, textvariable=self.outputfilevar).pack()

self.b4 = tk.Button(self.tw, text='change separator , or ;', width=20,command = self.change_).pack()
self.separatorvar = tk.StringVar()
self.separatorvar.set("Separator for column is: " + self.separator)
self.w4 = tk.Label(self.tw, textvariable=self.separatorvar).pack()

self.b3 = tk.Button(self.tw, text='Start Converter', width=20,command = self.start_converter).pack()
self.resultvar = tk.StringVar()
self.resultvar.set("Waiting Select File.")
self.w3 = tk.Label(self.tw, textvariable=self.resultvar).pack()
self.tw.mainloop()

def change_(self):
if self.separator == ",":
self.separator = ';'
else:
self.separator = ','
self.separatorvar.set("Separator is: " + self.separator)

def check_dir(self):
if len(self.sourcefile) > 0 and len(self.outputfile) > 0:
self.resultvar.set("Waiting Start Converter")

def select_file(self):
self.sourcefile = filedialog.askopenfilename(filetypes=[("PicoScope CSV",".csv")])
self.outputfilevar.set('Source File: ')
if len(self.sourcefile) > 0:
self.sourcefilevar.set('Source File: ' + self.sourcefile)

Expand All @@ -60,16 +77,18 @@ def start_converter(self):
dataline = fo.readline()#first line, Multi language, we dont use it
dataline = fo.readline()#second line, we got timebase (ns, us, ms, s, min)
base = ['ns','us','ms','s']
time = dataline.split(',')[0][1:-1]
time = dataline.split(self.separator)[0][1:-1]
for i in range(len(base)):
if time == base[i]:
multi = 1000 ** i
dataline = fo.readline()#empty line

dataline = fo.readline()#first data line
channel = dataline.count(',')
timebase = dataline.split(',')[0]
data = dataline.split(',')
dataline = dataline.replace(",", "." )#replace , with .
print('dataline:',dataline)
channel = dataline.count(self.separator)
timebase = dataline.split(self.separator)[0]
data = dataline.split(self.separator)
data[channel]=data[channel][:len(data[channel])-1] #remove \n
for i in range(channel):
data[i+1] = data[i+1] if len(data[i+1]) > 2 else '0'
Expand All @@ -90,8 +109,10 @@ def start_converter(self):

linenum = 4
for line in fo:
line = line.replace(",", "." )#replace , with .
print('line:',line)
linenum = linenum + 1
data = line.split(',')
data = line.split(self.separator)
data[channel]=data[channel][:len(data[channel])-1] #remove \n
if linenum == 5:
factor = str(round((float(data[0])-float(timebase))*multi))
Expand Down

0 comments on commit 3034522

Please sign in to comment.