Skip to content

System.IO.IOException: Error performing I2c data transfer #163

Closed

Description

@ZhangGaoxing

In Raspberry Pi 3B+ with Raspbian.

When I use UnixI2cDevice.WriteRead(), the program random throw System.IO.IOException: Error performing I2c data transfer. Sometimes 10 calls occur, and sometimes one call occurs. Why?

My Read() Method

public MLX90614Data Read()
{
    byte[] readBuf = new byte[2];
    MLX90614Data data = new MLX90614Data();

    sensor.WriteRead(new byte[] { MLX90614_AMBIENT_TEMP }, readBuf);
    data.AmbientTemp = BitConverter.ToInt16(readBuf, 0) * 0.02 - 273.15;
    sensor.WriteRead(new byte[] { MLX90614_OBJECT_TEMP }, readBuf);
    data.ObjectTemp = BitConverter.ToInt16(readBuf, 0) * 0.02 - 273.15;

    return data;
}

My Main() Method

while (true)
{
    MLX90614Data data = sensor.Read();

    Console.WriteLine($"Ambient Temperature: {data.AmbientTemp} ℃");
    Console.WriteLine($"Object Temperature: {data.ObjectTemp} ℃");
    Console.WriteLine();

    Thread.Sleep(2000);
}

My Terminal Log

True data

Ambient Temperature: 22.79 ℃
Object Temperature: 21.67 ℃

Ambient Temperature: 22.83 ℃
Object Temperature: 21.23 ℃

Then the error suddenly occurred.

Unhandled Exception: System.IO.IOException: Error performing I2c data transfer
Result: -1 ErrorNumber: 121 Error: 131071 ErrorMessage: Remote I/O error
   at System.Devices.I2c.UnixI2cDevice.RdWrInterfaceTransfer(Byte* writeBufferPtr, Byte* readBufferPtr, Int32 writeBufferLength, Int32 readBufferLength)
   at System.Devices.I2c.UnixI2cDevice.Transfer(Byte* writeBuffer, Byte* readBuffer, Int32 writeBufferLength, Int32 readBufferLength)
   at System.Devices.I2c.UnixI2cDevice.WriteRead(Byte[] writeBuffer, Byte[] readBuffer)
   at Iot.Device.MLX90614.MLX90614.Read() in C:\Users\zhang\source\repos\MLX90614\MLX90614\MLX90614.cs:line 52
   at MLX90614.Samples.Program.Main(String[] args) in C:\Users\zhang\source\repos\MLX90614\MLX90614.Samples\Program.cs:line 17

Activity

  1. joperezr commented on Jan 29, 2019

    @joperezr
    Member

    Looks like you are still using an old version of the API by looking at the callstack. Have you tried instead using a newer version of the package? We recently shipped a new version to NuGet

  2. ZhangGaoxing commented on Jan 30, 2019

    @ZhangGaoxing
    ContributorAuthor

    thanks

  3. ghost locked as resolved and limited conversation to collaborators on Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions