Shop OBEX P1 Docs P2 Docs Learn Events
SerialMirror - A FullDuplexSerial enhancement — Parallax Forums

SerialMirror - A FullDuplexSerial enhancement

mirrormirror Posts: 322
edited 2007-08-20 03:44 in Propeller 1
I've given this object a new name, as it breaks·existing functionality in
FullDuplexSerial. Having said that, it's exactly the kind of break I was
willing to tolerate for the extra feature. Here's the top of the file:

SerialMirror.spin : V07.05.10
·············
Derived from: Full-Duplex Serial Driver v1.1·
············· (C) 2006 Parallax, Inc.
It has been extended in the following ways:
1) Make allowance for different buffer sizes. I've set the default buffer to
·· 64 bytes as this is large enough to contain a complete incoming/outgoing
·· message for my protocol.
2) Check for a stop bit!! If a stop bit is not present then the received byte
·· is dropped. No flags of any sort are set. It's up to a higher level of the
·· protocol to check the message for integrity.
3) Variables have been moved to DAT space.
·· The significance of this is not obvious at first, but what it means is that
·· every instance of this object shares the same variable space. Why do this?
·· If you have multiple nested objects, then serial comms can be added to all
·· of them. ONLY the top object must call the start method. The nested objects
·· then have full comms access. A simple example is:
··
┌────────────────────────────────────────────────────────────────────┐
│  APP_SerialMirror.spin                                             │
├────────────────────────────────────────────────────────────────────┤           
│CON                                                                 │
│  _clkmode      = xtal1 + pll16x                                    │
│  _xinfreq      = 5_000_000                                         │
│                                                                    │
│  BaudRate      = 38400         'Baud                               │
│  RxPin         = 31            'For RS232                          │
│  TxPin         = 30            'For RS232                          │
│  CommsMode     = %0000         'See SerialMirror.spin for meaning  │
│                                                                    │
│OBJ                                                                 │
│  Debug : "SerialMirror"                                            │
│  Test : "TestObject"                                               │
│                                                                    │
│PUB Start                                                           │
│  Debug.start(RxPin, TxPin, CommsMode, BaudRate)                    │
│  Test.SayHello                                                     │
└────────────────────────────────────────────────────────────────────┘                                                                   
┌────────────────────────────────────────────────────────────────────┐
│  TestObject.spin                                                   │
├────────────────────────────────────────────────────────────────────┤           
│OBJ                                                                 │
│  Debug : "SerialMirror"                                            │
│                                                                    │
│PUB SayHello                                                        │
│  Debug.str(string("Hello",13,10))                                  │
└────────────────────────────────────────────────────────────────────┘     

4) This object is NOT suitable for driving multiple serial ports.
·· If you want multiple serial ports each with single object access, then
·· use FullDuplexSerial.
·· If you want serial comms through the same port from multiple objects,
·· then use THIS object.
·· If you want multiple serial ports each with multi-object usage, then copy
·· and rename this files for the number of unique serial ports.
5) Added GetNumber which will receive a number (positive or negative) from
·· the serial port in either decimal, binary or hexadecimal notation.
6) Added extra comments to the assembler section - for the newbies. I've been
·· doing this propeller stuff for a month now, so I guess that makes me an
·· old hand.
7) Added CrLf which does just that - purely a conveniance function for me.

Now in the object exchange at: http://obex.parallax.com/objects/189/



Post Edited (mirror) : 10/25/2007 6:43:32 AM GMT

Comments

  • Ken PetersonKen Peterson Posts: 806
    edited 2007-08-19 00:40
    You might want to incorporate locks in the sending functions if you intend to have more than one cog using it.

    Ken

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    The more I know, the more I know I don't know.· Is this what they call Wisdom?
  • mirrormirror Posts: 322
    edited 2007-08-20 00:07
    SerialMirror has been posted to the object exchange.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • MightorMightor Posts: 338
    edited 2007-08-20 03:44
    mirror said...
    SerialMirror has been posted to the object exchange.
    And there was much rejoicing!

    Thanks for that!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    | To know recursion, you must first know recursion.
Sign In or Register to comment.