Shop OBEX P1 Docs P2 Docs Learn Events
Stamp Basic Compiler for Linux — Parallax Forums

Stamp Basic Compiler for Linux

Adrian SchneiderAdrian Schneider Posts: 92
edited 2014-10-16 13:00 in Robotics
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
«1

Comments

  • grimmgrimm Posts: 14
    edited 2005-03-16 10:46
    Hi Adrian,

    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
  • Adrian SchneiderAdrian Schneider Posts: 92
    edited 2005-03-16 11:22
    Hi all

    seems some c++ compilers don't like my baroque coding style smilewinkgrin.gif
    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
  • grimmgrimm Posts: 14
    edited 2005-03-17 06:01
    Well I tried removing the voids but the compiler spit this back at me....

    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. smile.gif

    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
  • Adrian SchneiderAdrian Schneider Posts: 92
    edited 2005-03-17 08:19
    seems my first reply was a little too fast. However, try this and let me know wether it works:

    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
  • grimmgrimm Posts: 14
    edited 2005-03-17 09:10
    Hi 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
  • Adrian SchneiderAdrian Schneider Posts: 92
    edited 2005-03-17 09:46
    Glad that it works now!

    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
  • chemachema Posts: 14
    edited 2005-03-18 16:17
    Hello 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,
  • grimmgrimm Posts: 14
    edited 2005-03-19 00:55
    Hi Adrian,

    That worked!! cool.gif 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
  • Adrian SchneiderAdrian Schneider Posts: 92
    edited 2005-03-19 10:29
    Hi 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
  • chemachema Posts: 14
    edited 2005-03-19 16:40
    Ok, I will try it. Thanks Adrian.
  • Adrian SchneiderAdrian Schneider Posts: 92
    edited 2005-03-20 08:03
    hi chema

    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
  • chemachema Posts: 14
    edited 2005-03-20 11:11
    Adrian, it sounds great !!! I will begin with this step first.... In a couple of days i will tell you something.

    Many thanks for your help, once again [noparse]:)[/noparse]
  • noah44noah44 Posts: 21
    edited 2005-05-11 00:07
    Cheers to Adrian! I am running Fedora Core 3 on a Presario 2100 laptop. After having no luck with bstamp I was almost ready to boot up the Windows partition when I ran across this posting with stampbc. It works like a champ after replacing the three offending lines listed above, running the
    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?
  • Adrian SchneiderAdrian Schneider Posts: 92
    edited 2005-05-12 11:28
    << 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
  • noah44noah44 Posts: 21
    edited 2005-05-12 11:39
    Thanks Adrian, you are the man! Using the cat command works perfectly for viewing DEBUG statements.
  • noah44noah44 Posts: 21
    edited 2005-05-12 22:21
    Thanks again to Adrian for the quick responses to my previous questions.

    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.
  • noah44noah44 Posts: 21
    edited 2005-05-13 03:15
    Update to my last posting - I have discovered that after using stampbc to
    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/
  • Adrian SchneiderAdrian Schneider Posts: 92
    edited 2005-05-13 09:24
    Hi Noah

    I will have a look at your program and why it may generate a segmentation fault over the weekend.
    Stay tuned.

    Regards
    Adrian
  • Adrian SchneiderAdrian Schneider Posts: 92
    edited 2005-05-13 21:10
    Hi Noah

    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 smilewinkgrin.gif
  • noah44noah44 Posts: 21
    edited 2005-05-13 21:44
    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 wink.gif
  • noah44noah44 Posts: 21
    edited 2005-05-14 20:57
    Adrian,

    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.
  • Adrian SchneiderAdrian Schneider Posts: 92
    edited 2005-05-15 16:44
    burger.gif
    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
  • erichberichb Posts: 6
    edited 2005-06-01 16:48
    hi 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
  • Adrian SchneiderAdrian Schneider Posts: 92
    edited 2005-06-02 08:32
    Find the stampbc v2.1 here:
    Parallax Forums > Public Forums > Projects > new version of stampbc: v2.1
    Regards
    Adrian
  • New1976New1976 Posts: 18
    edited 2005-06-28 16:19
    Hi Adrian,

    I'm use this Tokenizer.dll to interface between Visual BAsic to BS2. Can your software be used?

    Regards,
    Steven
  • Adrian SchneiderAdrian Schneider Posts: 92
    edited 2005-06-29 07:49
    Hi 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
  • Dan!Dan! Posts: 2
    edited 2005-07-13 14:58
    Is there a way to call showtty and enter options (like bs, and d) without typing them in. What I want to do is make a shell script that calls showtty, switches to bs program mode, calls stampbc to download the program, switches to debug mode and then runs cat to see the output. It would be a lot easier if this was all in one command.

    Thanks,
    Dan
  • Adrian SchneiderAdrian Schneider Posts: 92
    edited 2005-07-25 08:35
    Hi 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
  • slackjackslackjack Posts: 25
    edited 2006-09-29 02:12
    Hello 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
  • bboothbbooth Posts: 1
    edited 2008-05-18 05:22
    I just downloaded the package and got the same error.

    I never learned C++, but this snippet compiled for me:

        void* p(0);
    
        p = dlsym(m_libt, "TestRecAlignment");
        m_TestRecAlignment = (bool(*)(TModuleRec*))p;
    
        p = dlsym(m_libt, "Compile");
        m_Compile = (bool (*)(SBTokenizer::TModuleRec*, char*, bool, bool))p;
    
        p = dlsym(m_libt, "Version");
        m_Version = (byte(*)())p;
    
    



    Couple years too late, but maybe it will help someone else..
Sign In or Register to comment.