this is a python library for vcd wave file read.
pip install pyvcdr
or just copy pyvcdr.py file to your project.
import pyvcdr
a = pyvcdr.VcdR()
a.read_file('./test1.vcd')
import pyvcdr
a = pyvcdr.VcdR()
a.parse_str('$var wire 1 ! D0 $end\n#0 0!\n')
after read. their are two ways to access the data. first is access data by signal:
print(a.signals[0])#Signal(wire, 1, !, D0)
print(a.signals[1])#Signal(wire, 1, ", D1)
print(a.signals[2])#Signal(wire, 1, #, D2)
print(a.signals[1].module)#D1
for i in a.signals[1].steps:
print(i)
#(0, '1') time, val
#(1250, '0')
#(6250, '1')
#。。。
second is access data by time:
for i in a.time_values:
print('time:', i[0], '. sig:', i[1], '. val:', i[2])
#(0, 'D0', '0')
#(0, 'D1', '1')
#(0, 'D2', '1')
#(1250, 'D1', '0')
#(6250, 'D1', '1')
#(10000, 'D1', '0')
#(15000, 'D1', '1')
#...
I need a python vcd file read program.
I used this library first: https://github.com/westerndigitalcorporation/pyvcd but it could not read file. just write is supported.
then this one: https://github.com/em-/python-vcd/tree/master/vcd it works, but is very very slow.
- the class Signal is from pyvcd library.
- import error fix and pep8 sytle fix by @EtlamGit
I just write it for my file read. so it may not fit some IEEE 1364-2005 protocol. if it do not work for you, add an issue on github: https://github.com/Jiangshan00001/pyvcdr
post the file that could not work. or you can also change the code yourself.
- V0.9 2022.7.10 fix issue when no newline char. thanks to: @AcksID
- V0.8 2021.10.9 add parse_str function.
- V0.7 2021.5.9 BUG FIX: import error fix and pep8 sytle fix. thanks t: @EtlamGit.
- V0.6 2021.5.8. add suport for bBrR data support.