Go Down

Topic: Using C# Class Library into sketch (Read 1 time) previous topic - next topic

-N4w4k-

Hey guys,

I've received my Arduino Uno and started a C# project to communicate with it. I'm using Arduino IDE plugin for visual studio, then I can have every projects into the same visual studio solution..

I managed to send and receive some data thanks to exemples but now I want Arduino sketch to use some object of my C# class library. I don't find the way to declare and use the objects into sketch program.

What I have for now:

BoxControl_Common Assembly:
Code: (C#) [Select]

namespace BoxControl_Common.Service.Arduino
{
    public enum ArduinoServiceRequest
    {
        SayHello = 1,
        SayHelloYou = 2
    }

    public class ArduinoServiceResponse
    {
        public static string BadRequest = "BAD REQUEST";
        public static string Hello = "HELLO";
        public static string HelloYou = "HELLO YOU!";

        //....
    }
}


Arduino Sketch:
Code: [Select]
const int BAUD_RATE = 9600;
const int DELAY = 100;

void setup()
{
Serial.begin(BAUD_RATE);
}

void loop()
{
if (Serial.available() > 0)
{
switch (Serial.parseInt())
{
case ArduinoServiceRequest.SayHello:
sayHello();
break;
case ArduinoServiceRequest.SayHelloYou:
sayHelloYou();
break;
default:
Serial.println(ArduinoServiceResponse.BadRequest);
break;
}
delay(DELAY);
}
}

void sayHello()
{
Serial.println(ArduinoServiceResponse.Hello);
}

void sayHelloYou()
{
Serial.println(ArduinoServiceResponse.HelloYou);
}


Any tips to declare and use ArduinoServiceRequest and ArduinoServiceResponse in my Arduino sketch?

PaulS

Quote
but now I want Arduino sketch to use some object of my C# class library
Not going to happen. The Arduino is programmed in C++, not C#.

The art of getting good answers lies in asking good questions.

-N4w4k-

It doesn't support .net class library? I was able to reference the c# library in the arduino sketch project, but can't find any way to use the classes in the sketch (since i'm too noob in c++ stuff).

Maybe the opposite is possible? Make a c++ library which is referenced in my c# projects?

Any way to share classes between arduino sketch and c# projects?

PaulS

Quote
Any way to share classes between arduino sketch and c# projects?
No. They are programmed in different languages.
The art of getting good answers lies in asking good questions.

-N4w4k-

Ok :( Its not really important, I'm just trying to figure out the possibilities. It'd have been great to be able to have kind of communication contract between c# application and arduino sketch.


Since yesterday I'm looking for solutions, I always think it will work but well.. it doesn't. I'm too noobish with C++ to figure out why. That's frustrating!

Could you explain to me why this topic can't help?

https://support.microsoft.com/en-us/kb/828736

It looks like it's what I'm trying to achieve!

Whandall

Could you explain to me why this topic can't help?
On the standard Arduino there are no DLLs at all, no dynamic linking,
it is even uncommon to use non-dynamic libraries.
Libraries in Arduino context more or less compare to 'sourcecode for library-members'
that get compiled and linked on demand.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

-N4w4k-


westfw

In general, in order to communicate data between very different environments (C# on x86 windows vs C++ on AVR Arduino, for example), you need to carefully define some sort of "extern data representation" that is a least-common-denominator that can be easily interpreted by both.   This is the sort of thing that makes computer networking such an "interesting" field; you want your IBM Mainframe 4 8-bit EBCDIC characters in a 32bit word fixed record text files to show up on your DEC 5 7-bit ASCII characters in a 36bit word newline-delimited text files are actually look right...  (ok, that particular example might be a bit dated...)

See the Internet RFCs and their carefully defined packet formats for some good examples.
See the CCITT OSI protocol specs for some bad examples :-)


Go Up