PDA

View Full Version : PINK BS2P SPSTR issue



mbmosher
05-25-2006, 01:17 AM
Ok, so this is due tomorrow so any help is greatly appreciated.

I'm trying to get my BS2P to gather some data from a web form on my PINK, very similar to the demo program that came with the pink manual. But when ever the program gets to the SERIN GETPINK, baudPINK, 100, main, [SPSTR 64] ('American) it times out and goes back to main. Any pointers?

Here's the code:

' {$STAMP BS2p}
' {$PBASIC 2.5}
'American Dreams BS2P
'Matthew Mosher
'www.matthewbmosher.com

OUTPUT 1
OUTPUT 15
INPUT 14
OUTPUT 9
OUTPUT 10
INPUT 8
INPUT 11

requestPINK PIN 15
GETPINK PIN 14
printerOn PIN 1
rx PIN 8
tx PIN 9
rts PIN 10
cts PIN 11

baudPINK CON 240 '1021 = 2400
baudPRINT CON 240 '= 9600
linefeed CON 10
esc CON 27
inverse CON "{"
inverted CON 1
align CON "a"
center CON "1"

user VAR WORD
country VAR BYTE
statusPINK VAR BYTE
update VAR statusPINK.BIT1
pointer VAR BYTE
char VAR BYTE

PAUSE 1000

'InitializePrinter
HIGH PrinterOn
PAUSE 5000
SEROUT tx\cts, baudPRINT, [esc]
SEROUT tx\cts, baudPRINT, [inverse]
SEROUT tx\cts, baudPRINT, [inverted]
PAUSE 100
SEROUT tx\cts, baudPRINT, [esc]
SEROUT tx\cts, baudPRINT, [align]
SEROUT tx\cts, baudPRINT, [center]
PAUSE 100
SEROUT tx\cts, baudPRINT, 100, main, ["www.worldisbetter.com"]
SEROUT tx\cts, baudPRINT, 100, main, [linefeed]
SEROUT tx\cts, baudPRINT, 100, main, ["Add your dreams at"]
SEROUT tx\cts, baudPRINT, 100, main, [linefeed]
SEROUT tx\cts, baudPRINT, 100, main, [linefeed]
SEROUT tx\cts, baudPRINT, 100, main, ["by Matthew B Mosher"]
SEROUT tx\cts, baudPRINT, 100, main, [linefeed]
SEROUT tx\cts, baudPRINT, 100, main, ["American Dreams"]
SEROUT tx\cts, baudPRINT, 100, main, [linefeed]
SEROUT tx\cts, baudPRINT, 100, main, [linefeed]
DEBUG "printer on and initialization sent", CR
LOW PrinterOn

main:

'GETstatus:
SEROUT requestPINK, baudPINK, ["!NB0ST"]
SERIN GETPINK, baudPINK, [statusPINK]
PAUSE 1000
DEBUG "PINK status ", DEC update, CR
IF update = 0 THEN GOTO main

'NEWuser:
user = user + 1
SEROUT requestPINK, baudPINK, ["NB0W13:user", CLS]
DEBUG "user ", DEC user, CR

'GETcountry:
SEROUT requestPINK, baudPINK, ["!NB0R12"]
SERIN GETPINK, baudPINK, [country]
PAUSE 100
DEBUG "country ", DEC country, CR
IF country <> 49 THEN GOTO main

'American:
SEROUT requestPINK, baudPINK, ["!NB0R11"]
SERIN GETPINK, baudPINK, 100, main, [SPSTR 64]
PAUSE 100
DEBUG "data sent to bs2p", CR

'SetUpPrinter
HIGH PrinterOn
PAUSE 5000
SEROUT tx\cts, baudPRINT, [esc]
SEROUT tx\cts, baudPRINT, [inverse]
SEROUT tx\cts, baudPRINT, [inverted]
DEBUG "printer on", CR

'Printdream:
'line04:
FOR pointer = 96 TO 126
GET pointer, char
SEROUT tx\cts, baudPRINT, 100, main, [char]
DEBUG char
IF char = CLS THEN EXIT
PAUSE 100
NEXT
'line03:
FOR pointer = 64 TO 95
GET pointer, char
SEROUT tx\cts, baudPRINT, 100, main, [char]
DEBUG char
IF char = CLS THEN EXIT
PAUSE 100
NEXT
'line02:
FOR pointer = 32 TO 63
GET pointer, char
SEROUT tx\cts, baudPRINT, 100, main, [char]
DEBUG char
IF char = CLS THEN EXIT
PAUSE 100
NEXT
'line01:
FOR pointer = 0 TO 31
GET pointer, char
SEROUT tx\cts, baudPRINT, 100, main, [char]
DEBUG char
IF char = CLS THEN EXIT
PAUSE 100
NEXT

'PrintUser:
SEROUT tx\cts, baudPRINT, 100, main, [linefeed]
SEROUT tx\cts, baudPRINT, 100, main, [" "]
SEROUT tx\cts, baudPRINT, 100, main, [HEX user]

'EndPrint
SEROUT tx\cts, baudPRINT, 100, main, [linefeed]
SEROUT tx\cts, baudPRINT, 100, main, [linefeed]
SEROUT tx\cts, baudPRINT, 100, main, [linefeed]
DEBUG CR, "printer off", CR, CR
LOW PrinterOn

GOTO main


Thanks! Thanks! Thanks!

TimC
05-25-2006, 08:54 AM
Matthew,
The short answer is use longer timeouts when talking to the PINK like 250-300:




SEROUT NBReceive,Baud,["!NB0ST"]
SERIN NBSend,Baud,300,Loop,[Status]




Another way to attack the problem is to keep asking "Does the PINK has any changes for the stamp."
If you create a loop that keeps asking there will be only a few program delays and no timeouts.
The PINK example code never worked that well for me.

Regards
Tim

See this thread for an example of what I am talking about:
http://forums.parallax.com/showthread.php?p=568653

mbmosher
05-25-2006, 11:15 AM
Okay, got that all sorted out, this has been a really intense project. Anyway, as it turns out if the BS2P SPSTR ins less than 64 bytes the serin times out, although it still got whatever data was there. My loop sent it back to main after timeout, so I put a shorstring lable right after the serin and timed it out to shortstring and with a few other tweeks it works fine now. Ugh. Thanks for the reply Tim.

Ryan Clarke
05-26-2006, 01:29 AM
That is correct, you need to check for an end of data character or the SERIN will look for all 64 bytes of data.

Ryan

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support

RClarke@Parallax.com (mailto:RClarke@Parallax.com)