Shop OBEX P1 Docs P2 Docs Learn Events
Serial Comms - The first tenative steps - can someone point the noob in the cor — Parallax Forums

Serial Comms - The first tenative steps - can someone point the noob in the cor

pacmanpacman Posts: 327
edited 2009-11-12 22:39 in Propeller 1
I have a rs232 serial device I want to communicate with.

Unfortunately this device is bit of a special beast, and I'm struggling with actually establishing reliable communications.

To establish communications the prop needs to send "ZA1". OK so far.

The other device can take up to three seconds to respond with a "^", but the manufacturer suggests that if i haven't got a response back in 1 second I should send "ZA1" again. This means that the other unit will occasionally wake-up and send one "^" for every ZA1 I sent.

So, If I'm using the FullDuplexSerial object (is that the best ? option), then I rxcheck and if no char then send again, if "rxcheck" is any value other then 0 then should I use "rx" ? What happens if the remote device woke up, decided to respond to a couple of ZA1's, sent several ^'s and I'm not calling 'rx' fast enough?

Then just to add insult to injury, once the unit has done it's first response to ZA1, I need to repeat the whole procedure with ZE1 (with the same sort of timing considerations}.

Does someone ALREADY have some code that is 'sort of' what I need to do and could share with me? It would be real good if it came with some comments so as I could dissect and LEARN.

Thanks heaps in advance.

Paul

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
=================
The future is in our hands.
Which way to the future?
=================

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2009-10-19 08:37
    Yes, I would use the FDX object. FDX has a tx & rx buffer - IIRC 16 bytes but can be expanded fairly easily but in powers of 2 (eg 32, 64, 128, 256, 512 max) - I have done this is required. So rx will get the next character out of the buffer. Just look at each of the FDX calls.

    Suggest you also echo the characters you tx and rx to the PC using a teminal program such as PropTerm for debugging purposes. Just use 115200 and you should have no problems in seeing what is happening.

    If you look at the TriBlade threa

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
    · Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-10-19 17:59
    Hello PacMan,

    see attached zip-archive with a demo.
    Play around with it. And come back with all the questions you have

    best regards

    Stefan
  • pacmanpacman Posts: 327
    edited 2009-10-20 09:04
    StefanL38 said...

    Play around with it. And come back with all the questions you have

    Stefan

    thanks for that, my basic code sort of looked similar (but without the DAT section - I likey).

    If I'm understanding the FDX+ object correctly {and there is every chance I'm not}, then doesn't your code only send one instance of ZA1. I was thinking I could reduce the time to 1000, and then have a loop counter (x strikes and give a "serious error" message).

    and should the line "Char := Debug.rxtime(3000)" _really_ be pointing to Debug? I would have thought it should be pointing to Serial, but there might be some other reason that I'm missing...

    And thanks for help so-far..

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    =================
    The future is in our hands.
    Which way to the future?
    =================
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-10-20 10:43
    Hello Pacman,

    think more positive about your abilities !

    Oops your right !! Of course Char := Debug.rxtime(3000) hast to be Char := Serial.rxtime(3000)

    I'm not sure what you mean with one instance. An instance in programming means there is one copy of a datastructure stored to memory doing whatever it does
    There is a repeat-loop that makes the whole thing repeat endlessly

    Of course you can have a loopcounter that does 3 or 5 trys and then sends a error-message that you designed to whatever it is

    You can reduce the timeout as I have said play around with the code to get familiar with it

    If you like attach a TXT-file of the output you get in PST.EXE to a posting that I can see what you get.

    best regards

    Stefan
  • pacmanpacman Posts: 327
    edited 2009-10-29 23:54
    @ "StefanL38"

    Thanks, I've successfully got my object sending ZA1 and waiting 1 second for a response.

    My initial test was sending to hyperterm and then me trying to type a ^ as a return.

    The net effect is that it appears that my USB/serial adaptor isn't transmitting (or my hyper-terminal settings are massively wrong) as no matter what I typed on the PC I got no response on the prop other than timeout.

    As a 'final' test I directly connected the prop output TX pin to the RX pin and - lo and behold- the data transmitted was what I was receiving... (who'd of thunk that smile.gif ).

    So now I've got to pick-up a new usb/serial converter to try and figure-out where I was going wrong (hyperterminal or cable)....


    And thanks again for your help so far...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    =================
    The future is in our hands.
    Which way to the future?
    =================
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-10-30 06:55
    If I remember correctly, Hyperterminal causes a reset, when you start it. Use the Propeller Serial Terminal (PST) instead. Teamwork with the Propeller Tool is better as well. If you switch to the Propeller Tool the PST closes the connection automatically and reconnecting is just a click on a button.
  • pacmanpacman Posts: 327
    edited 2009-10-31 00:17
    MagIO2 said...
    If I remember correctly, Hyperterminal causes a reset, when you start it. Use the Propeller Serial Terminal (PST) instead. Teamwork with the Propeller Tool is better as well. If you switch to the Propeller Tool the PST closes the connection automatically and reconnecting is just a click on a button.


    Hmm perhaps that was what I was doing wrong... (never mind, I needed a few new usb/232 adaptors anyway - I seem to be forever forgetting what the one I have is currently attached too).

    I was using the PST for the debug port, and hyperterm as the 'real device'. I wonder if you can run two versions of PST?

    What is this Teamwork of which you speak? - I've googled (and had a bit of sniff about in the archives, but I can't find it) - perhaps you can supply a link?

    Or perhaps you can offer suggestions as to a better (and ideally free) terminal program {windows} to use as the 'real device'.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    =================
    The future is in our hands.
    Which way to the future?
    =================
  • pacmanpacman Posts: 327
    edited 2009-11-10 07:42
    just an update..

    I got some new USB/serial adaptors today and they work - and my code works. Now that I have successfully got step 0.2 working, I can move on.

    So HUGE thanks to all who helped.

    Tip for young players... Use working hardware when testing your designs - it helps.....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    =================
    The future is in our hands.
    Which way to the future?
    =================
  • MacGeek117MacGeek117 Posts: 747
    edited 2009-11-12 22:39
    PacMan: this may be what you're looking for with the x-strikes method:
    PUB SomeRoutine | strikes
      repeat
        strikes++
     
        serial.str(string("ZAI"))
        char := serial.rxcheck
        
        if not char
          strikes++
        else
          return true
        
        if strikes == 3  'replace this with number of strikes before error
          return false
        
    

    The rest of the code would call this routine and check for the response (true being good and false being an error)
    Hope this helps!
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    BS2: $49


    SX48 Protoboard: $10

    Propeller Protoboard: Priceless

    www.apple.com

    www.parallax.com

    www.goldmine-elec.com

    www.expresspcb.com

    www.jameco.com
Sign In or Register to comment.