Giter Site home page Giter Site logo

WriteRead using I2C and MAX7311 about iot HOT 9 CLOSED

dotnet avatar dotnet commented on September 2, 2024
WriteRead using I2C and MAX7311

from iot.

Comments (9)

shaggygi avatar shaggygi commented on September 2, 2024 1

I didn't look into this much, but you might need to set the buffer size to 1. Not completely sure. Also, make sure the BusId is correct. I believe it should be 1.

var device = new System.Device.I2c.Drivers.UnixI2cDevice(new I2cConnectionSettings(BusId, address));
device.Write(new byte[] { 0x00 });
byte[] readBuffer = new byte[1];
device.Read(buffer);

from iot.

joperezr avatar joperezr commented on September 2, 2024

Because I2C protocol only uses 1 data pin, there is not a method like the TransferFullDuplex that we have in SPI. Internally what we are doing is to just do ioctl on the I2c device and send the information, so I would expect that as long as you set the right size of the read and write buffers that it should work correctly. Did you try what @shaggygi suggested?

from iot.

shaggygi avatar shaggygi commented on September 2, 2024

I tested this (only on Unix) and can repro this when sending Write or Read commands with an empty array or Span similar in @bigdnf example.

@joperezr I don't understand why the ioctl wouldn't take/ignore 0 buffer length, but I guess it is expecting something when doing a write/read function. To fix this, we could put a check in ReadWriteInterfaceTransfer and FileInterfaceTransfer to just return if writeBufferLength and readBufferLength are both 0.

I don't like this as it is a little more overhead for checking on every Write/Read call and if someone used an empty array/Span... no error would be shown, the buffer would still be empty and you'd probably see another GitHub issue created stating the I2C method wasn't working.

In addition, when cleaning/updating the I2C and SPI summaries in PRs #143/#144, I added comments for buffer size when reading. This would probably help a little.

Close issue as is?

from iot.

dominikjeske avatar dominikjeske commented on September 2, 2024

Thanks for info - I'm currently on business trip so I can't test anything. I will do it after return and close issue if I can fix it after your suggestions.

from iot.

joperezr avatar joperezr commented on September 2, 2024

@bigdnf have you had the chance if @shaggygi suggestions work in your scenario?

I tested this (only on Unix) and can repro this when sending Write or Read commands with an empty array or Span similar in @bigdnf example.

I don't see that in the example @bigdnf is using an empty array or Span, so that might be a different issue.

To fix this, we could put a check in ReadWriteInterfaceTransfer and FileInterfaceTransfer to just return if writeBufferLength and readBufferLength are both 0.

I believe that this is an actual bug if we aren't checking the size, and if so, I would probably even throw an exception maybe if the read buffer or writebuffer is 0 as this shouldn't be allowed.

from iot.

dominikjeske avatar dominikjeske commented on September 2, 2024

@joperezr sorry for my delay with testing this - I will try to give feedback as soon as possible.

from iot.

joperezr avatar joperezr commented on September 2, 2024

no worries at all, just wanted to check if that was something you still had in your plans šŸ˜„

from iot.

krwq avatar krwq commented on September 2, 2024

I think the correct fix should be to throw a descriptive exception when someone passes 0-length buffer to Read or am I missing something?

from iot.

shaggygi avatar shaggygi commented on September 2, 2024

@krwq The original issue was because there were no bytes allocated to perform read. Your suggestion with having a better exception description would help in this case. Other than that, I would label issue as stale and close.

from iot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.