RS232/ DB9 and Serial
Johnny5
Posts: 10
Hi folks. I am just trying to send a message to my computer and back. Can someone tell me what I am doing wrong with the connection of the wires?
' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM5}
test:
·SEROUT 1, 16780, 1000, [noparse][[/noparse]"Slowly"]
·GOTO test
The following is my C#.Net code:
sp.Open();
sp.ReadTimeout = 500;
sp.BaudRate =9600
sp.PortName="COM4";
this.lblSerIn.Text = sp.ReadLine();
sp.Close();
' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM5}
test:
·SEROUT 1, 16780, 1000, [noparse][[/noparse]"Slowly"]
·GOTO test
The following is my C#.Net code:
sp.Open();
sp.ReadTimeout = 500;
sp.BaudRate =9600
sp.PortName="COM4";
this.lblSerIn.Text = sp.ReadLine();
sp.Close();
Comments
The easiest way to communicate with a PC RS232 port is to use the same serial port used for programming. The DEBUG and DEBUGIN statements do this. You can also use the SEROUT and SERIN statements with pin # 16. Read the chapters in the Basic Stamp Syntax and Reference Manual for more information. The same information is in the help files of the Stamp Editor. The same chapters in the manual show how to connect Stamp I/O pins to most RS232 ports. The signal levels involved (+5V / 0V) may work with most RS232 ports, but not all. For those, you'll have to use something like a MAX232 to convert the signal levels back and forth.
test:
SEROUT 16, 16780, [noparse][[/noparse]"Slowly"]
GOTO test
Or am I totally off?
To begin I would probably work with a baud of 4800 until you have things working right. Read the help files in the Pbasic IDE for more information.
The following link refers to Visual Basic but the principal is the same for C# , of particular interest is the use of a "header" and newline character to "frame" your data.
http://forums.parallax.com/showthread.php?p=671804
Using the programming port (P16) is ideal , one thing might throw you at first is the fact that every character the PC ( C#) transmits is echoed back to the PC. If you don't take care of the echo it will mix with the next transmission.
Jeff T.
I will post a solution and code up soon.
"can the database save information that the EEPROM can read?" No, not quite
The EEPROM in the Stamp is used for two things ... 1) to store the program to be executed; 2) to store data with the WRITE statement that can be accessed with the READ statement. You can include data with your program using the DATA statement. This is the same as data written with the WRITE statement, just initialized when your program is downloaded to the Stamp.
If there's a database on your PC that you want to access from a Stamp, you have to write a program for the Stamp and a program for the PC to do this. The PC program waits for a request from the Stamp made up of serial data sent over a COM port. It decodes the request to determine what data needs to be accessed, accesses the data, and sends it to the Stamp in whatever format you need. The Stamp program does the opposite. It sends a request to the PC using a serial port with the data in whatever format you decide, then waits for a response from the PC. It decodes the data and makes use of it for whatever purpose you need.
Have a look at the PC program StampPlotPro at www.selmaware.com (and also from Parallax).
The serial control is event-driven, and you should read data when the DataReceived() event is triggered on the control.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy