pyftdi icon indicating copy to clipboard operation
pyftdi copied to clipboard

Error in class I2CBusScanner logic - if read success, skips write test

Open dphaas opened this issue 1 year ago • 1 comments

If port in non-smb_mode, successfully reads the loop continues when it should attempt to write. I modified the code to work as intended (I think) with comments below.

           for addr in range(cls.HIGHEST_I2C_SLAVE_ADDRESS+1):
                port = i2c.get_port(addr)
                if smb_mode:
                    try:
                        if addr in cls.SMB_READ_RANGE:
                            port.read(0)
                            slaves.append('R')
                        else:
                            port.write([])
                            slaves.append('W')
                    except I2cNackError:
                        slaves.append('.')
                else:
                    try:
                        port.read(0)
                        slaves.append('R')
                        # continue  <<< move to exception
                    except I2cNackError:
                        slaves.append('.')
                        continue
                        # pass  <<< delete
                    try:
                        port.write([])
                        # slaves.append('W')  <<< delete
                        slaves[-1] = 'W'  # overwrite the R with W
                    except I2cNackError:
                        slaves.append('.')

dphaas avatar Mar 05 '24 23:03 dphaas

Best not to make any changes on this yet. There seems to be an issue with a zero byte read, port.read(0). If one is to believe the doc strings for read() (Read one or more bytes....) this function does not support zero bytes but the default is readlen = int 0. Something doesn't like port.read(0). I'm not sure if it is pyftdi, the ftdi driver, the device I am communicating with or my protocol analyzer. Changing to port.read(1) seems to make the problem go away. I may dig into this more later but for now I have a work-around.

dphaas avatar Mar 06 '24 22:03 dphaas