Help with my code dealing with a table ? ?
I am basically trying "again" to send data over to my propeller using the Full duplex object. The idea is to send over a string from the PC and once the propeller receives it it can exacute a command accordingly.
here is what i have so far
can some one help me write the code? I wish to look up strings of data in a table then my propeller can do something given the string.
here is what i have so far
{
}
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
LCD : "LCDOBJECT"
ser : "256_FullDuplexSerial"
VAR
Long NAME
PUB Start | Index , Temp
SER.start(31,30,0,9600)
lcd.init
repeat
LCD.cls
repeat
Temp := ser.rx
While ser.rxcheck > 0
Index := 0
repeat
Temp := myString[noparse][[/noparse]index++]
lcd.writeOut(Temp)
waitcnt (1_000_000 * 50 + cnt )
While Temp > 0
DAT
myString byte "hello world",0
myString1 byte "This is a test",0
can some one help me write the code? I wish to look up strings of data in a table then my propeller can do something given the string.

Comments
{ } CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 OBJ LCD : "LCDOBJECT" ser : "256_FullDuplexSerial" VAR Long NAME PUB Start | Index , Temp SER.start(31,30,0,9600) lcd.init repeat LCD.cls repeat Temp := ser.rx While ser.rxcheck > 0 result := 0 repeat while Temp := table[noparse][[/noparse] result++ ] Case table 1: lcd.str(string("hello")) 2: lcd.str(string("This is a test")) DAT table byte"hello" byte "This is a test"do you mean you have 3 or maybe 255 strings
and with each string the propeller should do something different ?
a much easyier solution could be to just send ONE byte.
Now you are maybe thinking: oh how should i keep the overview if i have to deal with numbers from 1 to 255 ?
that's no problem you can define constants
CON Hello_World = 1 DoSomethingElse = 2 VAR Byte RcvdByte 'then inside the code it looks like this if RcvdByte = Hello_World LCD.Str(String("Hello World")) if RcvdByte = DoSomethingElse 'do something call another PUB-Method or what everetc.
if i look into your sourcecode i do not understand what you want to to
could you please comment EACH line of your code and write what YOU THINK it does
if i try to understand
repeat
Temp := ser.rx
While ser.rxcheck > 0
get bytes out of the receivebuffer and OVERWRITE each last received bytevalue by the next one that is received
Temp can hold only ONE long
if you want to receive more than one byte
you have to define an array of bytes
there is an object with name "serialmirror" in the object exchange
Inside of this object is a method RxStr which receveives a complete string that terminates with a carriage return
it works like this: the bytes of the string are stored into an bytearray
CON MaxStrLen = 16 ' maximum length that is required VAR Byte dataIn[noparse][[/noparse]MaxStrLen] ' BufferArray for strings up to MaxStrLen-1 characters last byte is the carriage return Byte MyCmd[noparse][[/noparse]MaxStrLen] PUB RxStr (stringptr) : Value | ptr {{ Accepts a string of characters - up to 15 to be passed by reference String acceptance terminates with a carriage return or the defined delimiter character. Will accept up to MaxStrLen - 1characters before passing back. Serial.Rxstr(@MyStr) ' accept serial.str(@MyStr) ' transmit }} ptr:=0 'set index of array to 0 bytefill(@dataIn,0,MaxStrLen) 'fill up array "datain" with 0s dataIn[noparse][[/noparse]ptr] := Rx 'get byte out of receivebuffer and store into BufferArray "dataIn" ptr++ 'incement indexpointer repeat while ((DataIn[noparse][[/noparse]ptr-1] <> 13) and (ptr < MaxStrLen)) ' repeat until a carriage return (13) is received or maximumlength is reached dataIn[noparse][[/noparse]ptr] := RX 'get byte out of receivebuffer and store into BufferArray "dataIn" ptr++ 'incement indexpointer dataIn[noparse][[/noparse]ptr-1]:=0 'after finishing receiving change last byte of BufferArray from 13 to 0 (zero-terminated string) byteMove(stringptr,@datain,MaxStrLen + 1) 'copy the content of the BufferArray "datain" into the bytearray specified by parameter "stringptr" ' a call of the method RxStr looks like this RxStr(@MyCmd) 'the "@"-Operator means the parameter is NOT the bytearray itself. It is the RAM-Adress of the bytearray 'at the end of the method RxStr there is a command bytemove. It does copy the bytes from RAM-Adress of "dataIn" to RAM-Adress of "MyCmd"if you have more questions feel free to post CONCRETE questions
regards
Stefan
Not really. Take it a step at a time and try and get one thing understood and working before trying to combine multiple things which aren't understood and don't work.
Let's start with reading a received character - have you read the comments in the Full Duplex Serial object ? For rxcheck ...
'' Check if byte received (never waits)
'' returns -1 if no byte received, $00..$FF if byte
So to read a received byte, assign the returned value for a call to rxcheck, then see if that value was greater or equal to zero, if so something was received, otherwise try again ...
Alternatively, save doing all that yourself and simply call the rx method and that waits until something is received then returns ...
It's either one way or another. No need to call rxcheck after calling rx unless you are trying to do something far more complicated than it appears you are.
I don't know what hardware you have but I recommend connecting up a TV then you have a very easy to use debugging display which can show what's received and what's happening in your program ...
tv.Start(TV_PIN) repeat rxdByte := rx tv.Str(String("Received char of ASCII value : ")) tv.Hex( rxdByte, 2 ) tv.Out( 10 )