Shop OBEX P1 Docs P2 Docs Learn Events
Full Duplex questions — Parallax Forums

Full Duplex questions

Zap-oZap-o Posts: 452
edited 2009-09-03 14:00 in Propeller 1
Ok I want to learn so please note I am aware of other objects that can do as I am about to ask.

I want to know how to compare a bye string with the rx_buffer[noparse][[/noparse] 16 ] in FullDuplexSerial. is this possible?
So far I am playing with the following


Var 
   Byte Rx[noparse][[/noparse] 16 ]

Dat
  Str1   Byte "Hello",0 


Pub Main | idx, CheckByte

Repeat

   CheckByte := Serial.rxcheck
   IF CheckByte+1
       Rx[noparse][[/noparse] idx ] := CheckByte
           idx++                                                    
   ELSE 
       Idx := 0




More code would then

  IF StringComp(@rx,str1)
     Serial.str(string("matched"))
  else 
     Serial.str(string("No match"))




Now it seems redundant to have the Rx array in this main cog when there is a buffer already in the Fullduplexserial named rx_buffer[noparse][[/noparse] 16 ]. Is this possible to access?

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-09-03 01:10
    Sure. Any cog can access any hub location at any time (within the access window, but with Spin you can ignore that). So, if you pass the start address of the array and the size (for orthanganality's sake) then you can treat as an array in your own program. You'd have to modify FDS to return the address and length, but that's only four lines of code so it's not a big deal. Then you use byte[noparse][[/noparse]address] to get to where you want to go.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-03 03:48
    Remember that both the receive and transmit buffers are circular. The index to the buffer wraps around as the assembly portion of the driver puts data into the buffer. Trying to compare the received input to some string won't usually work because of this wraparound.
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-09-03 04:38
    Hello Zap-o,

    there is are objects in the obex that can do a part of the work:

    Extended Full Duplex Serial which provides a method that can receive strings

    Strings that provide methods for stringmanipulation, finding a substring etc.

    I would NEVER use the rx_buffer directly. As the content of the rx-buffer can change in the backround at any unpredictable time.

    FullDuplexSerial starts another cog to be ready to receive data at any time and catch it. The new bytes are filled in into
    the circular buffer immediatly.

    best regards

    Stefan
  • william chanwilliam chan Posts: 1,326
    edited 2009-09-03 12:38
    Hi Stefan,

    How about a new FullDuplexSerial that allows the user to "easily" change the receive and transmit buffer sizes?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • Zap-oZap-o Posts: 452
    edited 2009-09-03 13:07
    Thanks every one.

    I guess its me but the notion that I would have to use 2 cogs to communicate to the PC is wasteful. I will stick to the FullDulexSerial object. On a related note can the buffer be increased?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-03 14:00
    The buffer size can be increased to any power of 2. There are several places in the code where a constant has to be changed.

    You might look at several of the alternative serial drivers like obex.parallax.com/objects/397/ and obex.parallax.com/objects/340/ and obex.parallax.com/objects/398/.
Sign In or Register to comment.