Shop OBEX P1 Docs P2 Docs Learn Events
Strings, serials, bytes and other animals. — Parallax Forums

Strings, serials, bytes and other animals.

HughHugh Posts: 362
edited 2013-06-20 08:39 in Propeller 1
Any help with the following would be gratefully received....

I am using v1.2 of the Simple_serial object to send data from one propeller to another. The data is being received at the other end, but when I go to write it to an SD card or LCD the received and re-assembled string of bytes is either 0 or a lot of gibberish.

This is the code at the 'receive' end. The goal is to grab the numbers out of a comma-delimited stream (e.g., ",1212,1213,1214,1215,1216 ..) passed by the other prop so it has a zero terminated string with which I can do things (send to an SD card or to an LCD).
PUB getDataCount | rxByteR, rxcount

' (Scratchpad is a 20 byte array, i.e., declared as "byte Scratchpad[20]" in VAR)





[B]SOLVED[/B]. PICNIC (Problem In Chair, Not In Computer)



dira[4]~~                                               ' Set pin4 as output


debug.init(16, 18, 100)                                 ' Start "simple_serial" object @ 100 baud
repeat                                                  ' Repeat infinitely
  rxByteR := 0                                          '     Set this to zero
  bytefill(@scratchpad, 0, 20)                          '     Set all of the bytes of ~scratchpad~ to zero. This will mean it should get treated as a zero-terminated string
  
  repeat until rxByteR == 44                            '     Keep receiving data until a comma (ASCII 44) is received
     rxByteR := debug.rx                                '          Receive data....
     
  rxByteR := 0                                          '     Having found the first comma. set this two values back to zero
  rxCount := 0                                          '     Set this counter to zero - this is going to track
  repeat while rxByteR <> 44                            '     Keep going until the next comma is found
     rxByteR := debug.rx                                '          Receive the next byte
     byteMove(@scratchpad + rxCount++, @rxByteR , 1)    '          Put the received byte into ~scratchpad~ at the position tracked by the counter; increment the counter
    
  
  dcFlag:=1                                             '     Set this flag to 1 so that another PUB knows it is ready
   !outa[4]                                             '     Toggle pin 4 so that the LED indicates traffic
  rxByteR := 0                                          '     Set this back to zero

I've tried using 'Scratchpad' directly and by pointer (writing it as a string to an LCD and via SimpleDebug to serial Terminal), to no avail. Another PUB in a different cog does the writing.

serial.str(@scratchpad) doesn't work - all I get is the final comma received, preceded by a single character, typically

Comments

  • Mike GMike G Posts: 2,702
    edited 2013-06-19 12:15
    byteMove(@scratchpad + rxCount++, @rxByteR , 1) 
    

    Should be - rxByteR not @rxByteR
    byteMove(@scratchpad + rxCount++, rxByteR , 1) 
    

    A little easier to read... and I believe I did not break any logic...
    rxCount = @scratchpad
    ...
    byteMove(rxCount++, rxByteR , 1) 
    

    Or just
    rxCount = @scratchpad
    ...
    byte[rxCount++] := rxByteR 
    
  • AribaAriba Posts: 2,690
    edited 2013-06-19 16:44
    There are many ways to do that, here is my version:
    PUB getDataCount : rxcount | rxByteR
    
    dira[4] := 1
    debug.init(16, 18, 100)                  'Start "simple_serial" object
    
    repeat
      repeat until debug.rx == ","           'wait for comma
      rxcount := 0
      repeat
        rxByteR := debug.rx
        scratchpad[rxcount++] := rxByteR     'fill string until next comma
      until rxByteR == ","
      scratchpad[--rxcount] := 0             'ending zero (replaces comma)
    
      dcFlag := 1                            'Set flag
      !outa[4]                               'toggle LED
    

    Andy
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-06-19 17:00
    Mike G wrote: »
    byteMove(@scratchpad + rxCount++, @rxByteR , 1) 
    

    Should be - rxByteR not @rxByteR
    byteMove(@scratchpad + rxCount++, rxByteR , 1) 
    

    A little easier to read... and I believe I did not break any logic...
    rxCount = @scratchpad
    ...
    byteMove(rxCount++, rxByteR , 1) 
    

    Or just
    rxCount = @scratchpad
    ...
    byte[rxCount++] := rxByteR 
    

    The bytemove method is a lot of overkill for a simple indexed store but the move operation requires a source address, not a source byte so the original version was correct. Unless of course rxByteR is already an address (is it?)

    Your last method using the simple indexed store is of course the best way of storing a byte in a buffer.
  • HughHugh Posts: 362
    edited 2013-06-20 08:39
    Thanks. Your versions are much better. Things started to 'creep' as I sought a solution - schoolboy error! Oops! :blush:
Sign In or Register to comment.