Git Product home page Git Product logo

Comments (11)

kentindell avatar kentindell commented on August 11, 2024 1

Firstly, I'd really not recommend #including C code into a file: it's a really bad style. You should add min.c into your project (do you use a Makefile or does your IDE build one for you?). Then the compiler knows it's C and not C++ and compiles accordingly. Also this way you can set your own compilation options for just that file.

from min.

Resonanz avatar Resonanz commented on August 11, 2024

These are my definitions so far:

min_context_t *mct;
uint8_t payLoad[5] = {1, 2, 3, 4, 5};
min_init_context(mct, 1);   // (context, port)
min_send_frame(mct, 0, payLoad, 5);

And these two functions are callbacks I think.

void min_tx_byte(uint8_t port, uint8_t byte) {
  Serial.write(byte);
}

void min_application_handler(uint8_t min_id, uint8_t *min_payload, uint8_t len_payload, uint8_t port) {
  Serial.print("got something");
}

It would be really helpful to have some further documentation so we can get this going. I am hoping to have some LabVIEW code written to communicate with the C code -- I think that is close to completion.

Many thanks.

from min.

kentindell avatar kentindell commented on August 11, 2024

Secondly, the Python code is a module, not a program: it's intended that you import the module into your own program and call it from there. So it definitely won't run by itself. You could easily make a trivial main.py program to call it for testing and that's where I'd start: a "print everything you see" program.

from min.

kentindell avatar kentindell commented on August 11, 2024

Thirdly, you haven't actually created a MIN context variable there: you just created a pointer to one that's uninitialized. You should do something like:

min_context_t mct;
min_init_context(&mct, 1);   // (context, port)
min_send_frame(&mct, 0, payLoad, 5);

The code you had would've been dereferencing a pointer to somewhere random and this would go bang. The reason the API expects you to do the memory allocation for the MIN context is that the code doesn't (and shouldn't) use any heap or dynamic memory: only the programmer knows the lifetime of the memory. Oh, and don't make the MIN context a local variable in a function: when you return from the function it will be deallocated from the stack and when you later call MIN you'll get your stack corrupted by writing to where that context was on the stack.

The two callbacks you have look fine.

from min.

kentindell avatar kentindell commented on August 11, 2024

Oh, and I forgot to say: the Python I wrote is Python 3 (I don't think anyone should be writing for Python 2 any more).

from min.

Resonanz avatar Resonanz commented on August 11, 2024

Hi Ken, it seems that Github doesn't support threaded comments, so I'll follow the order above.

C inside C++
The way this is done on Arduino is to use the extern keyword. So in fact, I don't have to touch your .c and .h files at all and can simply use extern "C" {#include min.h} in my Arduino code. It took a while to get this working and lots of people has asked how to do it online. Accessing a makefile may be possible but it is well hidden. Perhaps we should move to Atmel Studio, but then we lose the advantages of quick development.

Python
Okay, got that. Re the version, I think the helper file says python 2.7 (perhaps that is the min version -- bad pun sorry).

MIN context variable
LOL, the code you show is what I was using, until I changed it. Thanks for clarifying. The struct is a global in my code.

from min.

Resonanz avatar Resonanz commented on August 11, 2024

Hi Ken, to help us get started, is there any chance that you have the basic Python code available that uses your library? Or is this documented somewhere? Thanks.

from min.

kentindell avatar kentindell commented on August 11, 2024

I've got a very complex host monitor program that talks to the Pyboard to use the Pyboard as a CAN interface. I can try and cut something out of it and show you how it works but I haven't got time today to test it actually works.

from min.

kentindell avatar kentindell commented on August 11, 2024

41afd8d

from min.

kentindell avatar kentindell commented on August 11, 2024

Does that work for you?

from min.

kentindell avatar kentindell commented on August 11, 2024

I've added a "hello world" program (it really does say "hello world") that consist of a simple Python program and a sketch for the Arduino. More here: https://github.com/min-protocol/min/wiki/Running-the-example-program

from min.

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.