Shop OBEX P1 Docs P2 Docs Learn Events
Getting a string from a serial line — Parallax Forums

Getting a string from a serial line

bazibazi Posts: 29
edited 2010-06-18 01:45 in Propeller 1
I'm trying to modify propcmd to receive a file from my computer and write it to sd-card.

Serial communication works, but i can't figure out how to get a string usable with str-function from FullDuplexSerial and fsrw.popen()

I've tried this, but it does not work:
VAR
  filename[noparse][[/noparse]9]
  ext [noparse][[/noparse] 4]
...
PUB ....
...
  count := 0 ' get 8 bytes filename from host
  repeat while count < 8
    header_filename[noparse][[/noparse]count] := text.rx
    text.tx(header_filename[noparse][[/noparse]count])
    count++
  header_filename[noparse][[/noparse]8] := 0

  count := 0 ' get 3 bytes extension from host
  repeat while count < 3
    header_ext[noparse][[/noparse]count] := text.rx
    text.tx(header_ext[noparse][[/noparse]count])
    count++
  header_ext := 0

  text.str(string("filename: "))
  text.str(filename)
  text.tx(".")
  text.str(ext)



I hope you can help me [noparse]:)[/noparse]

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
some say the devil is dead... ...tish army!

Comments

  • pullmollpullmoll Posts: 817
    edited 2010-06-17 14:52
    bazi said...
    I hope you can help me [noparse]:)[/noparse]
    Sure. Try text.str(@filename) and text.str(@ext)
    Or even better yet use text.str(@header_filename), because that is where you collect the string!?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Pullmoll's Propeller Projects

    Post Edited (pullmoll) : 6/17/2010 3:02:52 PM GMT
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-06-17 15:19
    like its name says a string is a string of bytes where each byte represents a character
    variables in spin can contain a maximum of 4 bytes = 32 bit = 1 long

    strings are stored as a bytesequence. Like you do with

      header_filename[noparse][[/noparse]count] := text.rx
    
    



    How should a 32bit-variable contain 8 characters? Rhetoric question: it's not possible.
    So characters are stored as a sequence of bytes and you need to know WHERE this sequence of bytes is located in RAM

    That's what the str-method needs. The ADRESS WHERE the bytesequence ist stored.

    So you have to code @NameOfVariable like pullmoll sugested.

    the @-operator gives back the desired pointer to the RAM-adress of the variable

    "MyVariable" evaluates to the value of MyVariable

    "@MyVariable" evaluates to the RAM-adress where the value of MyVariable is STORED in RAM

    best regards

    Stefan
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-06-18 01:45
    That was a simple yet well worded explanation.

    TY

    Jeff T.
Sign In or Register to comment.