Word capped out at 255?
weekdayhack
Posts: 3
I am using the serin/serout commands to comminicate between two stamps.
I've pulled out the portion of my code that's giving me problems and I've simplified it to its lowest form (below and attached). I'm still having problems. I have an LCD and switch just for a sanity check. Everything operates as it should, but if I try to send "setpoint" from Stamp1 to Stamp2 with a value larger than 255, it just rolls it over. Not sure why I'm being capped at a Byte when I've declared "setpoint" as a Word. Probably has something to do with the fact that it's serial. Do I need to break the value up into managable pieces (size wise) using some mathematical operator in Stamp1 and then recombine them once they've reached Stamp2?·Seems strange to me that the serin/serout commands would be limited to·transferring just a Byte of data, but perhaps that makes sense given the serial is just 8-bit...???··Obviously clueless here. Any advice you can give is much appreciated.
-Neil
'Stamp1 (sends value)
' {$STAMP BS2px}
' {$PORT COM6}
· setpoint VAR Word
· setpoint=255
Send_value
· SEROUT 0\1,16468,[noparse][[/noparse]setpoint]
· GOTO Send_value··················· 'loop ensures that Stamp2 has a chance to recieve the value
'Stamp2 (recieves value)
' {$STAMP BS2px}
' {$PORT COM5}
· setpoint VAR Word
· btn7 VAR Bit
· SEROUT 14,188,[noparse][[/noparse]254,88] 'clear screen
· SEROUT 14,188,[noparse][[/noparse]254,71,20,4,254,75,254,84]'no cursor
button_enter:
· BUTTON 7,0,255,255,btn7,1,button_enter··········· 'allows me to make sure I can recieve the value when I·want it
· SEROUT 14,188,[noparse]/noparse]254,71,1,1,[color=red]"Setpoint="[/color············ 'just displaying it here instea of the debug window; obviously I get the same value both places
· GOTO Recieve_values
Recieve_values
· SERIN 0\1,16468, 50, Recieve_values, [noparse][[/noparse]setpoint]
· SEROUT 14,188,[noparse][[/noparse]254,71,1,2,DEC setpoint]
· GOTO Recieve_values································ 'loop ensures that I recieve the value if the timeout doesn't catch it for some reason
I've pulled out the portion of my code that's giving me problems and I've simplified it to its lowest form (below and attached). I'm still having problems. I have an LCD and switch just for a sanity check. Everything operates as it should, but if I try to send "setpoint" from Stamp1 to Stamp2 with a value larger than 255, it just rolls it over. Not sure why I'm being capped at a Byte when I've declared "setpoint" as a Word. Probably has something to do with the fact that it's serial. Do I need to break the value up into managable pieces (size wise) using some mathematical operator in Stamp1 and then recombine them once they've reached Stamp2?·Seems strange to me that the serin/serout commands would be limited to·transferring just a Byte of data, but perhaps that makes sense given the serial is just 8-bit...???··Obviously clueless here. Any advice you can give is much appreciated.
-Neil
'Stamp1 (sends value)
' {$STAMP BS2px}
' {$PORT COM6}
· setpoint VAR Word
· setpoint=255
Send_value
· SEROUT 0\1,16468,[noparse][[/noparse]setpoint]
· GOTO Send_value··················· 'loop ensures that Stamp2 has a chance to recieve the value
'Stamp2 (recieves value)
' {$STAMP BS2px}
' {$PORT COM5}
· setpoint VAR Word
· btn7 VAR Bit
· SEROUT 14,188,[noparse][[/noparse]254,88] 'clear screen
· SEROUT 14,188,[noparse][[/noparse]254,71,20,4,254,75,254,84]'no cursor
button_enter:
· BUTTON 7,0,255,255,btn7,1,button_enter··········· 'allows me to make sure I can recieve the value when I·want it
· SEROUT 14,188,[noparse]/noparse]254,71,1,1,[color=red]"Setpoint="[/color············ 'just displaying it here instea of the debug window; obviously I get the same value both places
· GOTO Recieve_values
Recieve_values
· SERIN 0\1,16468, 50, Recieve_values, [noparse][[/noparse]setpoint]
· SEROUT 14,188,[noparse][[/noparse]254,71,1,2,DEC setpoint]
· GOTO Recieve_values································ 'loop ensures that I recieve the value if the timeout doesn't catch it for some reason
Comments
SEROUT 0\1,16468,[noparse][[/noparse]setpoint.lowbyte,setpoint.highbyte]
and
SERIN 0\1,16468,50,Recieve_values,[noparse][[/noparse]setpoint.lowbyte,setpoint.highbyte]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i
http://www.parallax.com/Store/Books/BASICStamp/tabid/168/CategoryID/42/List/0/Level/a/ProductID/143/Default.aspx?SortField=ProductName%2cProductName
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Parallax Tech Support·
-Neil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
Eight bits is not universal, and did not come first. Few people use Baudot nowadays, but some do -- and Baudot is a five-bit convention (plus start and stop bits), and was once extremely common (like my across-the-street neighbors,·about the most common people I've ever had the misfortune to meet). I imagine there have been other conventionss, of different lengths.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i
Post Edited (Carl Hayes) : 11/20/2008 11:48:42 PM GMT
$PORT?!?!· You mean you can specify which COM port the BS2 will use for SERIN/SEROUT?
And here I've been scrambling about for the last few days pestering all sorts of people with how to do this and IT'S IN THE BOOK?!
AAARRRRGGGHHHHHHH!!!!!!!!!!!!!!!!!!!!!!!!
(breathe Dave, breath....)
I'm better now.
OK - before I go running off to check this out, does this directive work when there's a USB adapter sitting between the BOE serial port and the PC's USB port?
DJ
Post Edited (davejames) : 11/21/2008 12:46:47 AM GMT
The Stamp has no idea whether a USB adapter is present or not. All it knows is that there is supposed to be a logic level serial port. There's circuitry on the Stamp module to allow direct connection of the programming port to an RS232 serial port (or USB to RS232 adapter).
The $PORT directive specifies which port on the PC your Stamp is attached to.· Many PCs have multiple serial ports, and you might attach a Stamp to any, or all.· The PC I'm writing this on has Stamps on COM1, COM2, and COM5 at the moment.· Use $PORT to say which Stamp to download to.· If there's no $PORT directive, the Editor will ask which one.· That's all.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i
It's quite convenient to do this when programming multiple stamps on a single board, with the alternative being unplugging and reconnecting the serial cable to the other connector on the board...and then back and forth in an endless loop of rs232 loathing.
-Neil
(an excerpt from a recent email to Jeff Martin, a very patient Parallax apps guy):
"...I am beginning to believe that my requirement has turned into a classic case of knowing how to ask the right question and RTM (read-the-manual)."
I did not see the $PORT directive until yesterday, so I had no idea which COM port to use in my application. That question drove me down the bunny-trails of attempting to reprogram the FTDI VCP to writing my own "Stamp-present" detection routine.
So, now I know - and knowing is half the battle (GO JOE!).
A big lesson learned is asking the right question. If I had done that, you all would have pointed me to $PORT a week ago relieving me of a ton-o-confusion.
Thanks much,
DJ
Perhaps I missed something somewhere…the $PORT directive is useful for one thing really…if you have multiple serial ports and you don’t want the BASIC Stamp Editor checking them all for a BASIC Stamp when programming. It’s really useful if you have multiple BASIC Stamps connected to the PC, for example when testing RF Modules and one has TX code and the other has RX code. You can specify the TX code to go right to the TX board instead of prompting you. It doesn’t affect inability to program a BASIC Stamp or not find one, unless the directive exists for a port which the BASIC Stamp is not on. Perhaps I missed the underlying issue.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
Again, my situation has been a combination of me not understanding the technical issues of what I need to do, me not asking the right questions, me not understanding what the Stamp Reference manual is saying, and so on, and so on.
I had a Friday afternoon discussion with Mr. Martin (very nice internal Parallax software guy), which has clarified my need and the steps to achieve it. Evidently I'm one of a small number of people that have this particular requirement.
So, yes, I now understand the use of $PORT and how it will not help my efforts. Mr. Martin has pointed me to, and sent some info that discusses COM port detection. Mr. Pilgrim has also made a potentially useful suggestion.
I'm standing down from pestering everybody for a few days until I can read through Mr. Martin's material and formulate more focused questions.
Thanks for your input.
Happy Thanksgiving everyone,
DJ