Hello,
i try to write some kind of a forth-like application language for the arduino uno - written in C.
My development system is the Borland C++ - Compiler, and i must say, my first attempts are very promising.
Now i want to migrate the first prototype to the arduino-ide, but my first try did go wrong.
The only substantial change in the code i made for these migration is that i replaced the original getchar() - function used in Borland-C++ by the self-written getkey() - function in the arduino-ide, like it can be seen in the code snippet below.
But the effect was an erratical program behavior. Obviously i missed the difference in how the input-buffer is read in both Borland-C++ and arduino-ide, so that my function "get_token()" did not produce proper tokens.
Perhaps someone has a helpful hint?
Greetings from Hamburg/Germany
Glenn62
void skip_blanks(){
skip_blanks:
while ((c=getkey()) == ' ');
if (c == '\n')
goto skip_blanks;}
void get_token(){
int l=0;
token[l] = c;
++l;
while (((c=getkey()) != '\n') && (c != ' ')){
token[l] = c;
l++;}
token[l]= '\0';}
/*** getkey() added for arduino-ide ******/
char getkey() {
char inchar;
while (!Serial.available());
inchar = Serial.read();
return inchar;}
Migrating any any I-O code from machine to machine will always have problems.
What do you mean, exactly by the statement: "But the effect was an erratical program behavior.". What exectly were the expected results and what were the actual results?
Paul
For one thing, your skip blanks function discards all spaces, all new-lines, and the first character following either of those....
And, get RID of the goto! That is very poor style, and totally unnecessary in that absolutely trivial function.
Regards,
Ray L.
Ray L.
[/quote]
RayLivingston:
For one thing, your skip blanks function discards all spaces, all new-lines, and the first character following either of those....
Yes, skip_blanks() discards all spaces, it is supposed to do that.
And it discards all empty new lines, this too is totally right.
Last but not least it delivers the first character of a token to the following function get_token(), which fills up the token to its proper length. All this works perfectly fine with Borlands getchar(), but not with 'my' getkey(). Why is that so?
Paul_KD7HB:
Migrating any any I-O code from machine to machine will always have problems.
What do you mean, exactly by the statement: "But the effect was an erratical program behavior.". What exectly were the expected results and what were the actual results?
Paul
get_token() passes the \0-terminated tokens on to the interpreter (and eventually compiler). In Borland the interpreter recognizes the tokens without problems, but in Arduino only the second or third token in the input buffer is recognized correctly by the interpreter. And before diving into complex troubleshooting it would be good to know if i have missed a crucial point in migrating the code.
glenn62:
Last but not least it delivers the first character of a token to the following function get_token(), which fills up the token to its proper length. All this works perfectly fine with Borlands getchar(), but not with 'my' getkey(). Why is that so?
It doesn't "deliver" anything to anywhere, both since it is declared "void" and it contains no return statement.
Regards,
Ray L.
I finally got it! It was a little but crucial mistake I made.
Thanks to you two for your invaluable support!
If you need to skip blank input characters, this feature should be part of the "getkey()" function. The "skip_blanks()" function is not working properly as RayLivingston has already mentioned.