SERIN/OUT Via Web
Max
Posts: 13
Hey all, I'm a physical computing newbie who's having some trouble with his midterm.
The goal: Allow someone to press a button on a website to switch an LED on and off.
So far, my understanding of the process is that I'll need to enable Serproxy on the machine attached to the BASIC Stamp which will receive information via TCP/IP streams converted to RS-232 streams by Serproxy. I want to start by just getting SERIN to work on my local machine without Serproxy.
I did a quick search through some recent posts and found a few threads that seemed pertinent, but I'm missing a few basic assumptions somewhere and I'm hoping you folks can help me out, since I couldn't glean anything from the help files (well-written as they are).
Here's my PHP code:
Here's my BS2 code:
I don't see why this isn't working. What I believe should happen is that $string should be converted to the length of the pause between turning the LED (connected to input pin 7). So, if $string is "2000\n" and you load the page, having already loaded the program onto the BASIC stamp, the stamp should receive $string via SERIN, pause for half a second, then proceed with HIGH 7.
What I don't understand is the exact significance of HIGH 2 and LOW 2. Is 2 the SERIN pin?
Thanks in advance, all!
The goal: Allow someone to press a button on a website to switch an LED on and off.
So far, my understanding of the process is that I'll need to enable Serproxy on the machine attached to the BASIC Stamp which will receive information via TCP/IP streams converted to RS-232 streams by Serproxy. I want to start by just getting SERIN to work on my local machine without Serproxy.
I did a quick search through some recent posts and found a few threads that seemed pertinent, but I'm missing a few basic assumptions somewhere and I'm hoping you folks can help me out, since I couldn't glean anything from the help files (well-written as they are).
Here's my PHP code:
`mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=off`; $fp = fopen ("COM1:", "w+"); if (!$fp) { echo "Uh-oh. Port not opened."; } else { $string = "2000\n"; fputs($fp, $string); echo $string; fclose ($fp); }
Here's my BS2 code:
' {$STAMP BS2} ' {$PBASIC 2.0} MyByte VAR Byte INPUT 7 Main: HIGH 2 SERIN 16, 16384, [noparse][[/noparse]DEC MyByte] LOW 2 PAUSE 500 HIGH 7 PAUSE MyByte LOW 7 PAUSE 100 HIGH 7 PAUSE MyByte LOW 7 PAUSE 100 GOTO MAIN
I don't see why this isn't working. What I believe should happen is that $string should be converted to the length of the pause between turning the LED (connected to input pin 7). So, if $string is "2000\n" and you load the page, having already loaded the program onto the BASIC stamp, the stamp should receive $string via SERIN, pause for half a second, then proceed with HIGH 7.
What I don't understand is the exact significance of HIGH 2 and LOW 2. Is 2 the SERIN pin?
Thanks in advance, all!
Comments
Change your baudmode parameter from 16384 to 16468 and you should be good to go.
As far as the Pin 2 reference is concerned, the person who wrote that program probably had an LED on that pin and was interested to see if and when the SERIN completed. That's just a guess, however.
Regards,
Bruce Bates
Thanks! You have saved my life. I knew I should have read the baudmode portion of that help file closer... do you think I'll be able to figure out why 16468 worked and 16384 didn't by examining the documentation closer? I'd like to know how this stuff happens on as many levels as possible.
Thanks again. I hope no one minds me posting more questions to this thread as my project progresses...
I'll be happy to tell you, but as you indicated it WOULD be best for you to go back and verify how you made the error. Nothing wrong with trial and error learning, so long as it doesn't become a way of life
What I suspect you did was to account for INVERTED logic (16384) in the BAUDMODE and neglected to add in the baud rate. The BAUDMODE parameter is NOT just the baud rate. It's composed of a number of elements, of which baud rate is only one.
Regards,
Bruce Bates
How can I alter this code so that the web-user can turn on and off three different lights? For now, I'm not worried about refreshing the page every time they click - I can put JavaScript in later. I've seen code that looks like you can transfer multiple arguments using SERIN by just separating them with commas, but I can't get it to work.
Also, is it erroneous to assume that if I transfer the DEC number 7 using SERIN to the variable "MyByte", I can then use "HIGH MyByte" and "LOW MyByte" to turn Input 7 on and off? It seems like it's wrong, because I couldn't get it to work. Is there another way to do this?
Thanks, all.
I assume that you are using the 'computer' for the ethernet interface, then connecting to your Stamp via RS232? Is this correct?
Ryan
That's correct. The computer has a local HTTP server that contains the PHP script. I'm going to use Serproxy when I move the script to an external HTTP server.
HTH
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...