Mar-27-2022, 03:38 AM
Hi,
I just wanted to give an update (I wasn't able to work on this issue for some time) that I was able to solve the issues. I used a python library called zlib instead of calling a C function. Using a python library looked easier. I also worked using @deanhystad's suggestion that data was actually immutable. So, I was able to update my python script accordingly and was able to make it work. I am adding my code just in case someone else faces similar issue.
I just wanted to give an update (I wasn't able to work on this issue for some time) that I was able to solve the issues. I used a python library called zlib instead of calling a C function. Using a python library looked easier. I also worked using @deanhystad's suggestion that data was actually immutable. So, I was able to update my python script accordingly and was able to make it work. I am adding my code just in case someone else faces similar issue.
import datetime import os import struct import time import pigpio import spidev import zlib INTERRUPT_GPIO=25 bus = 0 device = 0 spi = spidev.SpiDev() spi.open(bus, device) spi.max_speed_hz = 4000000 spi.mode = 0 pi = pigpio.pi() if not pi.connected: exit() pi.set_mode(INTERRUPT_GPIO, pigpio.INPUT) C=0 def output_file_path(): return os.path.join(os.path.dirname(__file__), datetime.datetime.now().strftime("%dT%H.%M.%S") + ".csv") def spi_process(gpio,level,tick): print("Detected") data = bytes([0]*1024) spi.xfer2([0x02]) with open(output_file_path(), 'w') as f: t1=datetime.datetime.now() for x in range(1): recv = spi.xfer2(data) values = struct.unpack("<" +"I"*256, bytes(recv)) C = zlib.crc32(bytes(recv)) f.write("\n") f.write("\n".join([str(x) for x in values])) t2=datetime.datetime.now() print(t2-t1) print(C) input("Press Enter to start the process ") spi.xfer2([0x01]) cb1=pi.callback(INTERRUPT_GPIO, pigpio.RISING_EDGE, spi_process) while True: time.sleep(1)Thank you so much for all your help.