BBBCSIO

The I2CPortFS Class

 

The I2CPortFS Class

The I2CPort class writes to and reads from the one of the three I2C bus On Chip Peripheral (OCP) devices integrated into the Beaglebone Black CPU via the I2CDev device driver access method. At this time there is no BBBCSIO class of similar functionality which uses the Memory Mapped access method.

 

Source Code

The source code for this class is available online for download and also in browseable form.

 

Example Code

Example code which demonstrates the use of this class can be found on the I2C Port Example page.

 

Syntax

public class I2CPortFS : PortFS

Provides Inter-Integrated Circuit (I2C) port functionality for a BeagleBone Black (I2CDev Version).

 

Public Constructors

public I2CPortFS(I2CPortEnum i2cPortIn) : base(GpioEnum.GPIO_NONE)

Constructor.

Parameters
i2cPortIn - The I2C port to access.

 

Public Methods

public override void ClosePort()

Closes the port. Because we do not open the port at the PortFS level we cannot close it there either. This overrides the PortFS.ClosePort() and does what is necessary internally to close things up.

 

public void Dispose()

Implements IDisposable. Should be called after the class is closed to release resources.

 

public override PortDirectionEnum PortDirection()

Gets the PortDirection

Returns
A PortDirectionEnum value. This value is always PortDirectionEnum.PORTDIR_INPUTOUTPUT.

 

public void Read(int devID, byte[] rxByteBuf, int numBytes)

Reads a buffer in from an I2C Device.

The address of the I2C device is specified by the devID. You do not need to include the address as the first outgoing byte in the rxByteBuf or set the READ/WRITE bit in that address. The I2C driver does that and sends it for you automatically.

Parameters
devID, The I2C Device handle to read from.
rxByteBuf, The buffer for the received bytes.
numBytes, The number of bytes to receive.

 

public void Write(int devID, byte[] txByteBuf, int numBytes)

Writes a buffer out to an I2C Device.

The address of the I2C device is specified by the devID. You do not need to include the address as the first outgoing byte in the txByteBuf or set the READ/WRITE bit in that address. The I2C driver does that and sends it for you automatically.

Parameters
devID, The I2C Device handle to write to.
txByteBuf, The buffer for the transmitted bytes.
numBytes, The number of bytes to send.

 

Public Properties

public I2CPortEnum I2CPort { get; }

Gets the I2C Port. There is no Set accessor this is set in the constructor

value
The working I2CPortEnum.