PDA

View Full Version : String help and the Dat indexing problem



grasshopper
01-10-2009, 11:30 PM
OBJ
Ser : "FullDuplexSerial"

Var

Byte RxDat[30] ' for serial data buffer

Pub Main

Ser.Start(USBRx,USBTx,OFF,19200)

REPEAT
IF (ser.rxcheck == "(")
GetCom

Pub Getcom | stringCount, Scrap, X

Scrap~
StringCount~

Repeat UNTIL (RxDat[ StringCount ] := SER.rx ) == ")"
StringCount ++

Repeat X from 1 to 3
IF (textComp(@rxDat[ 0 ],@RX[ X ],7) == TRUE)

Case X
1 : Ser.str(string("One"))
2 : Ser.str(string("Two"))
3 : Ser.str(string("Three"))

Dat
RX[ 1 ] BYTE "One A11",0
Rx[ 2 ] BYTE "Two B22",0
Rx[ 3 ] BYTE "Three 33",0




My problem is in the Dat section. I cant index through the library of commands. Is there a way to do this?

grasshopper
01-11-2009, 02:08 AM
I solved it! Yea

Phil Pilgrim (PhiPi)
01-11-2009, 02:48 AM
So show us what you did.

-Phil

grasshopper
01-11-2009, 04:38 AM
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

USBRx = 31 ' Usb comm RX pin
USBTx = 30 ' Usb comm TX pin
BAUD = 19200 ' Baud rate
Leng = 3 ' Size of the Table

OBJ
Ser : "FullDuplexSerial"

Dat
Val0 BYTE "D1 XX ?",0 'A string input from computer
Val1 BYTE "D1 X1 ?",0 'A string input from computer
Val2 BYTE "D1 Y2 S",0
Table
Byte @Val0, @Val1, @Val2

Var
Byte RxDat[ 30 ]

Pub Main
Ser.Start(USBRx,USBTx,0,9600)

REPEAT
IF (ser.rxcheck == $5B)
GetCom

Pub Getcom | stringCount, Scrap ,X

Scrap~
StringCount~
X := 0
Repeat Until (RxDat[ StringCount ] := SER.rx ) == $5D
StringCount ++

Repeat Leng
IF (TextComp(@rxDat[ 0 ],@@Table[ X ],7) == TRUE)
quit
X++

Case X
0 : Ser.str(string("[D1 XX ?]"))
1 : Ser.str(string("[D1 X1 ?]"))
2 : Ser.str(string("[D1 Y2 S]"))

Pub TextComp(stringA,stringB,Count)

Repeat Count
IF (Byte[stringA++] <> Byte[stringB++])
Return False
Return True





This is it. Sorry i did not post the code a bit ago, but it did not seem like anyone was interested.

Post Edited (grasshopper) : 1/10/2009 8:44:57 PM GMT

Phil Pilgrim (PhiPi)
01-11-2009, 05:05 AM
My only suggestion would be to change the Table values (@Val0, et al.) to WORDs instead of BYTEs. You may have lucked out with their offsets being less than 256.

-Phil