-
Notifications
You must be signed in to change notification settings - Fork 1
/
dekoder_program_by_Aleksa.py
70 lines (52 loc) · 2.04 KB
/
dekoder_program_by_Aleksa.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
import ripyl
#Importuj dekoder za dekodovanje
import ripyl.protocol.lin as lin
#import ripyl.protocol.uart as uart
#Impotovanje data seta
import csv
#CRTANJE GRAFIKA
import matplotlib
import ripyl.util.plot as rplot
from collections import OrderedDict
import ripyl.streaming as stream
#Za LeCroy osciloskop CSV reader. Ukoliko ne radi, izbrisati header iz csv file.
def read_lecroy_csv(fname):
sample_period = 0.0
raw_samples = []
with open(fname, 'rb') as csvfile:
c = csv.reader(csvfile)
# Sample period is in cell B2 (1,1)
# Time is in column D (3)
# Samples are in column E (4)
for row_num, row in enumerate(c):
if row_num == 1: # get the sample period
sample_period = float(row[0])
break
csvfile.seek(0)
for row in c:
raw_samples.append(float(row[1]))
return raw_samples, sample_period
raw_samples, sample_period = read_lecroy_csv('dataset_oscilloscope_read.csv')
print('Raw samples: ' + str(type(raw_samples)) + "size: " + str(len(raw_samples)))
#Razlika izmedju dva uzorkovanja. Protictati iz CSV file ili sa osciloskopa
sample_period = 0.0000004
#Pretvorio sam stream u listu
txd = list(ripyl.streaming.samples_to_sample_stream(raw_samples, sample_period, start_time=0.0, chunk_size=100000))
records = list(uart.lin_decode(iter(txd), bits=8, parity='even', stop_bits=1))
#records = list(lin.lin_decode(iter(txd)))
# niz_podataka = []
# print(len(records))
# print(records[1])
# for i in range(len(records)):
# niz_podataka.append(records[i].getData())
# Define the channels ordered from top to bottom with the y-axis labels
channels = OrderedDict([('TXD (V)', txd)])
# print(type(channels))
title = 'LIN plot'
# print(records)
# print(channels)
# The Plotter object formats the samples and annotations into plotted waveforms
plotter = rplot.Plotter()
plotter.plot(channels, records, title,label_format=stream.AnnotationFormat.Text)
#plotter.plot(channels, records, title)
plotter.show() # Show the plot in a matplotlib window