Shop OBEX P1 Docs P2 Docs Learn Events
problem using serial object — Parallax Forums

problem using serial object

Zap-oZap-o Posts: 452
edited 2009-04-12 00:41 in Propeller 1
I am having some difficulty with the following code. I wish to send a long of data that is a variable derived from 4 bytes
[b]
Con
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000
   

  Rx   = 31                            
  Tx   = 30                                 
  baud   = 19200 

OBJ                                              
   Ser           : "FullDuplexSerial"

Var
   Long Header
   Byte Small [noparse][[/noparse] 10 ]
   
Pub Start

  ser.Start(Rx,Tx,0,baud)  
  small [noparse][[/noparse] 0 ] := "+"
  small [noparse][[/noparse] 1 ] := "2"
  small [noparse][[/noparse] 2 ] := "3"
  small [noparse][[/noparse] 3 ] := "2"
  
  Header := small [noparse][[/noparse] 0 ] <- 24 | small [noparse][[/noparse] 1 ] <- 16 | small [noparse][[/noparse] 2 ] <- 8 | small [noparse][[/noparse] 3 ]
  {pack bytes in a long}
       
  repeat 
    ser.str(@Header)
    waitcnt(clkfreq / 10 + cnt)  
[/b]




The result looks like --> 232++232 . Do I need to terminate with a "0" or something and if so how?

Comments

  • Chuck RiceChuck Rice Posts: 210
    edited 2009-04-12 00:30
    You are making it too complicated. Just send the small array.

    ser.Start(Rx,Tx,0,baud)  
      small [noparse][[/noparse] 0 ] := "+"
      small [noparse][[/noparse] 1 ] := "2"
      small [noparse][[/noparse] 2 ] := "3"
      small [noparse][[/noparse] 3 ] := "2"
      small [noparse][[/noparse] 4 ] := 0         ' <-- Add this line to terminate the string
      
      Header := small [noparse][[/noparse] 0 ] <- 24 | small [noparse][[/noparse] 1 ] <- 16 | small [noparse][[/noparse] 2 ] <- 8 | small [noparse][[/noparse] 3 ]   ' <--- delete this line. Not needed. 
      {pack bytes in a long}
           
      repeat                                                                                                       ' <--- delete this repeat. Not needed.
        ser.str(@small)                                                                                        ' <--- Change this line to use the small array directly. 
        waitcnt(clkfreq / 10 + cnt)  
    
    



    If you want to do it more simply, just use

    ser.Start(Rx,Tx,0,baud) 
    ser.str(string("+2320"))
    waitcnt(clkfreq / 10 + cnt)
    



    The string(...) function creates the string and null terminates it.
  • Zap-oZap-o Posts: 452
    edited 2009-04-12 00:41
    Chuck Rice, boy you nailed it. Seems I was making it much more heavy than it needed to be. Thank you.
Sign In or Register to comment.