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

Multiple SPI throws IOAlreadyExistsException #244

Open
mvanassche opened this issue Sep 22, 2022 · 2 comments
Open

Multiple SPI throws IOAlreadyExistsException #244

mvanassche opened this issue Sep 22, 2022 · 2 comments

Comments

@mvanassche
Copy link

When creating multiple spi, an exception IOAlreadyExistsException is thrown.

The config id is not transferred to the instance object.

Unlike other IO, SpiBase inherits from IOBase, which does not transfer the id/name to the instance (GpioBase and I2CBase do transfer).

I suppose there is simply

        this.name = config.name();
        this.id = config.id();
        this.description = config.description();

missing in the constructor of SpiBase?

@mvanassche
Copy link
Author

diff --git a/pi4j-core/src/main/java/com/pi4j/io/spi/SpiBase.java b/pi4j-core/src/main/java/com/pi4j/io/spi/SpiBase.java
index 80f807e..751bc80 100644
--- a/pi4j-core/src/main/java/com/pi4j/io/spi/SpiBase.java
+++ b/pi4j-core/src/main/java/com/pi4j/io/spi/SpiBase.java
@@ -48,6 +48,9 @@ public abstract class SpiBase extends IOBase<Spi, SpiConfig, SpiProvider> implem
      */
     public SpiBase(SpiProvider provider, SpiConfig config) {
         super(provider, config);
+        this.name = config.name();
+        this.id = config.id();
+        this.description = config.description();
     }
 
     /** {@inheritDoc} */

I tested with that diff with my example with two SPI devices on the same bus, different channel, and so far, it works.

@FDelporte
Copy link
Member

Thanks @mvanassche for reporting and proposing a fix!!!
I created a PR for this #245.

eitch added a commit that referenced this issue Sep 26, 2022
MMMMMNG added a commit to fhnw-sgi-ip12-22vt/ip12-22vt_ladestationen that referenced this issue Jun 1, 2023
…, probably because of this bug: Pi4J/pi4j-v2#244

result: IOAlreadyExistsException at runtime
fusetim added a commit to fusetim/pi4j-v2 that referenced this issue Apr 14, 2024
…iption

The classes extending IOBase were already updating those fields (except SerialBase).
SerialBase was the only class missing this change.

These changes allow the user to use multiple Serial interface at the same time. It
was impossible before, as Pi4J would throws IOAlreadyExistsException.

This commit "moves" the fixes for the similar issues in the SPI interface.

Ref: Pi4J#244, Pi4J#257
Closes: Pi4J#257
fusetim added a commit to fusetim/pi4j-v2 that referenced this issue Apr 14, 2024
…iption

The classes extending IOBase were already updating those fields (except SerialBase).
SerialBase was the only class missing this change.

These changes allow the user to use multiple Serial interface at the same time. It
was impossible before, as Pi4J would throws IOAlreadyExistsException.

This commit "moves" the fixes for the similar issues in the SPI interface.

Ref: Pi4J#244, Pi4J#257
Closes: Pi4J#257
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

2 participants