Shop OBEX P1 Docs P2 Docs Learn Events
Reading Serial — Parallax Forums

Reading Serial

Chuck MintonChuck Minton Posts: 45
edited 2010-08-06 00:20 in Propeller 1
I am trying to read a serial (rx) string. The string will be an occasional 7 char ASCII being sent over satellite that I will be receiving over pp13 .

Can't get past first base... Using FullDuplesSerial sending you give a value and that works, but receiving I can not compile if a variable follows FullDuplexSerial.rx (variable). So... I don't fully understand the function of a return variable as I read under PUB in the prop manual page 182: As FSD.rx:rxbyte is the actual format.
My question is how do we use "PUB Name : RValue " concerning :RValue. And, How do we access this information when it has been called by an object (the Return Value).

Appreciating any help,
Chuck

Comments

  • Mike B.Mike B. Posts: 31
    edited 2010-07-29 00:16
    Hi.· First off I am a complete newbie to the Prop so my response may or may not be valuable!· lol.· I also tried in vain to get FullDuplexSerial to work on my simple Scott Edwards 4 X 20 serial LCD without luck.· I come from the BS2P40 world so decided to give "BS2_Functions.spin a try and it works great and is really easy to use.· Give that a try and you'll be up and running in minutes.

    · Mike B.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-07-29 00:27
    Can you be more descriptive about what you're receiving? If it's the ASCII representation of a numeric value it will need conversion.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-07-29 00:29
    Chuck,

    I made the same mistake when I first used FullDuplexSerial.

    wrong way:· FullDuplexSerial.rx(variable)

    correct way:· variable := FullDuplexSerial.rx

    Duane
  • Chuck MintonChuck Minton Posts: 45
    edited 2010-07-29 02:47
    http://forums.parallax.com/forums/emoticons/jumpin.gif
    Thanks Duane! you got it.

    On the phone with my son and he just led me through the same thing....It works... I get streaming ASCII through my prop and onto parallax serial terminal!


    Thanks so much , I just didn't get that an objects variable could be on the right hand side of the :=.

    So Fun!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-07-29 16:48
    Chuck,
    Glad I could help.· I find the checkrx method very useful.· Since FullDuplexSerial is running in its own cog, you don't need to sit and wait for data in your main loop, you can just check it every now and then (as long as its buffer doesn't fill up).
    I use code like this a lot:
      repeat
        tempCharacter := debug.checkrx  ' checkrx returns a -1 is nothing has been received
        if tempCharacter > -1
          ' do stuff with tempCharacter
        ' do other stuff between checks
    
    

    There is also and object called SimpleSerial·that doen't run in its own cog and so doesn't have a checkrx method.· I often use SimpleSerial in a dedicated cog·to listen to a serial port and set a flag indicating new data and have the main program loop check to see if the new data flag is set.· I'm still tring to figure out which of these two methods (no pun intended) work best.

    Duane
  • Chuck MintonChuck Minton Posts: 45
    edited 2010-07-30 15:07
    Duane,
    Tnx. I am running this serial manipulation in a separate cog so this was not a problem, however, I can see it very valuable in some occasion. Plus it sounds like it buffers the string!?

    I ran into a stumbling point yesterday: Read in a wanted set of ASCII> Each Character in a separate variable. Then wanted to compress into a single Word or Long....But could not figure that one out. Then I remembered seeing somewhere....(i.e. 3 letter word) : Take the first letters value multiply by 1M, then multiply the second letters value by 1K, and don't multiply the last.... then add them all together . After that I could do a single compare against predetermined value. I suppose if I use hex value I would only need to multiply by 100 each step.
    My question .. is there a better way to stack ascii into a block so I could work with comparing "word" values??? I have gotten notice that I could not have more than 8 stacked "if" statements.
  • Chuck MintonChuck Minton Posts: 45
    edited 2010-07-30 15:22
    This is the same problem in "Newb question: Append to a variable"... me and John are working together on .
  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-07-30 18:43
    Chuck,
    I posted some code in this thread that sets longs equal to the ASCII string.· I use two global variables leftDecimalMass and rightDecimalMass.· The method watches for a decimal to know when to start increasing the rightDecimalMass and stop increasing the leftDecimalMass.· Normally I'd use the pseudoreal number trick of having my decimal number multiplied by some power of 10 (in this case I'd use 10000 since I have four possible digits after the decimal), but I needed to keep track of the two sides of the decimal so they would display correctlly on my setup.

    PUB StrToPseudonumber(rawBufferPointer, bufferPointer) | character, afterDecimalFlag, localNumber, size, endFlag
      leftDecimalMass := 0
      rightDecimalMass := 0
      positiveMassFlag := 1
      afterDecimalFlag := 0
      endFlag := 0
      
      size := strsize(rawBufferPointer)
      repeat size
        character := byte[noparse][[/noparse]rawBufferPointer++]
        localNumber := 999          ' if localNumber is still 999 I know the character read wasn't a numeral.
        case character
          43: positiveMassFlag := 1 ' +
          45: positiveMassFlag := 0 ' -
          46: afterDecimalFlag := 1 ' .
            byte[noparse][[/noparse]bufferPointer++] := character
          48..57:  localNumber := character - 48   ' 48 is the ASCII value for zero (see character chart in help menu)
            byte[noparse][[/noparse]bufferPointer++] := character
          71, 103: endFlag := 1         ' g
        if localNumber < 10 and endFlag == 0       ' localNumber will be 999 still if no numeral was found this loop
          if afterDecimalFlag
            rightDecimalMass := (rightDecimalMass * 10) + localNumber    ' I want the weight in both a string and in decimal form in a variable.
          else
            leftSize++
            leftDecimalMass := (leftDecimalMass * 10) + localNumber   
      byte[noparse][[/noparse]bufferPointer] := 0                    ' Strings are supposed to end in zero, so I add on to make sure it does.
      
    

    I decide to copy the code here.· I think I messed up the html tags in this post.

    Make sure you look at FullDuplexSerial's dec method.· I use something like that method a lot when I need to transform a variable in to an ASCII string.

    Duane
  • Chuck MintonChuck Minton Posts: 45
    edited 2010-08-05 22:52
    Good news got through my program I was wanting to create. All is well.
    So, then I wanted to do some more experimenting with Parallax Serial Terminal (both object and program).
    I set up this simple code... and I get what starts out to be normal characters reflected to the screen but then turn in to gibberish.
    The strange thing is I have code I wrote 2 days ago and the PST works fine. Very confused!!! input a "g" and reflect a( "c"+a squiggly line under it )followed by a("Y"+ two dots over it). Tried different baud settings for naught.
    Perplexed!!!!!

    VAR
    word SERDAT

    OBJ
    BUG:"PARALLAX SERIAL TERMINAL"

    PUB TESTING
    BUG.STARTRXTX (31,30,0,4800)
    REPEAT
    serdat := bug.charin 'waiting to grab byte of serdat from keyboard
    bug.char(serdat) 'send var serdat to Parallax Serial Terminal program to view on monitor.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-08-05 23:02
    Chuck,

    I've had the same thing happen to me many times.

    One of the first things I try is closing PST and reopening it.· I also try reloading the program (F11) and then click "Enable" in PST.· If I'm still getting gibberish (and I've double check my baud settings) I reboot my PC.· I don't what can go wrong with a PC to mess it up but this often works (I had to do it today and it work fine afterwards).· This can be really frustrating sometimes.

    Duane
  • Chuck MintonChuck Minton Posts: 45
    edited 2010-08-06 00:20
    ....I claim cortex deficiency!....

    did not get the Pll and cyrstal constants in ! Daaah~

    eventually I hope to learn
Sign In or Register to comment.