Shop OBEX P1 Docs P2 Docs Learn Events
Extended Full Duplex Serial question — Parallax Forums

Extended Full Duplex Serial question

Zap-oZap-o Posts: 452
edited 2010-07-01 07:14 in Propeller 1
In the Extended Full Duplex Serial object there is a function RxStr. The last line in that function has me a little confused.

Do I need a long array called stringptr and if so how do I compare it towards another string?


The code is below.

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 15 characters before passing back.
  Serial.Rxstr(@MyStr)        ' accept
  serial.str(@MyStr)          ' transmit
 }} 
    ptr:=0
    Bytefill(@dataIn,0,15)                               
    dataIn[noparse][[/noparse]ptr] :=  Rx        
    ptr++                                                  
    repeat while ((DataIn[noparse][[/noparse] ptr-1 ] <> 13) and (DataIn[noparse][[/noparse]ptr-1] <> Delimiter)) and (ptr < 15)       
       dataIn[noparse][[/noparse] ptr ] :=  RX    
       ptr++
    dataIn[noparse][[/noparse] ptr-1 ]:=0                                         
    byteMove(stringptr,@datain,16)                                      




Thanks

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2010-06-30 19:39
    You have to define a byte array with a size of 16. The function will read the string into it's own buffer first. If it received 15 characters or a carriage return or a character that equals the delimiter (must be set with a different function), it replaces the last character ( the carriage return or the delimiter or the 16th byte) with the string end ( $00 ). After that - to make it easy - the whole internal buffer is copied to your buffer.

    As you have a valid string in your buffer in any case you can simply use the SPIN string compare function.
  • Zap-oZap-o Posts: 452
    edited 2010-07-01 01:32
    MagIO2

    I am clear on defining the byte array for the function to read from. The lack of clarity that I am concerned with is the last line of code - the object has no instructions reguarding the data type for stringptr; Is it a long array or a long

    A: In the line of code below; should stringptr be a long then the 15 bytes of data would over fill the long given that 4 bytes make a long not 15.

    B: In the line of code below; should stringptr be a long array then problems would be using stringcompar. Not sure it can be done with arrays.



    byteMove(stringptr,@datain,16)
    




    Sorry if i am not clear - no sleep from raising a new child is testing all the fiber I am made of.

    Post Edited (Zap-o) : 7/1/2010 11:31:57 AM GMT
  • MagIO2MagIO2 Posts: 2,243
    edited 2010-07-01 07:14
    Somewhere in your code you have a byte array

    VAR
    byte theStringBuffer[noparse][[/noparse]16]

    and you call the function like this:

    RxStr( @theStringBuffer )

    When the function is done you will find the string in your array.
    What this function needs is the address of the byte array, that's why the parameter is named ...ptr. What bytemove expects are 2 pointers and the number of bytes to copy. If you directly want to copy from one buffer to another you usually say:

    bytemove( @buf1, @buf2, 100 )

    But in the RxStr the variable stringptr already contains the address. It's like saying:
    stringptr := @buf1
    bytemove( stringptr, @buf2, 100 )

    That's actually what's happening if you call RxStr correctly:
    RxStr( @theStringBuffer ) in fact stores the pointer to the buffer in variable stringptr.

    bytemove(stringptr, @datain, 16) does not overwrite the variable stringptr. It overwrites the memory location that stringptr points to, which is your theStringBuffer array.
Sign In or Register to comment.