Javelin Terminal Window Help
Can anyone explain how I can get simple integer data back from the debug terminal window?
In BS it is easily done.· I can't seem to do it with JAvelin.
·char inputs = Terminal.getChar();
·int data = (int)inputs;
· I want·a simple user input back from the terminal.· They enter a numeric number and then I perform some math functions on that number.
· It seems that when I get the data I can not cast it back or get it to the numeric value I want to use.
· 3 = 51(ascii number)··Just want the int 3!
Thanks,
Scott·
In BS it is easily done.· I can't seem to do it with JAvelin.
·char inputs = Terminal.getChar();
·int data = (int)inputs;
· I want·a simple user input back from the terminal.· They enter a numeric number and then I perform some math functions on that number.
· It seems that when I get the data I can not cast it back or get it to the numeric value I want to use.
· 3 = 51(ascii number)··Just want the int 3!
Thanks,
Scott·
Comments
(rename your Terminal.java to Terminal.org) then copy my Terminal.java to the core folder.
http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/core/
Then get my Format class (Format.java) here:
http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/util/text/
There is also a pdf file for the Format class.
Complete Format application package with demo programs (Appnote 012):
http://www.parallax.com/javelin/applications.asp
char[noparse]/noparse line = new char[noparse][[/noparse]7]; //allows up to 6 chars (decimal 16bit number with sign)
int[noparse]/noparse i = new int[noparse][[/noparse]1]; //placeholder for binary int
Terminal.getString(line,6); //read up to 6 chars from terminal
Format.bscanf(line,0," %d",i); //read int value skipping any leading whitespace
Now i[noparse][[/noparse]0] is the binary value you entered via Terminal.
Read the pdf file for more·info on bscanf.
regards peter
Post Edited (Peter Verkaik) : 11/1/2005 12:07:01 PM GMT
I was started writing my own last night thinking that is what·I had to do.· I wondered why though that the Basic Stamp debug window had all of this in there and not the javelin.
Look around the files section on yahoo group JavelinCode.
http://groups.yahoo.com/group/JavelinCode/files/
Most code I have put there are general utilities, because the Javelin
lacked those. The Format class is very useful for user interface code
using the IDE message window, or for printing to char arrays.
regards peter
·Format.bscanf(line,0," %d",value);·· <--- says either misplaced or not found????· and the Format.java file is in the
%javelin_ide_path%\stamp\util\text folder.
If that folder does not exist, create it first.
In your main class
import stamp.util.text.*;
then you can use
Format.printf("just some text\n"); //same as System.out("just some text\n");
Format.printf("a hex value %04x",value); //print hex number with leading 0's to message window
Format.bscanf(line,0," %d",i); //read a binary int
etc.
regards peter
I also had to look more closely at the bscanf parameters I was not accepting an int [noparse]/noparse back in.· I appreciate all of your help.
For example, if you input values for x, y and z via terminal, you
just enter the values seperated by spaces, on a single line.
In your code
char[noparse]/noparse line = new char[noparse][[/noparse]81];
int[noparse]/noparse x = new int[noparse][[/noparse]1];
int[noparse]/noparse y = new int[noparse][[/noparse]1];
int[noparse]/noparse z = new int[noparse][[/noparse]1];
int k; //parser index
Terminal.getString(line,80); //single line holding multiple values
k = Format.bscanf(line,0," %d",x); //parse x
k = Format.bscanf(line,k," %d",y); //parse y
k = Format.bscanf(line,k," %d",z); //parse z
In the same way you can use bprintf() to assemble a string into a char array
without the overhead of String methods (the Format class does not use Strings,
although it accepts Strings in formal parameters)
regards peter