Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dphaas opened this issue Mar 5, 2024 · 1 comment
Open

Comments

@dphaas
Copy link

dphaas commented Mar 5, 2024

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
Copy link
Author

dphaas commented Mar 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant