Announcement

Collapse
No announcement yet.

Serial comms with hardware flow control (CTS/RTS)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Serial comms with hardware flow control (CTS/RTS)

    I need to write a serial comms program with hardware flow control (CTS/RTS), and was hoping for a couple of pointers:

    First, will the PB comms engine handle this provided I set CTSFlow and RTSFlow for the port, or do I have to set the lines manually from within my app?

    Second, RTSFlow has 4 possible settings: Disable, Enable, Handshake and Toggle. Which one should I use? I assume I know what Disable and Enable means (always off and always on, respectively?), but I'm not quite sure what the difference between Handshake and Toggle is. Sounds like Handshake is the one for me, but I'd like to know rather than assume...

    Also, if any one has some PB/DLL 6 source code using CTS/RTS flow control I'd really appreciate it!

    Thanks!

    Ketil

  • #2
    Do you already have PB/DLL 6.0?

    If so, use the COMM.BAS example in the SAMPLE\COMM folder to get you going.

    To add RTS/CTS flow control, add in the following statements:
    Code:
      COMM SET #hComm, CTSFLOW = 1
      COMM SET #hComm, RTSFLOW = 2
    RTSFLOW's states relate to the states that a Win32 DCB structure can use:
    0=RTS_CONTROL_DISABLE Disables the RTS line when the device is opened and leaves it disabled.
    1=RTS_CONTROL_ENABLE Enables the RTS line when the device is opened and leaves it on.
    2=RTS_CONTROL_HANDSHAKE Enables RTS handshaking. The driver raises the RTS line when the "type-ahead" (input) buffer is less than one-half full and lowers the RTS line when the buffer is more than three-quarters full. If handshaking is enabled, it is an error for the application to adjust the line by using the EscapeCommFunction function.
    3=RTS_CONTROL_TOGGLE Specifies that the RTS line will be high if bytes are available for transmission. After all buffered bytes have been sent, the RTS line will be low.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Lance,

      Wow - how's that for fast reply?? The support offered in these forums must be the best in the business!!

      Thanks a lot for the info! I talked to Digi (comms board vendor) about this, and they said that it is not handled by hardware or driver. I was afraid my app would have to handle this, meaning that setting RTSFlow and CTSFlow was just to indicate what protocol features were in use, but that I'd still have to toggle the RTS and CTS lines myself.

      From the info you supplied it seems that to change a no flow control routine to use CTS/RTS flow control (which is what I need to do), all I have to do is add the lines to set CTSFlow to 1 and RTSFlow to 2, and the rest is handled for me (lines on/off etc)?

      Yes, I do indeed have PB/DLL 6, and have used the serial comms routines several times. I just wasn't able to find a definite answer to what it would take to implement hardware flow control (no examples that I could find employed it). In fact, serial comms support was my main reason for sticking with VB, so as of version 6.0 PB is my preferred language. I'm still not quite familiar with all aspects of dialog events etc, but I'm learning... I'm quite sure that if one of you guys wrote a book called "PowerBASIC for VB dummies" or similar, it would make the best seller list the moment it was released!

      Thanks again,
      Ketil


      ------------------

      Comment


      • #4
        Thanks for the compliments!

        One hint for using the built-in COMM statements and functions is that they encapsulate the API - therefore, you can figure out what most of the COMM function's parameters do by looking into the serial communications API's in the WIN32.HLP file.

        You can manually fiddle the RTS line if you really need to, but you'll have to "get dirty" with the Win32 API (which is possible by getting the O/S file handle to the COMM file by using the FileAttr(hComm,2) function) and use the EscapeCommFunction(hFile, [%SETRTS] | [%CLRRTS]) API.

        In your case, you'll probably need to use either Handshake (2) or Toggle (3) ... which ever suits your application.


        ------------------
        Lance
        PowerBASIC Support
        mailto:s[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment

        Working...
        X