Stamp Basic Compiler for Linux
Adrian Schneider
Posts: 92
Due to some request, I added the current version (2.0) of stampbc (STAMP Basic Compiler) for Linux
stampbc is based on the compiler shared library 'tokenizer.so' v1.23 provided by Parallax. The current version
supports stamp basic 2.5. stampbc is a command line frontent to the tokenizer, and manages all the
serial communication stuff to download single- and multi-module programs to the stamp.
Unpack the tgz-File to some directory and read the README-file for a description of who to
compile, install and use stampbc.
Feel free to contact me for further questions.
Regards
Adrian
stampbc is based on the compiler shared library 'tokenizer.so' v1.23 provided by Parallax. The current version
supports stamp basic 2.5. stampbc is a command line frontent to the tokenizer, and manages all the
serial communication stuff to download single- and multi-module programs to the stamp.
Unpack the tgz-File to some directory and read the README-file for a description of who to
compile, install and use stampbc.
Feel free to contact me for further questions.
Regards
Adrian
tgz
53K
Comments
I tried to compile your software but g++ reported several errors and will not finish. I'm running Fedora Core 3 on a Athalon XP 2000+. The errors are as follows....
make
g++ -Wall -D_COLORFUL -c stampbc.cc
g++ -Wall -D_COLORFUL -c SBTokenizer.cc
SBTokenizer.cc: In member function `byte SBTokenizer::init()':
SBTokenizer.cc:68: error: ISO C++ forbids cast to non-reference type used as lvalue
SBTokenizer.cc:69: error: ISO C++ forbids cast to non-reference type used as lvalue
SBTokenizer.cc:70: error: ISO C++ forbids cast to non-reference type used as lvalue
make: *** [noparse][[/noparse]SBTokenizer.o] Error 1
Any fix would be great, as it looks like your software is the only one that supports Pbasic 2.5. Thanks,
Jason
seems some c++ compilers don't like my baroque coding style
I think you can easily fix this: edit the tokenizer.cc at lines 68,69,70 and remove or outcomment that "(void *)" - this should
help. If not let me know.
Regards
Adrian
make
g++ -Wall -D_COLORFUL -c stampbc.cc
g++ -Wall -D_COLORFUL -c SBTokenizer.cc
SBTokenizer.cc: In member function `byte SBTokenizer::init()':
SBTokenizer.cc:68: error: invalid conversion from `void*' to `byte (*)(SBTokenizer::TModuleRec*)'
SBTokenizer.cc:69: error: invalid conversion from `void*' to `byte (*)(SBTokenizer::TModuleRec*, char*, byte, byte, SBTokenizer::TSrcTokReference*)'
SBTokenizer.cc:70: error: invalid conversion from `void*' to `byte (*)()'
make: *** [noparse][[/noparse]SBTokenizer.o] Error 1
Knowing nothing about c++, but still wanting to try something, I added "void *" in front of each statment without the parens. The compiler did spit some warnings back to me, but it compiled.
make
g++ -Wall -D_COLORFUL -c stampbc.cc
g++ -Wall -D_COLORFUL -c SBTokenizer.cc
SBTokenizer.cc: In member function `byte SBTokenizer::init()':
SBTokenizer.cc:68: warning: unused variable 'm_TestRecAlignment'
SBTokenizer.cc:69: warning: unused variable 'm_Compile'
SBTokenizer.cc:70: warning: unused variable 'm_Version'
g++ -Wall -D_COLORFUL -c SBCompiler.cc
g++ -Wall -D_COLORFUL -c SBProject.cc
g++ -Wall -D_COLORFUL -c SBLoader.cc
g++ -Wall -D_COLORFUL -o stampbc stampbc.o SBTokenizer.o SBCompiler.o SBProject.o SBLoader.o -ldl
I tried to run stampbc -V but all I got for my efforts was a seg fault. Is there anything else I could try? Thanks,
Jason
replace the three offending lines
(void *)m_TestRecAlignment = dlsym(m_libt, "TestRecAlignment");
(void *)m_Compile = dlsym(m_libt, "Compile");
(void *)m_Version = dlsym(m_libt, "Version");
with:
void* p(0);
p = dlsym(m_libt, "TestRecAlignment");
m_TestRecAlignment = (bool (*)(TModuleRec*))p;
p = dlsym(m_libt, "Compile");
m_Compile = (bool (*)(TModuleRec*, char*, unsigned char, unsigned char, TSrcTokReference*))p;
p = dlsym(m_libt, "Version");
m_Version = (byte (*)())p;
what happens here is that SBTokenizer.h provides three pointers to functions (TestRecAlignment, Compile, Version).
These pointers are set to their entrypoints inside a shared library (tokenizer.so) by the function dlsym. My compiler
(SuSe 9.0) accepts (void*) casts as lvalue without even a warning. I tried this solution an it compiles and also
compiles PBasic without segfault.
Please let me know if this works, so I can provide a fixed version of stampbc soon
Regards
Adrian
That worked. [noparse]:)[/noparse] I was able to get stampbc to talk with tokenizer.so version 1.23 and compile the test.bs2 code. I am unable to get the program to talk with the basic stamp though. I have the serial version of the board of education board. The /dev/ttyS0 device has the correct permissions and it appears that stampbc is trying to talk to the bs2. When I try to either run the stampbc -j command or send a program (stampbc test.bs2) the bs2 will reset and run the exsisting program that is in it's memory. The new program does not get loaded and the stampbc -j command returns the following:
./stampbc -j
trying to identify the stamp
** no stamp or unable to identify
Getting closer, thanks again. [noparse]:)[/noparse]
Jason
did you try the 'showtty' script that comes with the tgz-file? In the README file are some hints hwo to setup the /dev/ttyS0 device.
The script helps you the see the current settings and to make changes. Also make sure that no other process is using /dev/ttyS0.
showtty /dev/ttyS0
or just showtty as /dev/ttyS0 is the default. Then enter the following commands
9600 raw -echo -hupcl
'-echo' is important since the basic stamp has loopback circuitry on its main
serial port (pin 16 from stamp basic, physically pins 1 SOUT and 2 SIN).
'raw' means that the byte stream is transmitted unchanged as it is provided
by the program.
'-hupcl' avoids certain unintended stamp resets upon opening the serial line.
Adrian
I download your stampbc program. I read the installation steps and this what I get when I execute make && make install:
---
chema@fw:~/stampbc$ make clean
rm -f *.o
rm -f stampbc
chema@fw:~/stampbc$ make
g++ -Wall -D_COLORFUL -c stampbc.cc
In file included from SBCompiler.h:12,
from SBProject.h:15,
from stampbc.cc:20:
defs.h:15: #error 'word' MUST be 16 bits!
defs.h:19: #error 'byte', 'char' and 'bool' MUST be 8 bits!
make: *** [noparse][[/noparse]stampbc.o] Error 1
---
Can you tell me how can I fix this problem ? I'm using debian Woody.
Many thanks for your program and i hope to use it as soon as I can compile the program.
Regards,
That worked!! I can compile the test program and run it on the stamp. Thank you so much for the help and the program. Would copying /dev/ttyS0 to /etc/udev/devices preserve the showtty settings, or will I need to set them everytime I reboot?
Thanks again,
Jason
as I have no /etc/udev/devces on my SuSe-installation I can not decide. However, if you want to preserve your
tty settings use the command 'g' in showtty. This will result in a lengty string of ':'-separated numbers which represent
the current settings in a concise format.
Copy an paste that string and use it as an argument to: 'stty -F/dev/ttyS0 <that_string>' (or whatever /dev/tty you
use). Place this command somewhere in your startup script or a shell script or an alias (this is what I do).
chema:
the error messages you get mean that the unsigned short and unsigned char types provided by your environment do not
have the right sizes, 16 and 8 bits respectively. You will have to do some research on your compiler's includes to
find matching replacements and apply them to lines 23 & 29 of defs.h (typedefs for byte and word). Otherwise you will run into
type alignment problems and the compiler will not work.
regards
Adrian
an other idea that came about: maybe the macros UCHAR_MAX and USHRT_MAX are just not defined - in this case
just comment out the lines 14-20 from defs.h and try your luck again.
to find that macros (usually they are defined in limits.h) try the following:
find /usr/includes -exec grep UCHAR_MAX {} \; -print
reards
Adrian
Many thanks for your help, once again [noparse]:)[/noparse]
showtty commands, and using the LD_LIBRARY_PATH=./ ./stampbc command to run it. I actually made an alias to it known simply as bs2 in my .bashrc
profile so it is easier run.
A question perhaps you might think is stupid...
I using stampbc on a BS2 with PBASIC 2.5 coding. My debug statements are not working, is there a way to enable them?
whow did you capture the output of your debug statements? E.g. cat /dev/ttyS0 (you may need to tweak com port settings
using showtty)
Regards
Adrian
I am having a new problem now.
I was able to upload code to the BS2 and it ran fine with the debug statements output through
the cat command using stampbc but now I am getting a segmentation fault when I try to
run my latest program. I verified that I am using the 1.23 tokenizer with the -V option.
I ran it through the Windows compiler and it works fine... no other .BS2 programs
give me segmentation faults. I am somewhat stumped here.
Attached is the code that segmentation faults using stampbc and the 1.23 tokenizer but
works fine under the Windows compiler.
compile my program into a .o file (DONT use the -c command),
I can then use the bstamp_run to upload the .o file with no segmentation faults.
Strange but true... thanks again for the tips earlier Adrian.
Incidently, I have uploaded pictures and a work log of my work on a BS2
BOE equipped with an SRF04 sonar rangefinder, a digital compass Appmod,
a crawler kit, and a two-servo custom built gripping claw.
The code I posted previously pertains to the project:
http://www.ecst.csuchico.edu/~noahs/224/3-SeniorProject/
I will have a look at your program and why it may generate a segmentation fault over the weekend.
Stay tuned.
Regards
Adrian
I found the bug which causes the segmentation fault when trying to download your program:
The object file buffer size in SBLoader.cc is to small (2048 byte instead of 2304 byte), you can
easily fix it yourself:
SBLoader::download(...)
{
char objBuffer[noparse][[/noparse]2304];
...
I will provide a definitive fix with improved error handling in this case in version 2.1
Regards
Adrian
I suspected it was something simple like that.
I am using 99% of the EEPROM and smaller programs
ran fine using stampbc...
I am wondering now why the max size should be 2304
instead of 2048. The max size is reported to be 2K
in the books?
I will try it with 2304 and report back later... I'm sure it
will work though
Thank you, thank you, thank you. Great job man. It works (I knew it would).
And it seems to upload the object code to the stamp much faster than just using bstamp_run.
For those of you who are trying to get a Linux version of the BS2 tokenizer/compiler working
you have come to the right posting. Above are the correct instructions on how to install and
modify the stampbc program that compiles and uploads PBASIC 2.5 Basic Stamp 2 code wonderfully.
Hopefully if you are stuck like I was you can find this posting on Google. I am running Fedora Core 3
on a Presario 2100 laptop with Parallax's Board of Education (Serial Edition) and a BS2 stamp.
I am pushing the little BS2 to its max using all 2K of its EEPROM, I have upgraded a standard
serial BOE bot kit to include a Compass AppMod, an SRF04 sonic rangefinder, and a custom-built
two-servo-powered gripping-claw. Pictures and source code available at the link I posted above.
Cheers again to Adrian for his work.
Hi Noah
After a glance to the SBTokenizer.h I noticed they reserve 2304 bytes for their object code,
which is the 2048 bytes of stamp memory plus som extra 256 bytes. I overlooked that fact
when I defnied the buffer size - however, this is fixed now.
I uploaded stampbc v2.1
have fun
Adrian
thx for further development of stampbc.
i was looking for version 2.1 but i cant find/see it - can u point me towards it ?
best regards
erich
Parallax Forums > Public Forums > Projects > new version of stampbc: v2.1
Regards
Adrian
I'm use this Tokenizer.dll to interface between Visual BAsic to BS2. Can your software be used?
Regards,
Steven
As stampbc is intended for use under Linux (to be able to compile stamp/download basic programs under linux at all)
it may be of little use for your purpose.
In fact I can hardly imagine in what way you use the tokenizer.dll together with VB in your project.
Could you be more specific on that?
Regards
Adrian
Thanks,
Dan
Sorry for keeping you waiting.
You would have to modify showtty to use it with command line arguments instead of interactively. As showtty is just
a shell script this should be easily possible. In fact showtty is just a user interface to commands like "stty".
Regards
Adrian
When I replaced the three offending lines, Here is what I get:
make
g++ -g -Wall -D_COLORFUL -c SBTokenizer.cc
SBTokenizer.cc: In member function `bool SBTokenizer::init()':
SBTokenizer.cc:75: error: expected primary-expression before "bool"
SBTokenizer.cc:75: error: expected `)' before "bool"
make: *** [noparse][[/noparse]SBTokenizer.o] Error 1
I never learned C++, but this snippet compiled for me:
Couple years too late, but maybe it will help someone else..