Shop OBEX P1 Docs P2 Docs Learn Events
Serial comms with prop — Parallax Forums

Serial comms with prop

realolmanrealolman Posts: 65
edited 2009-01-31 18:54 in Propeller 1
I have two cogs running. One is a counter that increments the variable, MyVariable

The other handles serial comms to and from the propeller. I am using FD_Serial and Extended_FD_Serial.

In the serial comms·cog there is opportunity for input and output·in the execution of a repeat loop.

· The variable, InputVariable, accepts input and lights LED's so I can tell the input has been received.

In the line: InputVariable:=ser.rxDec· ...if I use ser.rxDec or ser.rxdec the execution stops and waits at that line until input is received.

If I use ser.rxcheck it seems to return it as something that· InputVariable can't use, as the LED's all stay on... something seems to be wrong... maybe it's the -1 return.


I am not at all sure I am using ser.RxDec or ser.rxcheck properly.· Is there a receive buffer associated with this?·

If so,how is it used?· It seems rxCheck wouldn't be of much use if the input had to arrive exactly at that moment.

Do I have to notify the sender that I am waiting to recieve, and then wait for it?

Or what?.... thank you

repeat 



If MyVariable <> OldCount        'if couter has incremented 

 ser.dec(MyVariable)             'serial transmit count 

 OldCount := MyVariable          'if count has been transmited, make OldCount 
                                 'variable equal to MyVariable so same count 
                                 'is not transmitteed over and over 
 

'this section accepts input 
 

InputVariable :=ser.rxDec        serial input 
 

If InputVariable >0              'if serially input number is above 0 
                                 'light LED's 

  outa[noparse][[/noparse]17..21] :=InputVariable  

Post Edited (realolman) : 1/31/2009 4:09:17 PM GMT

Comments

  • KyeKye Posts: 2,200
    edited 2009-01-31 16:16
    If you want to, you can use the 256 Byte FIFO buffered Full Duplex Serial driver I made, looking at the demo you can see how to use it to do all you want to accomplish. It does not have built in character conversion, however, so you should supply that yourself.

    http://obex.parallax.com/objects/397/

    The driver allows you to send chunks of data at will and allows you to check how many bytes are in the receiving buffer and what the last received byte is without removing it from the buffer. Such a feature is useful for receiving a chunk of data followed by a return or such to indicate when the data stream is finished.

    The demo with the driver illustrates this.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-01-31 18:06
    Hello Realolman,

    yes FullDuplexSerial and as ExtendedFD_Serial uses FullDuplexSerial as its base

    both use the sendbuffer and receivebuffer of the FullDuplexSerial-object (shortname FDS)

    You can use rxcheck as it's name says: check for bytes received

    As long as the call of ser.rxcheck results in -1 you know no bytes in the receivebuffer

    if the value is between 0 and 255 this value is the first byte inside the receivebuffer
    example you send ASCII-coded decimalnumber "7654" to the propeller

    if you use ser.rxcheck the resukt of rxcheck will be -1 as long as nothing is send
    if the "7654" arrived in the receivebuffer of FDS ser.rxcheck will give the result
    "7" and a ser.rxdec will receive a "654"

    now an easy way to do a ser.rxdec after the ser.rxcheck would be if you send
    a starting character before sending the ASCII-codes decimal value
    by this way you just use the starting-character for indicating decimal value received

    anyway this is a proposal into the fog.

    I don't know what you exactly try do do.
    If you describe the COMPLETE functionality that you are trying to achieve the help can be much better


    Anyway by debugging you can detect what is going on
    and to be sure that your debugging info is right start your debuggingtest with sending hardcoded values
    where you are 100% sure that everything works properly


    some comments on your code snippet

    the commands below the repeat are NOT indented this means you start a repeat-loop that does infinitly nothing
    I don't think that this is the thing you want to do

    maybe it's a copy&paste-error

    So please describe the whole thing that you want to do and the solution will come RUNNING to you
    otherwise the solution "will be hidden in the fog" caused by the lack of information

    best regards

    Stefan
  • realolmanrealolman Posts: 65
    edited 2009-01-31 18:54
    It's a copy and paste thing. the code works in the propeller except:

    If I use· InputVariable:=ser.rxDec· or· InputVariable:=ser.rxdec,

    · the execution stops and waits at that line until input is received.· Then it executes the rest of the loop until it reaches that line again... then it stops and waits...

    If I use ser.rxcheck ,·execution continues, but·I believe it is returning -1 , which the outa[noparse][[/noparse]17..21] :=InputVariable· displays as all the LED's being on.

    I like your idea :
    now an easy way to do a ser.rxdec after the ser.rxcheck would be if you send
    a starting character before sending the ASCII-codes decimal value
    by this way you just use the starting-character for indicating decimal value received.


    I am going to try to do something with that
    I did not understand how the ser.rxcheck worked. Now that you have explained that, I think I can make some progress... thank you.


    I simply want to use a cog to send the contents of a global variable that is modified by a different cog, when the contents of that variable change.
    And modify another global·variable according to received transmissions.· The LED's are just temporary to make sure It's receiving what I sent.

    I am monitoring the transmissions from the propeller with the Parallax Serial Terminal.
    repeat 
    
    
    
     If MyVariable <> OldCount      'if counter has incremented 
      ser.dec(MyVariable)           'serial transmit count 
      OldCount :=MyVariable         'if count has already been transmited, make OldCount 
                                    'variable equal to MyVariable so same count 
                                    'is not transmitteed over and over 
    
     InputVariable :=ser.rxcheck    'checks to see if serial input 
     If InputVariable >0            'if serially input number is above 0 
                                  
    
     outa[noparse][[/noparse]17..21] :=InputVariable   'light LED's 
    




    ·
Sign In or Register to comment.