Giter VIP home page Giter VIP logo

Comments (7)

virtuald avatar virtuald commented on July 3, 2024 1

Also, my understanding is that many SPI devices require you to write something in order to read it, which is why an API like transaction exists. So maybe you're just not telling the device to send any data, so it isn't.

from robotpy-wpilib.

virtuald avatar virtuald commented on July 3, 2024

bytes are readonly in python. I believe if you use a bytearray instead then it will work.

It should give a good error message when you pass in a bytes... what error message do you get when you do that? We can try to make the error better in the future.

from robotpy-wpilib.

echap1 avatar echap1 commented on July 3, 2024

I will try that today. I get no type error when invoking the function (but I do when trying to pass something like [] instead of bytes), it just gives me a segmentation fault with a traceback to the read function. Is there any way I can specify the size of the read? Will it just be the size of my bytearray?

from robotpy-wpilib.

virtuald avatar virtuald commented on July 3, 2024

Yes, it should be the size of your bytearray.

I'll see if I can take a look tonight.

from robotpy-wpilib.

echap1 avatar echap1 commented on July 3, 2024

The function returns the size of my bytearray, so I think you're right. However, when I try to initiate a read the bytearray is unmodified and the function doesn't error even when no SPI device is connected. Is this intended behavior?

from robotpy-wpilib.

virtuald avatar virtuald commented on July 3, 2024

The binding looks right to me. Here's what robotpy-build autogenerates to bind the function:

.def("read", [](frc::SPI * __that,bool initiate, const py::buffer& dataReceived) {
          int size = 0;
          auto __dataReceived = dataReceived.request(true);
          size = __dataReceived.size * __dataReceived.itemsize;
          auto __ret =__that->Read(initiate, (uint8_t*)__dataReceived.ptr, size );
          return __ret;
        },

Looking at SPI::Read it looks like the return value should be ... something undocumented. According to HAL, it looks like the return value should be whatever ioctl is going to return: ... which is likely going to be the length of data written?

from robotpy-wpilib.

virtuald avatar virtuald commented on July 3, 2024

I'm going to close this as I don't believe there's a bug here, just the error message needs improvement.

from robotpy-wpilib.

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.