Shop OBEX P1 Docs P2 Docs Learn Events
strcomp doesn't seem to evaluate right - Please help — Parallax Forums

strcomp doesn't seem to evaluate right - Please help

Shane MShane M Posts: 58
edited 2009-06-27 18:35 in Propeller 1
I am basically reading from a serial port. (Currently just typing a word).

My routine should receive the string (it does), see if the string received (strin)·is DIFFERENT from the last time (using strlast) and if NOT the same I am having my EMIC text to speech chip say the word AND copy the strin to strlast.· If it IS the same it should simply ignore the block.

I was on support for a while and even the support guy was stumped.

Here is the code snippet:

 repeat
 
    'serial.RxStrTime(5000,@strin)
    serial.RxStr(@strin)

    'if the string received is different then say the word
    if (not strcomp(@strin,@strlast))
      emic.say(@strin, true)  'have emic say text
      
      serial.str(@strin) ' this is just a debug serial dump for myself
      emic.WaitNotBusy  ' wait until emic is not busy

 
      CopyString(@strlast,@strin) ' copy the strin to strlast (this DOES work)

 
      emic.say(@strlast, true)  'have emic say text 

      serial.dec(strsize(@strin)) ' I dumped this to make sure the strings were viewed as the same size
      serial.dec(strsize(@strlast))  
    
    emic.WaitNotBusy              

 
'this is my copy routine.  It does work.    
PUB CopyString(dest,src)
  byteMove(dest,src,15)
  dest[noparse][[/noparse]strsize(src)+1]:=0


Basically it always evaluates as if the strings don't match.

Can anyone help me?

Shane Merem
www.websiteforge.com
www.magnusoft.com

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-27 00:33
    How do you define the strings and their initial contents?
  • Shane MShane M Posts: 58
    edited 2009-06-27 03:13
    VAR
    Byte strin[noparse][[/noparse]15]
    Byte strlast[noparse][[/noparse]15]

    Thanks for your help
  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-27 03:32
    You need to define them as 16 byte strings. There must be space for 15 string characters plus a zero byte terminator. You should initialize them before you use them. I'd do

    strin[noparse][[/noparse] 0 ] := 0
    strlast[noparse][[/noparse] 0 ] := 0

    CopyString also has to be

    bytemove(dest,src,strsize(src)+1)

    You don't need to add another zero terminator since the bytemove copies the one from the source string.
  • Shane MShane M Posts: 58
    edited 2009-06-27 18:35
    Hi. Thanks for the fast response. It's awesome when people with similar interests help each other!

    The copystring change is what ultimately fixed it. Thank you!
Sign In or Register to comment.