Hello guys,
Im currently creating a HMI wich allow control of the arduino card by the PC thanks to Visual Studio (c#).
My current problem is that Im sending a message to the arduino on the serial port with Visual Studio,
this message is well received by the arduino and Im able to stack it into a string :
string dir;
[.....]
if(test[0]=='D' && APC==1)
{
dir=Serial.readStringUntil('\n');
dir();
}
[...]
The string is the exact same stuff I wanted to have,
but I dont know how to convert that string into a function...
I dont know how to explain it but I created functions on a .h + .cpp wich got the exact same names that the messages I sends and I want those messages to launch the functions without using a thousands if.
I dont get it,
At first my idea was to find the good function to "launch" in my .h basing on the message I receive.
I'll have literraly hundreds maybe thousands of functions in my .h (pic n°2)
and i want to start the good one with the message I receive (pic n°1)
C/C++ (except possibly for very rare interpreted versions) is a compiled language, which means that names like 'dir', 'lecturedef', 'effacementdef' and so on, that you have declared in your program, are stripped away and converted to machine addresses at compile time. They are not available to the program in any way, shape or form at run time. There are some alternative suggestions posted that you have to investigate, because your approach is simply not possible.
I dont know how to convert that string into a function...
The Arduino does not need to receive the actual name of a function or even any text. What the user sees and selects in the HMI on the PC need not have any resemblance to the command sent to and acted upon by the Arduino apart from being unique
For instance, a user could select the dir command, the PC could send say 99 and on receipt of 99 the Arduino could execute the dir command. That way all you need on the PC is an array of function pointers indexed by the function number, but my mind boggles at the thought of there being thousands of them
UKHeliBob:
For instance, a user could select the dir command, the PC could send say 99 and on receipt of 99 the Arduino could execute the dir command. That way all you need on the PC is an array of function pointers indexed by the function number, but my mind boggles at the thought of there being thousands of them