PHP and basic stamp
Carlo
Posts: 23
hi guys,
I was wondering if someone could solve this problem.
I would like to write a simple program, possibly using PHP that will send an 8 bit command to the masic stamp throught the serial port. I found a few PHP scripts on the web like this one
http://www.phparch.com/discuss/index.php/m/3312/0/#msg_2994
and this one
http://www.phpfreaks.com/quickcode/code/156.php
but when I try the program it doesn't seem to work. Would anyone know if what I am trying to do is even possible? Or is there some other programming language that I can use that works better? I suggested PHP since I already know how to use it quite well.
Thanks for your help!!
Carlo
I was wondering if someone could solve this problem.
I would like to write a simple program, possibly using PHP that will send an 8 bit command to the masic stamp throught the serial port. I found a few PHP scripts on the web like this one
http://www.phparch.com/discuss/index.php/m/3312/0/#msg_2994
and this one
http://www.phpfreaks.com/quickcode/code/156.php
but when I try the program it doesn't seem to work. Would anyone know if what I am trying to do is even possible? Or is there some other programming language that I can use that works better? I suggested PHP since I already know how to use it quite well.
Thanks for your help!!
Carlo
Comments
And on the BS2 you need:
SERIN 16, 16684, [noparse][[/noparse]DEC MyByte]· ' This recieves the a '\n'·delimited number string
PAUSE 100
SEROUT 16, 16684, [noparse][[/noparse]DEC MyByte]· ' This sends it back.
And you need a DB-9 straight-through cable.
And you need to set DTR FALSE (leaving it true holds the BS2 in reset).
And you need to know that the BS2 hardware will echo everything you send it, before doing anything else with it.
Post Edited (allanlane5) : 3/18/2005 4:05:07 PM GMT
are you using the code which requires the serproxy program? I didn't understand which variable I need to set to zero and is the DB-9 streight-through cable the same one I am using to program the basic stamp?
Please excuse my ignorance!!
Carlo
Set "$serproxy=false", or just cut and paste from the non-serproxy stuff (you don't actually need serproxy, it seems). And yes, the DB-9 cable you use is the same one you used to program the BS2.
for the PHP:
<?php
`mode com4: BAUD=9600 PARITY=N data=8 stop=1 xon=off`;
$fp = fopen ("COM4:", "w+");
if (!$fp) {
echo "Uh-oh. Port not opened.";
} else {
$string = 100;
fputs ($fp, $string );
echo $string;
fclose ($fp);
}
?>
and for the stamp:
' {$STAMP BS2}
' {$PBASIC 2.5}
MyByte VAR Byte
HIGH 2
SERIN 16, 16684, [noparse][[/noparse]DEC MyByte] ' This recieves the a '\n' delimited number string
PAUSE 100
INPUT 2
SEROUT 16, 16684, [noparse][[/noparse]DEC MyByte] ' This sends it back.
I inserted HIGH 2 and INPUT 2 so that I would see if the program moved on from the SERIN command, I couldn't think about another way to see if it actually worked.
$string = "100\n"; # We want the string value of 100, followed by a CR, in $string
fputs($fp, $string);
2. Your BS2 program needs to be:
MyByte VAR BYTE
Main:
HIGH 2
SERIN 16, 16384, [noparse][[/noparse]DEC MyByte] ' Sorry, I got the constant wrong. Look up SEROUT in the help.
' This is 84 for 9600 baud, plus $4000, for Inverted. You need both.
LOW 2 ' NOT 'Input 2' -- that only makes it float. 'LOW 2' puts a hard zero on the line.
PAUSE 500
SEROUT 16, 16384, [noparse][[/noparse]"Got: ", DEC MyByte, CR]
GOTO MAIN
What this will do is wait in the SERIN until it gets the string, convert the string to a value, put the value into MyByte. It will then drop the P2 pin, then pause 1/2 second (500 milliseconds). Then it wil echo the byte as a string, and do a GOTO Main to do it again. It will 'wait' in the SERIN until the next time.
And I am assuming you are using the BOE, which will let your program run even though you are asserting DTR high.
·
I hope not to bother you with any more silly problems!
Carlo