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

Temporary fix for linuxfs-i2c IOException. Also fix return code for … #336

Merged
merged 1 commit into from
Mar 15, 2024
Merged

Temporary fix for linuxfs-i2c IOException. Also fix return code for … #336

merged 1 commit into from
Mar 15, 2024

Conversation

taartspi
Copy link
Collaborator

…bytes read readRegister.

See issue #335 for a complete description of the problem and temporary fix.

Copy link
Member

@eitch eitch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I currently don't see a better solution, and as you wrote, a client is supposed to reset internal pointers anyhow. This code is approved

@@ -330,8 +330,6 @@ public int writeReadRegisterWord(int register, int word) {
reg[1] = (byte) (word & 0xff);
reg[2] = (byte) ((word >> 8) & 0xff);
byte buff[] = new byte[2];

int rCode = this.readRegister(reg, buff, 0, buff.length);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this readRegister?

@@ -56,6 +56,8 @@ public synchronized I2C create(I2CConfig config) {
LinuxFsI2CBus i2CBus = this.i2CBusMap.computeIfAbsent(config.getBus(), busNr -> new LinuxFsI2CBus(config));
// create new I/O instance based on I/O config
LinuxFsI2C i2C = new LinuxFsI2C(i2CBus, this, config);
// Workaround, needed if first LinuxFsI2C usage is ioctl (readRegister or writeRegister)
i2C.read();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there not an init of a buffer in this method, which then makes the ioctl work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For instance i can see this:

    this.lastAddress = i2c.device();
    this.file.ioctl(I2CConstants.I2C_SLAVE, i2c.device() & 0xFF);

so the very first thing that happens, is that we set the lastAddress, then immediately perform an ioctl... So maybe this is missing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i do see that the readRegister() does this too...

@eitch eitch merged commit 8119be5 into Pi4J:develop Mar 15, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants