MSCOMM and RTS 
Author Message
 MSCOMM and RTS

Hi,
I want to use the RTS pin of my serial port of a Win2000 PC.
I want to raise the pin before sending a message. After sending the message
the RTS pin has to be Low.

I tryed the following code but RTS stays NOT(!) High all the time, just for
x second.
The behaviour of the same code is different at a WIN98 Pc.

Does anybody know what to do?

Thank you!

Lothar

c = "1234567890"
...
MSCOMM1.RTSEnable = True        'High at RTS

MSCOMM1.OutBufferCount = 0
MSCOMM1.Output = c                    'send it

 Do
         countbuffer = MSCOMM1.OutBufferCount        'wait until "send" is
ready
Loop Until countbuffer = 0

MSCOMM1.RTSEnable = False     'Low at RTS



Sat, 07 Aug 2004 21:15:49 GMT  
 MSCOMM and RTS
Hi,

Your code is OK, except for one thing.

You do not account for the UART transmit FIFO!  The UART FIFO buffers up to
16 bytes and sends from that buffer.  Thus what you are seeing is exactly
what you would expect.  You must add a delay AFTER the loop to account for
the time that it takes to clear the FIFO.  The actual delay time is easy to
calculate.  It is 16 (the FIFO buffer depth) divided by the serial speed (in
BYTES per second).  Thus, if the .Settings property = "9600, N, 8, 1" you
would delay for 16/960 (about 17 mS).  It would not be unreasonable to add
some "slop" and make this a 20 mS delay (appropriate for RS-485 for
example).

For lots more information on this sort of thing you may be interested in my
book.  I has working example code that covers this situation and lots more.

--
Richard Grier  (Microsoft Visual Basic MVP)
Hard & Software
12962 West Louisiana Avenue
Lakewood, CO  80228
303-986-2179 (voice)
303-986-3143 (fax)
Leave voice mail or fax that I can receive as email at 303-593-9315
Author of Visual Basic Programmer's Guide to Serial Communications, 2nd
Edition ISBN 1-890422-25-8 (355 pages).
For information look on my homepage at http://www.hardandsoftware.net.
Use the Books link to order.  For faster service contact the publisher at
http://www.mabry.com.



Sun, 08 Aug 2004 01:48:21 GMT  
 MSCOMM and RTS
Thanks{*filter*}!
We have already tried to wait for xx ms as you sugested. But the delay is
not always the same: different PC, different Windows Version -> different
dely!
For the application I have this is unfortunatly not possible.
A good solution seemed to be the use of  some API functions:

      dim myDCB as DCB 'The DCB structure defines the control setting for a
serial communications device.

      ret = GetCommState(MSCOMM1.CommID, myDCB)
      myDCB.fBitFields = &HCFFF And myDCB.fBitFields 'clear bit 13 und 14
      myDCB.fBitFields = &H3000 Or myDCB.fBitFields    'set bit 13 and 14 to
make the Hardware do the following:

' 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.
      ret = SetCommState(MSCOMM1.CommID, myDCB)

This is fine on a Win2k or WinXP PC.

But this commands do not work befor Win2000.

Do you have any other ideas?
Thanks
Lothar



Sun, 08 Aug 2004 23:23:19 GMT  
 MSCOMM and RTS
Thanks{*filter*}!
We have already tried to wait for xx ms as you sugested. But the delay is
not always the same: different PC, different Windows Version -> different
dely!
For the application I have this is unfortunatly not possible.
A good solution seemed to be the use of  some API functions:

      dim myDCB as DCB 'The DCB structure defines the control setting for a
serial communications device.

      ret = GetCommState(MSCOMM1.CommID, myDCB)
      myDCB.fBitFields = &HCFFF And myDCB.fBitFields 'clear bit 13 und 14
      myDCB.fBitFields = &H3000 Or myDCB.fBitFields    'set bit 13 and 14 to
make the Hardware do the following:

' 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.
      ret = SetCommState(MSCOMM1.CommID, myDCB)

This is fine on a Win2k or WinXP PC.

But this commands do not work befor Win2000.

Do you have any other ideas?
Thanks
Lothar



Sun, 08 Aug 2004 23:25:52 GMT  
 MSCOMM and RTS
Hi,

No.  What I suggested works for my applications. How are you generating the
delay?  Perhaps the problem is in that code.

--
Richard Grier  (Microsoft Visual Basic MVP)
Hard & Software
12962 West Louisiana Avenue
Lakewood, CO  80228
303-986-2179 (voice)
303-986-3143 (fax)
Leave voice mail or fax that I can receive as email at 303-593-9315
Author of Visual Basic Programmer's Guide to Serial Communications, 2nd
Edition ISBN 1-890422-25-8 (355 pages).
For information look on my homepage at http://www.hardandsoftware.net.
Use the Books link to order.  For faster service contact the publisher at
http://www.mabry.com.



Mon, 09 Aug 2004 01:15:03 GMT  
 MSCOMM and RTS

Quote:

> No.  What I suggested works for my applications. How are you generating
the
> delay?  Perhaps the problem is in that code.

      myMessage = "123456..."
      MSCOMM1.RTSEnable = true            ' set RTS pin

      MSCOMM1.OutBufferCount = 0
      MSCOMM1.Output = myMessage      ' send the string

      mydelay = GetTickCount() + 20           '  set delay to 20 ms

      Do

          countbu = MSCOMM1.OutBufferCount

       Loop Until countbu = 0 And mydelay < GetTickCount( )

        MSCOMM1.RTSEnable = false        'reset RTS pin

This code works in general. But the delay is not always the same: different
PC's -> different delays ...
The RTS pin must control the receive/transmit Pin of a 485 IC.
The response of the Controllers to this myMessage in the 485 Bussystem is
sometimes (on some PC's) faster than the delay.
In that case the receive/transmit Pin of the 485 IC is in wrong position and
messages are lost. That is why the timing is of RTS Pin is important to the
problem.
Thank's for Your help!
Lothar



Mon, 09 Aug 2004 18:08:12 GMT  
 MSCOMM and RTS
Hi,

Add DoEvents in your loop.

--
Richard Grier  (Microsoft Visual Basic MVP)
Hard & Software
12962 West Louisiana Avenue
Lakewood, CO  80228
303-986-2179 (voice)
303-986-3143 (fax)
Leave voice mail or fax that I can receive as email at 303-593-9315
Author of Visual Basic Programmer's Guide to Serial Communications, 2nd
Edition ISBN 1-890422-25-8 (355 pages).
For information look on my homepage at http://www.hardandsoftware.net.
Use the Books link to order.  For faster service contact the publisher at
http://www.mabry.com.



Tue, 10 Aug 2004 01:23:36 GMT  
 MSCOMM and RTS
Hi,

BTW, I think the the timeGetTime API is more appropriate for mS resolution
timing (GetTickCount does NOT provide mS resolution).

--
Richard Grier  (Microsoft Visual Basic MVP)
Hard & Software
12962 West Louisiana Avenue
Lakewood, CO  80228
303-986-2179 (voice)
303-986-3143 (fax)
Leave voice mail or fax that I can receive as email at 303-593-9315
Author of Visual Basic Programmer's Guide to Serial Communications, 2nd
Edition ISBN 1-890422-25-8 (355 pages).
For information look on my homepage at http://www.hardandsoftware.net.
Use the Books link to order.  For faster service contact the publisher at
http://www.mabry.com.



Tue, 10 Aug 2004 01:26:09 GMT  
 MSCOMM and RTS



Quote:
> Hi,

> Add DoEvents in your loop.

> --

doEvents does not improve the accuracy of the time mangement

I will try the timeGetTime function.

thanks,
Lothar



Tue, 10 Aug 2004 17:00:30 GMT  
 MSCOMM and RTS



Quote:
> Hi,

> BTW, I think the the timeGetTime API is more appropriate for mS resolution
> timing (GetTickCount does NOT provide mS resolution).

Yes, this works better! I have not tested jet this version on a Win95
machine (timeGetTime is little bit different on Win95) but on Win98 and
Win2000 the delay is nearly the same.

Thank a lot for this advise!

Althought we would prefer a not-time-controlled solution, this way probably
solves our problem.

Thanks again!!!

Lothar



Wed, 11 Aug 2004 00:17:08 GMT  
 MSCOMM and RTS
Hi,

doEvents does not improve the accuracy of the time mangement
<<

DoEvents ARR needed in the loop.  Not for time management, but so that other
things work correctly.

--
Richard Grier  (Microsoft Visual Basic MVP)
Hard & Software
12962 West Louisiana Avenue
Lakewood, CO  80228
303-986-2179 (voice)
303-986-3143 (fax)
Leave voice mail or fax that I can receive as email at 303-593-9315
Author of Visual Basic Programmer's Guide to Serial Communications, 2nd
Edition ISBN 1-890422-25-8 (355 pages).
For information look on my homepage at http://www.hardandsoftware.net.
Use the Books link to order.  For faster service contact the publisher at
http://www.mabry.com.



Wed, 11 Aug 2004 01:12:54 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. VB3 MSComm Question (RTS)

2. RTS/CTS using MSComm in VB

3. MSComm RTS Status

4. MSCOMM, Direct control of RTS

5. MSComm - Control of RTS

6. rts enable nd dtr enable with mscomm

7. Com Port CTS,RTS Etc...?

8. Com Port CTS,RTS Etc...?

9. How to detect RTS change?

10. DTR and RTS control in QBASIC

11. Controlling CTS and RTS from QB

12. How to detect CTS, RTS???

 

 
Powered by phpBB® Forum Software