using serin with strings
KB3JJG
Posts: 95
Greetings,
I have been having some trouble getting my realbasic application to send commands to my stamp. The realbasic serial control only sends strings and I think thats where my problem is. I have looked at the serin command reference in stampworks·over and over, used google site search to search these forums and havnt had any luck after many hours.
I am trying to send data to a stamp, this data is then relayed to an parallax ssc. I am using pin 16 at the moment for the communication. The data I send consists of 3 chunks, a sync number(255), a servo channel number and a position between 250-1250. I have tried many different variations of serin using the wait command· and the dec and str modifiers. Here is the pbasic code I have tried
' {$STAMP BS2}
' {$PBASIC 2.5}
pos·· VAR·· Word
ra VAR Byte
sdat CON 15
baud CON 396
chan VAR Word
ra = 0
Main:
SERIN 16,16780, [noparse][[/noparse]wait (255), dec chan,dec pos]
SEROUT sdat, Baud+$8000,[noparse][[/noparse]"!SC", chan, ra, pos.LOWBYTE, pos.HIGHBYTE, CR]
GOTO Main
I have tried variations of the serin command like
SERIN 16,16780, [noparse][[/noparse]wait ("255"), dec chan,dec pos]· ****quotes around 255
SERIN 16,16780, [noparse][[/noparse]wait ("255"),·str chan,str pos]· ***str modifier instead of dec
The string coming out of realbasic that I am using to test is 2551280·· 255 sync byte,servo channel 1, and pos 280.· I know I have all good components as I am able to replicate this exact idea in visual basic. Can someone help me get pointed in the right direction. I guess the real question is how do I·accept strings with serin and is their something similiar to visual basic's val()· in pbasic. Thanks in advance!
KB3JJG
I have been having some trouble getting my realbasic application to send commands to my stamp. The realbasic serial control only sends strings and I think thats where my problem is. I have looked at the serin command reference in stampworks·over and over, used google site search to search these forums and havnt had any luck after many hours.
I am trying to send data to a stamp, this data is then relayed to an parallax ssc. I am using pin 16 at the moment for the communication. The data I send consists of 3 chunks, a sync number(255), a servo channel number and a position between 250-1250. I have tried many different variations of serin using the wait command· and the dec and str modifiers. Here is the pbasic code I have tried
' {$STAMP BS2}
' {$PBASIC 2.5}
pos·· VAR·· Word
ra VAR Byte
sdat CON 15
baud CON 396
chan VAR Word
ra = 0
Main:
SERIN 16,16780, [noparse][[/noparse]wait (255), dec chan,dec pos]
SEROUT sdat, Baud+$8000,[noparse][[/noparse]"!SC", chan, ra, pos.LOWBYTE, pos.HIGHBYTE, CR]
GOTO Main
I have tried variations of the serin command like
SERIN 16,16780, [noparse][[/noparse]wait ("255"), dec chan,dec pos]· ****quotes around 255
SERIN 16,16780, [noparse][[/noparse]wait ("255"),·str chan,str pos]· ***str modifier instead of dec
The string coming out of realbasic that I am using to test is 2551280·· 255 sync byte,servo channel 1, and pos 280.· I know I have all good components as I am able to replicate this exact idea in visual basic. Can someone help me get pointed in the right direction. I guess the real question is how do I·accept strings with serin and is their something similiar to visual basic's val()· in pbasic. Thanks in advance!
KB3JJG
Comments
A name would be handy, unless you like that alphabet soup
Here's what I'd be tempted to try:
SERIN 16,16780, [noparse][[/noparse]wait (255), dec chan, dec3 pos]
After that I'd also add the following DEBUG command to find out what we're actually receiving:
DEBUG? DEC chan, DEC3 pos
Since I haven't had my second cup of coffee yet, let me offer the following caveat which may be appropriate. DEBUG is a special case of SEROUT which operates at a fixed baudrate of 9600 BPS through SOUT (pin port 16). You are using pin port 16 and 2400 BPS in your baudmode parameter. This may cause an unseen conflict (by including the DEBUG command in a program which uses pin port 16). To avoid this you can change the RealBasic program to output 9600 baud and change your SERIN to 16468 to avoid that possible problem. Alternatively, you could also use a different pin port to avert the possibility of this potential conflict.
Regards,
Bruce Bates
On SERIN, the DEC modifier expects a String (ending with CR, I believe). It then converts the String to a Byte or Word, and stores that in the variable.
If you really are sending the STRING "2551280", that doesn't make much sense. You need a sync BYTE, not the string "255", that kind of defeats the purpose.
Others have used: "?010280" -- being a ? for a sync byte, channel 01 (allows more than 9 channels) and "0280" for position (allows up to 9999 position values).
An alternative for the bs2 might be "?01", <CR>, "0280", <CR>. Then on the BS2 you can do:
SERIN 16, BaudMode, [noparse][[/noparse]WAIT ("?"), DEC Channel, DEC Position]
and it should work.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://ca.geocities.com/steve.brady@rogers.com/index.html
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
Regarding my question, thanks for the suggestions! I am stuck at my office today but I am eager to get home and try out the tips! I will post my results!
Thanks!
·