Comments (11)
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.
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.
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.
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.
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.
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.
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.
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.
from min.
Does that work for you?
from min.
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)
- MIN protocol not working properly on TI MCUs but works on STM HOT 2
- Escape 0x03 (CTRL-C)
- Question regarding the signal layer json HOT 2
- Question: Is Data-Streaming Supported? HOT 2
- Ability to calculate CRC in HW HOT 1
- Time-based frame-delimiting HOT 4
- A Rust library for MIN. HOT 1
- Any port for C#? HOT 2
- STM32Cube USB VCP HOT 9
- Review Comments
- Received spurious ACK HOT 2
- Testing MIN with serial monitor HOT 2
- How to include in C++ project? HOT 1
- Possible bug in the code
- Multiple Ports HOT 2
- Memory conflict: Multiple MIN ports access the same payloads_ring_buffer HOT 2
- Time variable not initialized in transport_fifo_reset HOT 1
- Python package
- What is the best practice for calling min_poll HOT 4
- Python host vs target C implementations
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from min.