How do I Flush the rs-232 Input Buffer ?


Results 1 to 2 of 2

Thread: How do I Flush the rs-232 Input Buffer ?

  1. #1
    Registered
    Join Date
    Dec 2012
    Location
    USA
    Posts
    34
    Downloads
    0
    Uploads
    0

    Default How do I Flush the rs-232 Input Buffer ?

    Short version:
    How do I flush the rs-232 receive buffer?

    Longer version: LOL
    I'm using the Kanalog rs-232 and an rs-485 converter to send modbus commands to my VFD. It's working but the (very) cheap rs-485 converter is sending back spikes on the Kanalog rx input line anytime the Kanalog transmits a bit change.

    The scope shows any bit change on the transmit line produces a spike large enough on the input line to look like a start bit. It also finishes the frame with about 6 or 7 extra spikes every time so I get a bunch of ff bypes in the receive buffer in front of the actual VFD response.

    So far no amount of terminating resistors or capacitors has completely eliminated the spikes. I just wrote code to loop through and toss any leading ff bytes until the vfd address of '01' is found and it works pretty well.

    The vfd always takes at least 5 milliseconds to respond so I was wondering if there was a way to turn off the rs-232 and/or flush the rx buffer; if I did this a couple ms after sending a command it would eliminate the garbage ff bytes.

    I found a post that mentioned setting pRS232RecIn and Out to the same value but it didn't mention what value. I'm guessing that setting them equal to each other might work but which comes first ? LOL

    Would setting pRS232RecOut = pRS232RecIn be the correct order ? Or is this even possible ?

    I found the declarations in KMotionDef but it's mostly over my head.

    I probably should leave it alone since it's working but I hate to have bad data coming in if I don't have to.

    (eventually I'll try some better quality rs485 converters, mine are only 5 or 6 bucks each off ebay.)


    Thanks

    Similar Threads:


  2. #2
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default

    Hi czralv,

    Yes it is a circular buffer that forms a FIFO. So setting the Head to the Tail or vice versa will set the FIFO empty. Note your User Thread might get preempted (interrupted) at any time and if a new character came in then the Head (pRS232RecIn) would advance. Doing a WaitNextTimeSlice() beforehand will guarantee nothing unexpected happens.

    HTH
    Regards
    TK

    Regards
    TK http://dynomotion.com


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

How do I Flush the rs-232 Input Buffer ?

How do I Flush the rs-232 Input Buffer ?