PC-Stamp communication using C++ serial com
sdy
Posts: 40
I'm writing a program in C++ that talks to/from stamp. I've done it in VB ok, but I want C++ for this other guy (who won't learn VB). Anyone done this? I'm using a serial port libary I got from: http://www.codeproject.com/system/serial.asp
There is a function called ReadByte. I assume this causes the C++ program "hang" until a byte shows up on the COM port.
Do you use a "synch" byte from the stamp to know when stamp is done sending bytes, not knowing how many it's going to send? Do you keep appending bytes until the "end synch byte" comes? Thanks for any help.
There is a function called ReadByte. I assume this causes the C++ program "hang" until a byte shows up on the COM port.
Do you use a "synch" byte from the stamp to know when stamp is done sending bytes, not knowing how many it's going to send? Do you keep appending bytes until the "end synch byte" comes? Thanks for any help.
Comments
C# is fairly similar to C++ and shoud be easy to convert to C++.
www.bjhamltn.com/Projects/Serial_ComPort.zip
I use ReadFile().
I used this to read DTMF tones from the modem.
If you want,
you could use the SHIFTOUT command in Stamp and send 1 byte, plus an x-tra bit as the end-of byte marker.
You could also just use Flow control, by connecting a stamp output to the appropriate handshaking pins on the PC Serial port. You would pulse the Flow Control pin to let the PC you are done sending it the data.
Hope this helps.
·
C/C++ generally require the actions taken to be explicitly programmed by the programmer. So ReadByte most like does only that, and will need to be incorporated in some kind of control loop to get the desired results.
Are you writing this program with Visual Studio 2005? If so, you can use managed C++, which has a SerialPort control that works very similar to the same control in VB.Net. The library that you are currently using is a bit lower level than the .Net framework, so you need a better idea of what's going on with the hardware.
If your friend wants something that is fairly easy to use & develop for, and is willing to learn some basics, you might want to take a look at Tcl & Tk. Tcl is a scripting language that is similar to C in syntax, and is frequently used in embedded applications. For example, it is used in Cisco routers.
Here is a code sample that retrieves the temperature from a temp sensor that I have connected to a HomeWork board:
This example is used interactively from a Tcl command shell. Once I load the code library into the shell session, I can type Temp at the prompt to run the procedure. Note that this is a simple example, with no error checking etc., but it is the majority of what you need for basic IO. As a note, this proc is part of a small library that I was messing with for a robot simulator that I built with a HomeWork board. The simulator uses LEDs to indicate direction, and includes a temperature and light sensor, piezo speaker, and a servo. So I have basic commands for the following:
Direction:
Stop
Forward
ForwardLeft
ForwardRight
Reverse
ReverseLeft
ReverseRight
PivotLeft
PivotRight
Sensors:
Signal
Temp
Light
ServoLeft
ServoCenter
ServoRight
SetServo
The big thing in all of this is that I was surprised how easy it was to do this compared to a C project that I was messing with, and it was all done interactively.
If your friend absolutely wants a C/C++ solution, then take a look at Ch, a C/C++ interpreter. it's very good for prototyping and interactive development. You can also create interactive commands; there are samples available online for the Barret Hand robotic arm.
Post Edited (Kevin Wood) : 8/13/2007 1:09:32 AM GMT
Pete