View Full Version : How to get c++ to receive BS2's readings
10-05-2008, 09:01 PM
Hi, i asked this question before and received an answer that is to use serial in and serial out. But my BS2 is USB, also i do not know the program for the serial communication, can anyone help me with this?
10-05-2008, 11:07 PM
Which board are you using? The stamp itself is not USB. To your computer the USB connection looks like a com port and if you look in device manager (if you are using microsoft) you will see them. There are commands in c++ to send and receive serial data and SERIN and SEROUT in pbasic to do the same.
10-07-2008, 10:25 AM
I am using the board of education (USB). So can c++ read USB the way they read serial data? My laptop do not have serial ports as well.
10-07-2008, 10:37 AM
The USB system provides a "virtual" com port. The USB to serial adapter built into the BOE-USB provides the Stamp end of the "virtual" com port. Your laptop's operating system (presumably Windows) provides the laptop end of the "virtual" com port. To your C++ program, this looks like a com port and behaves like an ordinary com port. To the Stamp, the USB to serial adapter looks like a com port. In this case, you can use either the DEBUG and DEBUGIN statements or you can use the SEROUT and SERIN statements with port #16 specified. Read the Stamp Basic Manual for details on the Stamp end. For C++, use whatever you would normally use to do serial port I/O.
There's an excellent book that I have, called "The Definitive Guide to Building Java Robots" by Scott Preston. It's an excellent book that uses Java to think and send commands to the Basic Stamp, via COM ports. It has a couple of chapters dedicated to getting the communication up and running. I learned Java first several years ago, and now I'm learning C++. They're very similar, so similar in fact that you can probably pick up the other in a month. If you see the book, flip through and see what happens in Java, then see what the C++ equivalent is.
10-07-2008, 05:25 PM
10-09-2008, 11:55 PM
Btw, does the tokenizer convert BS2 code into .exe files? I think i can run .exe files with c++ as well
Not unless you explicitly tell it to do so. You have to select "Generate Object Code" from the main menu, then select the EXE option. This allows you to download via a computer that does not have the editor.