dwfpy icon indicating copy to clipboard operation
dwfpy copied to clipboard

spi read and write_read calls do will raise an exception as out values are in parameter list instead of being return values

Open darkerspalbird opened this issue 10 months ago • 1 comments

Hi Marius,

principally I like the feel of dwfpy.

But when I tried to use spi I got a traceback error when reading back values, see below. I use WaveForms beta 3.23.40 (latest beta) on Windows 11.

WaveForms has such a lot of functionality that I believe a testbench which tests all functions is mandatory. I assume you convert from c to python with a translation script I did not try to debug further. For sure many more read functions are affected.

Root cause of the conversion error is that the parameter list are not modified in a way that out channels are return values.

Please set up a regression test and clearly point out what is functioning correctly and what not. Thanks for your effort!

==============================

Traceback (most recent call last): File "C:\Users\grw2rt\Desktop_local_Coole_Eva_Kits\cj135_digilent_discovery\protocol_spi.py", line 51, in rx = spi.read(words_to_receive=10) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\grw2rt\AppData\Local\Programs\Python\Python311\Lib\site-packages\dwfpy\protocols.py", line 417, in read api.dwf_digital_spi_read(self._device.handle, dq_mode, bits_per_word, rx_buffer8, len(rx_buffer8)) TypeError: call takes exactly 4 arguments (5 given)

declaration in bindings.py

dwf_digital_spi_write_read = _dwf_function('FDwfDigitalSpiWriteRead', (_IN, HDWF, 'hdwf'), (_IN, c_int, 'cDQ'), (_IN, c_int, 'cBitPerWord'), (_IN, POINTER(c_ubyte), 'rgTX'), (_IN, c_int, 'cTX'), (_OUT, POINTER(c_ubyte), 'rgRX'), (_IN, c_int, 'cRX'))

incorrect use in protocols.py

""" api.dwf_digital_spi_read(self._device.handle, dq_mode, bits_per_word, rx_buffer8, len(rx_buffer8)) """

Possibly correct use, need to be corrected

rx_buffer8=api.dwf_digital_spi_read(self._device.handle, dq_mode, bits_per_word, len(rx_buffer8))

========================= Traceback (most recent call last): File "C:\Users\grw2rt\Desktop_local_Coole_Eva_Kits\cj135_digilent_discovery\protocol_spi.py", line 33, in rx = spi.write_read(buffer=tx, words_to_receive=10) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\grw2rt\AppData\Local\Programs\Python\Python311\Lib\site-packages\dwfpy\protocols.py", line 463, in write_read api.dwf_digital_spi_write_read( TypeError: call takes exactly 6 arguments (7 given)

declaration in bindings.py

dwf_digital_spi_write_read = _dwf_function('FDwfDigitalSpiWriteRead', (_IN, HDWF, 'hdwf'), (_IN, c_int, 'cDQ'), (_IN, c_int, 'cBitPerWord'), (_IN, POINTER(c_ubyte), 'rgTX'), (_IN, c_int, 'cTX'), (_OUT, POINTER(c_ubyte), 'rgRX'), (_IN, c_int, 'cRX'))

incorrect use in protocols.py

""" api.dwf_digital_spi_write_read( self._device.handle, dq_mode, bits_per_word, tx_buffer8, len(tx_buffer8), rx_buffer8, len(rx_buffer8), ) """

Possibly correct use, need to be corrected

rx_buffer8=api.dwf_digital_spi_write_read( self._device.handle, dq_mode, bits_per_word, tx_buffer8, len(tx_buffer8), len(rx_buffer8), )

darkerspalbird avatar Feb 17 '25 23:02 darkerspalbird

Hi there, you are correct, I goofed up the SPI prototypes with some previous update (I need to find a way to test that automatically).

I pushed the updated binding to main for you to try: See https://github.com/mariusgreuel/dwfpy/wiki/Developer-Cheat-Sheet

mariusgreuel avatar Feb 21 '25 21:02 mariusgreuel