stuck
MTSkull
Posts: 4
I am creating a C# application that will send a short command string to a BS2, which will then control motors and senors to do stuff. I am stuck on how to get the stamp to respond to the data being sent. I am sending 5 hex bytes starting with hex00 followed by 4 more hex bytes(1 to 9) that will eventually tell the stamp what to do. Also in the print it routine, the calling application can read the debug print out, but would SerOut be more appropriate there?
Thanks
Thanks
' {$STAMP BS2} ' {$PBASIC 2.5} 'Serial Comms COmmands SI PIN 0 ' serial input FC PIN 1 ' flow control pin #SELECT $STAMP #CASE BS2, BS2E, BS2PE T1200 CON 813 T2400 CON 396 T9600 CON 84 T19K2 CON 32 T38K4 CON 6 #ENDSELECT Inverted CON $4000 Open CON $8000 Baud CON T38K4 + Inverted 'Serial Imput Variables ExternInput VAR Byte StartCol VAR Byte StartRow VAR Byte StopCol VAR Byte StopRow VAR Byte 'Variables for Print function idx VAR Word ' current location number phrase VAR Nib ' current phrase number char VAR Byte ' character to print 'Response Codes Pickup DATA 0,"Pickup",CR DropOff DATA 0,"Drop Off",CR MovingX DATA 0,"Moving X",CR MovingY DATA 0,"Moving Y",CR MovingZUp DATA 0,"Moving Z Up",CR MovingZDn DATA 0,"Moving Z Down",CR Completed DATA 0,"Completed",CR BigErr DATA 0,"Big Error",CR LittleErr DATA 0,"Little Error",CR Main: ExternInput = 255 DO SERIN SI\FC, Baud, [noparse][[/noparse]ExternInput] ' receive one byte ' DEBUG letter ' display on screen IF (ExternInput = 0)THEN GOSUB Is_True GOSUB Operate_Gantry ENDIF PAUSE 1000 ' wait one second LOOP ' repeat forever END Get_Move_Command: SERIN SI\FC, Baud, [noparse][[/noparse]StartCol] SERIN SI\FC, Baud, [noparse][[/noparse]StartRow] SERIN SI\FC, Baud, [noparse][[/noparse]StopCol] SERIN SI\FC, Baud, [noparse][[/noparse]StopRow] RETURN Operate_Gantry: 'just send this data back for now, later do stuff here FOR phrase = 1 TO 11 ' Print blocks one by one LOOKUP (phrase - 1), [noparse][[/noparse]MovingX, MovingY, MovingZDn, Pickup, MovingZUp, MovingX ,MovingY, MovingZDn, DropOff, MovingZUp, Completed], idx GOSUB Print_It PAUSE 1000 ' Pause for 5 seconds NEXT RETURN Print_It: DO READ idx, char ' Get next character idx = idx + 1 ' Point to next location IF (char = 0) THEN EXIT ' If 0, we're done with block DEBUG char ' Otherwise, transmit it LOOP RETURN ' Return to the main routine
Comments
It'll wait·to receive a·$00, which prompts the stamp to take in the four following bytes as command data.
You could add a timeout for the WAIT, too.
I found this snipit in the PBasic Guide book, it echoes back what I send to it but then it should start transmitting all of the string data, which never seems to happen.
Thanks
Brian
PS -- BS2 baudmode for 9600, inverted, 8-N-1·is: 16468 ($4054)
PPS -- I think that it should be "true", too, and that's: 84 ($54).··Is your PC/C-program sending "inverted"?
PPPS -- PBASIC Help informs that at speeds > 2400 baud that the Stamp might not cope with Qualifiers, so you might have to change that, too.· I have a GPS project and its data comes in at 4800bps and I use Qualifiers (WAIT and STRs) with it just fine.· It waits for the appropriate sentence/header and then starts accepting data, much the way you're trying to.
Post Edited (PJ Allen) : 3/22/2008 6:45:36 PM GMT
Which brings to mind a question, is there a way to step through the code line by line while it is executing?