problem with VB MSComm and the DTR-line 
Author Message
 problem with VB MSComm and the DTR-line

Hi!

I want to get data from a D/A-transformer that is connected to the
serial port. He's adressed and the data is read with the RTS/CTS-lines.
With the DTR-line, the transformer is given a 'clock-signal' and in the
first step the transformer-state is switched to 'on'.

I change the state of the RTS/CTS-lines using the fields RTSEnable and
CTSHolding. The state of the DTR-line is switched with DTREnable.

RTS and CTS are working properly, I tested that connecting two computers
with a null-modem-cable. But changing the state of the DTR-line leads to
no result! The transformer isn't working, because he don't knows that he
is switched to 'on' and a test with the second computer shows that the
DTR-line has not changed to 'HIGH' or 'LOW'.

I've tested several settings of the MSComm-Object with no result. I'm
using WinNT 4.0 and tested my code under Win98, but that doesn't work,
too.

Here's a s{*filter*}t of my VB-Code, perhaps I've forgot to set a Field...?

-----snip

    MSComm.CommPort = 1

    MSComm.Settings = "9600, N, 8, 1"
    MSComm.RThreshold = 0
    MSComm.SThreshold = 0
    MSComm.InputLen = 0
    MSComm.CTSTimeout = 0:

    MSComm.PortOpen = True

    'WHILE ...

       MSComm.DTREnable = False

       '... some code .... change of RTS (write) & CTS (read)

       MSComm.DTREnable = True

       '... some code ....

     'WEND

-----snip

Perhaps it is possible to change the state of the handshake-lines with
the windows API?

Has anyone an idea?
Thank you in advance.

Tom

--

homepage: come.to/toms_homepage



Fri, 01 Feb 2002 03:00:00 GMT  
 problem with VB MSComm and the DTR-line
Hi!

I want to get data from a D/A-transformer that is connected to the
serial port. He's adressed and the data is read with the RTS/CTS-lines.
With the DTR-line, the transformer is given a 'clock-signal' and in the
first step the transformer-state is switched to 'on'.

I change the state of the RTS/CTS-lines using the fields RTSEnable and
CTSHolding. The state of the DTR-line is switched with DTREnable.

RTS and CTS are working properly, I tested that connecting two computers
with a null-modem-cable. But changing the state of the DTR-line leads to
no result! The transformer isn't working, because he don't knows that he
is switched to 'on' and a test with the second computer shows that the
DTR-line has not changed to 'HIGH' or 'LOW'.

I've tested several settings of the MSComm-Object with no result. I'm
using WinNT 4.0 and tested my code under Win98, but that doesn't work,
too.

Here's a s{*filter*}t of my VB-Code, perhaps I've forgot to set a Field...?

-----snip

    MSComm.CommPort = 1

    MSComm.Settings = "9600, N, 8, 1"
    MSComm.RThreshold = 0
    MSComm.SThreshold = 0
    MSComm.InputLen = 0
    MSComm.CTSTimeout = 0:

    MSComm.PortOpen = True

    'WHILE ...

       MSComm.DTREnable = False

       '... some code .... change of RTS (write) & CTS (read)

       MSComm.DTREnable = True

       '... some code ....

     'WEND

-----snip

Perhaps it is possible to change the state of the handshake-lines with
the windows API?

Has anyone an idea?
Thank you in advance.

Tom

--

homepage: come.to/toms_homepage



Fri, 01 Feb 2002 03:00:00 GMT  
 problem with VB MSComm and the DTR-line
HI,

Windows interferes with the timing of DTR (and RTS) when you use the
DTREnable and RTSEnable properties.  To do what you want, I think that you
will have to access the UART modem status register (to read the CTS bit),
and the UART modem control register (for the RTS and DTR control bits).  To
do this you need an add-on DLL or OCX.  I have an OCX that you can download
from my homepage (IOOcx).  Many of these solutions, such as IOOcx work only
under Windows 95/98, so NT is more difficult (though possible, using a
kernel mode driver add-on).

Timing may be critical for a synchronous data transfer using this sort of
arrangement.  You will not be able to get speeds in excess of 1000 bits per
second, and even that speed is problematic.  Do you have any specific speed
requirements?  It should work without any problem if you need only 100-300
bits per second.

If all that you need is to assure that DTR is in the correct state, and if
speed is not a special issue, then you can try this:

    MSComm.CommPort = 1
    'the other MSComm properties do not matter

    MSComm.PortOpen = True
    'WHILE ...
       MSComm.DTREnable = False
        Wait 200
       '... some code .... change of RTS (write) & CTS (read)
       MSComm.DTREnable = True
        Wait 200
       '... some code ....
     'WEND

Private Sub Wait (ByVal Milliseconds)
Dim Timeout As Long
    Timeout = timeGetTime + Milliseconds)
    Do Until timeGetTime >= Timeout
        DoEvents
    Loop
End Sub

Public Declare Function timeGetTime  Lib "winmm.dll" () As Long

However, even changing RTS state using MSComm1.RTSEnable = True or False
encounters a delay in the change of state of the actual pin on the serial
port -- this may cause trouble.  Note, that when you read CTS, you code has
to allow for the time it takes for Windows to actually set the RTS state,
and for the connected device to respond.  You cannot read CTS immediately,
and expect it to be in the correct state.

--
Richard Grier
Hard & Software
12962 West Louisiana Avenue
Lakewood, CO  80228
303-986-2179 (voice)
303-986-3143 (fax)
Author of Visual Basic Programmer's Guide to Serial Communications, 2nd
Edition (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.



Fri, 01 Feb 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. problem with VB MSComm and the DTR-line

2. Problem with VB MSComm and the DTR-line

3. Monitoring DTR line in VB Win

4. DTR control with MSCOMM

5. rts enable nd dtr enable with mscomm

6. Detecting State Change in DTR Line with VB4.0

7. Detecting Changes in DTR Comm Line in VB4

8. ***** Fix to DTR Problem *****

9. vb-5 mscomm problem

10. VB 6.0 MsComm object problem

11. VB 4.0a fixes MSCOMM problem?

12. Problem with Modesm, MSCOMM.VBX and VB 3.0 Pro

 

 
Powered by phpBB® Forum Software