Two-way communication (BS2 - Desktop Computer)
eyyYo
Posts: 14
Hello!
Im new to this thing with microcontrollers, but im catching on quick! Now i have been woundering a thing for a time now. How do you create a two way communication with a desktop·computer (Using BS2-IC)?
I want BS2 do do some things when i send a message to it, from my desktop computer. I also want my desktop computer do do some things when BS2 send a message. I have achieved to send a message to the computer, but havent been able to find documentation on how to send from pc->bs2.
Thank you in advance. /Adam
Im new to this thing with microcontrollers, but im catching on quick! Now i have been woundering a thing for a time now. How do you create a two way communication with a desktop·computer (Using BS2-IC)?
I want BS2 do do some things when i send a message to it, from my desktop computer. I also want my desktop computer do do some things when BS2 send a message. I have achieved to send a message to the computer, but havent been able to find documentation on how to send from pc->bs2.
Thank you in advance. /Adam
Comments
MAIN:
SEROUT 16, 16468, [noparse][[/noparse]"Hi there!", CR]
PAUSE 500 ' Pause 500 mSec, so BS2 doesn't 'flood' you
GOTO MAIN
On the PC, you'll have to open the serial port, or use the Debug window, or use Hyperterm to open the serial port.
like: (maybe crappy syntax and stuff, im just making example)
IF REC_MSG = "open pin5" THEN
out5 = 1
endif
so, when the computer sends (etc) "open pin5", the BS2-module will open pin5
the computer programming i think i can figure out on my own (never used serial port in programming, though)
SERIN 16,baud,[noparse][[/noparse]WAIT("Turn On Pin 5"),SPSTR 75]··
FOR x = 0 TO 74
·GET z,temp
·'do whatever you are going to do here'
Next
SERIN is the command to get data from the PC
16 is the communications pin (stamp to pc)
baud is the appropriate baud rate for the stamp you are using· (9600 for basic stamp, I believe)
Wait is the command to wait for a particular string
Get takes each character retrieved from the Serin, and reads it as a variable.
Definitely look at the SERIN in the help file.
SERIN 16, I9600, [noparse][[/noparse]DEC MyVal]
IF MyVal = 1 THEN
' Do something here
ENDIF
IF MyVal = 2 THEN
' Do something here...
ENDIF
And you'd send something like:
fprintf(serport, "1\n"); // This sends a "1" in a way the 'DEC' modifier will accept it.
or
fprintf(serport, "2\n"); // etc.
Main:
SERIN 16, I9600, [noparse][[/noparse]DEC MyVal] 'note that this limits you to 0-9
BRANCH MyVal, [noparse][[/noparse]DoSomething0, DoSomething1, DoSomething2]
DoSomething0:
RunSomeCommand
GOTO Main
DoSomething1:
RunSomeOtherCommand
GOTO Main
DoSomething2:
RunThisAndThat
GOTO Main
etc.
BRANCH will let you branch to up to 256 locations based on the value of MyVal. The labels consume no program space (I think?) and the execution would be faster than using IF...THEN loops.
http://www.stampplot.com
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
StampPlot - GUI and Plotting Software
Southern Illinois University Carbondale, Electronic Systems Technologies