PDA

View Full Version : Another Serial Object Question...



Joms
07-17-2009, 04:08 AM
I know I am almost beating a dead horse here, but I have searched and don't quite understand what I am reading. I have looked at the FDS4Port, Full Duplex Serial, and Extended Duplex Serial objects but still have a few questions.

I am trying to input a continuous string of data. I have done this several times in the stamp but having problems finding the right command in the prop objects. Ideally I would like to use the FDS4Port object as I will be input two or three strings at the same time, but I can always use another object 3 times if I had to.
Basically I am looking for the proper wait command. The delimiter appears to be used differently then the wait command.

I do not have much code written yet as I am having problems getting started with this command. In Basic it would look something like this...

SERIN 15, 16572, [WAIT($A,$B,$C), variable]


Heres what I have for the start part of my program so far...





OBJ
Data: "FDS4Port"

PUB Start
Data.Init
Data.AddPort(0,26,Data#PINNOTUSED,Data#PINNOTUSED, Data#PINNOTUSED,Data#DEFAULTTHRESHOLD,Data#OCTX,48 00)
Data.AddPort(1,27,Data#PINNOTUSED,Data#PINNOTUSED, Data#PINNOTUSED,Data#DEFAULTTHRESHOLD,Data#OCTX,48 00)
Data.Start

Main

PUB Main

Mike Green
07-17-2009, 04:49 AM
There is no WAIT equivalent. You have to do it yourself like:


REPEAT
temp := Data.rx(0)
UNTIL temp == $A or temp == $B or temp == $C
variable := Data.rx(0) ' For a single byte value
variable |= Data.rx(0) << 16 ' Add for the 2nd byte of a 16-bit word value

JonnyMac
07-17-2009, 04:49 AM
Assuming you have a serial input object called 'term' you could create custom methods; one to wait on a character (any byte, actually), another to wait on a string:



pub waitch(ch) | check

repeat
check := term.rx
until (check == ch)


pub waitstr(pntr) | count, cpntr, check

count := strsize(pntr)
cpntr := pntr

repeat while count
check := term.rx ' get character from stream
if (check == byte[cpntr]) ' compare to string
--count ' if match, update count
++cpntr ' and character pointer
else
count := strsize(pntr) ' else reset count
cpntr := pntr ' and character pointer


To handle your specific example you would do this:



waitstr(string($A, $B, $C))
variable := term.rx

Post Edited (JonnyMac) : 7/16/2009 8:56:01 PM GMT