Shop OBEX P1 Docs P2 Docs Learn Events
Receiving RS232 and not having to wait for input — Parallax Forums

Receiving RS232 and not having to wait for input

OctahedronOctahedron Posts: 18
edited 2011-02-09 14:29 in Propeller 1
I was wondering if there is a generally accepted way to receive RS232 input but not have to wait around for it to show up? I have a device that will transmit data when it feels like it and I am doing some other things at the same time and what to check if there is something to look at in my own time and not wait for the device to send me something. I have used a new cog to run some spin code that does just that (I think) but I was wondering if there was an easy way/object/other for this or a common method?

Here is what I am doing and please hold the giggles.
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

   ' debug - USE onboard pins
  pcDebugRX       = 31           
  pcDebugTX       = 30
  pcMode          = 0

  CmdDebugRx      = 25
  CmdDebugTx      = 24

  ' serial baud rates  
  pcDebugBaud     = 115200
  CmdDebugBaud     = 9600
  
  
 
Var
         Byte Command
         long Cog[2]
         long stack[132]

        
OBJ
  Debug    : "FullDuplexSerialPlus"    '....added this to do sum debugging
  CmdDebug  : "FullDuplexSerialPlus"
  ReturnCom : "GadgetRS232Com2"
PUB Start :  okay  

  Debug.Start(pcDebugRX,pcDebugTX,pcMode,pcDebugBaud)  ' start the debugger
  cmdDebug.Start(CmdDebugRX,CmdDebugTX,pcMode,cmdDebugBaud)  ' start the debugger
  'if cog > 0
    'cogstop(cog)
  'cog := cognew(ReturnCom.start(pcDebugRX,pcDebugTX,pcMode,pcDebugBaud,CmdDebugRX,CmdDebugTX), @stack[0])
  waitcnt(ClkFreq * 5 + cnt)  'wait a bit to give time to activate the Serial terminal
  Debug.tx(13)
  cog[0] := cognew(GetCmdInput, @stack[0]) + 1
  waitcnt(clkfreq/2 + cnt)
  cog[1] := cognew(GetPCinput, @stack[66])  + 1
' cogstop(cog[1])
' cog[1] := cognew(GetPCinput, @stack[66])  + 1

  repeat
PUB GetCmdInput  :count


    'cmdDebug.str(string("Starting RGB control Program!", 13))
    Debug.str(string("Starting RS232 OO output to PC!", 13))
    CmdDebug.rxFlush
    Count := 0 
    repeat
        Command := CmdDebug.Rx
        
        if command == 32
          Debug.tx(13)
        '  count := 0
        'count += 1
        'Debug.hex(Command, 2)
        Debug.tx(Command)
        Command := 0
PUB SetUpOOSpec


    'cmdDebug.str(string("Starting RGB control Program!", 13))
    Debug.str(string("Config OO spec!", 13))
    Debug.rxFlush 
    repeat
        Command := Debug.Rx
        CmdDebug.tx(Command)
        Command := 0
PUB GetPCInput : Char


    'cmdDebug.str(string("Starting RGB control Program!", 13))
    Debug.str(string("Starting RS232 Com to OO spec!", 13))
    Debug.rxFlush 
    repeat
        Char := Debug.Rx
        CmdDebug.tx(Char)   
        Char := 0

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-02-08 20:36
    The FullDuplexSerial objects buffer data as it comes in. You don't have to be sitting around waiting for it. Just check the buffer when it's convenient.

    -Phil
  • OctahedronOctahedron Posts: 18
    edited 2011-02-09 14:29
    Well doesn't that work like a charm. It didn't occur to me that I can view the code of an object such as FullDuplexSerial! I will have to get used to doing that. I imagine it is the .rxcheck that will do what I need. Thanks for your help.
Sign In or Register to comment.