Class SMBus


  • public class SMBus
    extends Object
    SMBus is more or less a subset of I2C and has its own standard.

    As such, the Linux kernel provides utilities for executing SMBus operations on an I2C bus.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  SMBus.Block
      Class representing a block of bytes for SMBus operations.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int blockProcessCall​(int command, SMBus.Block block)
      SMBus RPC-like operation, writing several bytes after specifying a command and then reading several bytes as an answer.
      int blockProcessCall​(int command, SMBus.Block blockWrite, SMBus.Block blockRead)
      SMBus RPC-like operation, writing several bytes after specifying a command and then reading several bytes as an answer.
      int processCall​(int command, int word)
      SMBus RPC-like operation, writing a short after specifying a command and then reading the answer.
      void quick​(boolean isWrite)
      SMBus operation sending only the READ or WRITE bit, no data is carried.
      int readBlock​(int command, SMBus.Block block)
      SMBus operation reading several bytes after specifying a command.
      int readByte​(int command)
      SMBus operation reading a byte after specifying a command.
      int readByteDirectly()
      SMBus operation reading a byte without a command.
      void readI2CBlock​(int command, SMBus.Block block, int length)
      SMBus-like operation reading several bytes after specifying a command where the length is part of the message.
      int readWord​(int command)
      SMBus operation reading a short after specifying a command.
      void usePEC​(boolean usePEC)
      Enables or disables packet error checking for SMBus commands.
      void writeBlock​(int command, SMBus.Block block)
      SMBus operation writing several bytes after specifying a command.
      void writeByte​(int command, int b)
      SMBus operation writing a byte after specifying a command.
      void writeByteDirectly​(int b)
      SMBus operation writing a byte without a command.
      void writeI2CBlock​(int command, SMBus.Block block)
      SMBus-like operation writing several bytes after specifying a command where the length is part of the message.
      void writeWord​(int command, int word)
      SMBus operation writing a short after specifying a command.
    • Method Detail

      • usePEC

        public void usePEC​(boolean usePEC)
                    throws IOException
        Enables or disables packet error checking for SMBus commands.

        Is ignored unless the underlying driver provides this functionality.

        Slave devices do not necessarely support this feature either.

        Parameters:
        usePEC - Should PEC be enabled ?
        Throws:
        IllegalStateException - When the underlying I2C bus has been closed.
        IOException - When the bus is not a proper I2C bus or an unplanned error occured.
      • quick

        public void quick​(boolean isWrite)
                   throws IOException
        SMBus operation sending only the READ or WRITE bit, no data is carried.
        Parameters:
        isWrite - True if the WRITE bit must be set.
        Throws:
        IllegalStateException - When the underlying I2C bus has been closed.
        IOException - When the bus is not a proper I2C bus or an unplanned error occured.
      • readByteDirectly

        public int readByteDirectly()
                             throws IOException
        SMBus operation reading a byte without a command.
        Returns:
        Unsigned byte received from the slave.
        Throws:
        IllegalStateException - When the underlying I2C bus has been closed.
        IOException - When the bus is not a proper I2C bus or an unplanned error occured.
      • readByte

        public int readByte​(int command)
                     throws IOException
        SMBus operation reading a byte after specifying a command.
        Parameters:
        command - AKA "register".
        Returns:
        Unsigned byte received from the slave.
        Throws:
        IllegalStateException - When thelbus has been closed.
        IOException - When the bus is not a proper I2C bus or an unplanned error occured.
      • readWord

        public int readWord​(int command)
                     throws IOException
        SMBus operation reading a short after specifying a command.
        Parameters:
        command - AKA "register".
        Returns:
        Unsigned short received from the slave.
        Throws:
        IllegalStateException - When the underlying I2C bus has been closed.
        IOException - When the bus is not a proper I2C bus or an unplanned error occured.
      • readBlock

        public int readBlock​(int command,
                             SMBus.Block block)
                      throws IOException
        SMBus operation reading several bytes after specifying a command.
        Parameters:
        command - AKA "register".
        block - Block of bytes the answer will be written to.
        Returns:
        Number of bytes read.
        Throws:
        IllegalStateException - When the underlying I2C bus has been closed.
        IOException - When the bus is not a proper I2C bus or an unplanned error occured.
      • readI2CBlock

        public void readI2CBlock​(int command,
                                 SMBus.Block block,
                                 int length)
                          throws IOException
        SMBus-like operation reading several bytes after specifying a command where the length is part of the message.

        This operation is not in the SMBus standard but is often supported nonetheless.

        Parameters:
        command - AKA "register".
        block - Block of bytes the answer will be written to.
        length - How many bytes should be read.
        Throws:
        IllegalStateException - When the underlying I2C bus has been closed.
        IOException - When the bus is not a proper I2C bus or an unplanned error occured.
      • writeByteDirectly

        public void writeByteDirectly​(int b)
                               throws IOException
        SMBus operation writing a byte without a command.
        Parameters:
        b - Unsigned byte that needs to be sent.
        Throws:
        IllegalStateException - When the underlying I2C bus has been closed.
        IOException - When the bus is not a proper I2C bus or an unplanned error occured.
      • writeByte

        public void writeByte​(int command,
                              int b)
                       throws IOException
        SMBus operation writing a byte after specifying a command.
        Parameters:
        command - AKA "register".
        b - Unsigned byte that needs to be sent.
        Throws:
        IllegalStateException - When the underlying I2C bus has been closed.
        IOException - When the bus is not a proper I2C bus or an unplanned error occured.
      • writeWord

        public void writeWord​(int command,
                              int word)
                       throws IOException
        SMBus operation writing a short after specifying a command.
        Parameters:
        command - AKA "register".
        word - Unsigned short that needs to be sent.
        Throws:
        IllegalStateException - When the underlying I2C bus has been closed.
        IOException - When the bus is not a proper I2C bus or an unplanned error occured.
      • writeBlock

        public void writeBlock​(int command,
                               SMBus.Block block)
                        throws IOException
        SMBus operation writing several bytes after specifying a command.

        After the command byte, the master also sends a byte count, how many bytes will be written.

        Parameters:
        command - AKA "register".
        block - Block of bytes to write.
        Throws:
        IllegalStateException - When the underlying I2C bus has been closed.
        IOException - When the bus is not a proper I2C bus or an unplanned error occured.
      • writeI2CBlock

        public void writeI2CBlock​(int command,
                                  SMBus.Block block)
                           throws IOException
        SMBus-like operation writing several bytes after specifying a command where the length is part of the message.

        This operation is not in the SMBus standard but is often supported nonetheless.

        Unlike writeBlock, this operation does not send a byte count after the command.

        Parameters:
        command - AKA "register".
        block - Block of bytes to write.
        Throws:
        IllegalStateException - When the underlying I2C bus has been closed.
        IOException - When the bus is not a proper I2C bus or an unplanned error occured.
      • processCall

        public int processCall​(int command,
                               int word)
                        throws IOException
        SMBus RPC-like operation, writing a short after specifying a command and then reading the answer.
        Parameters:
        command - AKA "register".
        word - Unsigned short to be sent.
        Returns:
        Unsigned short given back by the slave.
        Throws:
        IllegalStateException - When the underlying I2C bus has been closed.
        IOException - When the bus is not a proper I2C bus or an unplanned error occured.
      • blockProcessCall

        public int blockProcessCall​(int command,
                                    SMBus.Block block)
                             throws IOException
        SMBus RPC-like operation, writing several bytes after specifying a command and then reading several bytes as an answer.
        Parameters:
        command - AKA "register".
        block - Block of bytes to write, also where the answer will be written to.
        Returns:
        Number of bytes read.
        Throws:
        IllegalStateException - When the underlying I2C bus has been closed.
        IOException - When the bus is not a proper I2C bus or an unplanned error occured.
      • blockProcessCall

        public int blockProcessCall​(int command,
                                    SMBus.Block blockWrite,
                                    SMBus.Block blockRead)
                             throws IOException
        SMBus RPC-like operation, writing several bytes after specifying a command and then reading several bytes as an answer.
        Parameters:
        command - AKA "register".
        blockWrite - Block of bytes to write.
        blockRead - Block of bytes the answer will be written to (can be the same as blockWrite if it can be overwritten).
        Returns:
        Number of bytes read.
        Throws:
        IllegalStateException - When the underlying I2C bus has been closed.
        IOException - When the bus is not a proper I2C bus or an unplanned error occured.