Reading a 15V+ signal on a COM port from VB 
Author Message
 Reading a 15V+ signal on a COM port from VB

Hi everyone!

I am looking for a source code to read a pin of the COM port from VB. What I
really need is an example where it is possible to read of there is a signal
on one of the pins (in my case pin 7). We need this for a fotocell counter!

I know this is possible in VB because the previous program that did this was
also written in VB but we do not have the source code!

This is really urgent!

Thanks in advance!

Greetings,

Wouter from Belgium




Tue, 20 May 2003 03:00:00 GMT  
 Reading a 15V+ signal on a COM port from VB


Quote:
> Hi everyone!

> I am looking for a source code to read a pin of the COM port from VB.
What I
> really need is an example where it is possible to read of there is a
signal
> on one of the pins (in my case pin 7). We need this for a fotocell
counter!

> I know this is possible in VB because the previous program that did
this was
> also written in VB but we do not have the source code!

Wouter,

I have only done it in C but using API calls, so it should be possible
in VB. What you need to do is open the port as a file with the
CreateFile API. This returns a handle to the file. Then use
ClearCommError to get all the status information. Pin 7 is CTS, right?
You will find all the details on MSDN, look for an article
called "Serial Communications in Win32"
--
Roger Abbott, RHA (Minisystems) Ltd - http://www.rhaminisys.com
DDE Client and Server ActiveX controls for Visual Basic
DDE FAQ and DDE utility tools, browser URL monitor,
Program launcher/setup menu, other freeware and shareware

Sent via Deja.com http://www.deja.com/
Before you buy.



Tue, 20 May 2003 03:00:00 GMT  
 Reading a 15V+ signal on a COM port from VB

Hi,

You can use MSComm (the Microsoft Comm control), or download XMComm.ocx from
my homepage.  You can use code like this:

MSComm1.PortOpen = True
If MSComm1.RTSHolding = True Then
    '+15 V
Else
    '-15 V
End If

'or

Private Sub MSComm1_OnComm ()
    If MSComm1.CommEvent = comEvRTS Then
        If MSComm1.RTSHolding = True Then
            '+15 V
        Else
            '-15 V
        End If
End Sub

The second construct is useful, because it notifies you when RTS changes
state (then tells you the actual state).

BTW, I selected RTS for this because it is pin 7 on a 9-pin serial port.
However, pin 7 on a 25-pin port is Ground, and cannot be used for input or
output.  For a 25-pin port you would have to use pin 4 (for RTS in the above
example).

For lots more information, you may be interested in my book.  See below.
--
Richard Grier (Microsoft Visual Basic MVP)
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 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/vbpgser.



Tue, 20 May 2003 03:00:00 GMT  
 Reading a 15V+ signal on a COM port from VB
Hi{*filter*}!

It worked fine! Thank you very much!

Greetings,

Wouter from Belgium


Quote:

> Hi,

> You can use MSComm (the Microsoft Comm control), or download XMComm.ocx
from
> my homepage.  You can use code like this:

> MSComm1.PortOpen = True
> If MSComm1.RTSHolding = True Then
>     '+15 V
> Else
>     '-15 V
> End If

> 'or

> Private Sub MSComm1_OnComm ()
>     If MSComm1.CommEvent = comEvRTS Then
>         If MSComm1.RTSHolding = True Then
>             '+15 V
>         Else
>             '-15 V
>         End If
> End Sub

> The second construct is useful, because it notifies you when RTS changes
> state (then tells you the actual state).

> BTW, I selected RTS for this because it is pin 7 on a 9-pin serial port.
> However, pin 7 on a 25-pin port is Ground, and cannot be used for input or
> output.  For a 25-pin port you would have to use pin 4 (for RTS in the
above
> example).

> For lots more information, you may be interested in my book.  See below.
> --
> Richard Grier (Microsoft Visual Basic MVP)
> 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 ISBN 1-890422-25-8 (355 pages).
> For information look on my homepage at http://www.*-*-*.com/ .
> Use the Books link to order.  For faster service contact the publisher at
> http://www.*-*-*.com/



Thu, 22 May 2003 03:00:00 GMT  
 Reading a 15V+ signal on a COM port from VB


Quote:
> Hi{*filter*}!

> It worked fine! Thank you very much!

Well, you did ask on the winapi newsgroup so I assumed you wanted to do
it using the API.

Roger

Quote:


> > Hi,

> > You can use MSComm (the Microsoft Comm control), or download
XMComm.ocx
> from
> > my homepage.  You can use code like this:

> > MSComm1.PortOpen = True
> > If MSComm1.RTSHolding = True Then
> >     '+15 V
> > Else
> >     '-15 V
> > End If

> > 'or

> > Private Sub MSComm1_OnComm ()
> >     If MSComm1.CommEvent = comEvRTS Then
> >         If MSComm1.RTSHolding = True Then
> >             '+15 V
> >         Else
> >             '-15 V
> >         End If
> > End Sub

> > The second construct is useful, because it notifies you when RTS
changes
> > state (then tells you the actual state).

> > BTW, I selected RTS for this because it is pin 7 on a 9-pin serial
port.
> > However, pin 7 on a 25-pin port is Ground, and cannot be used for
input or
> > output.  For a 25-pin port you would have to use pin 4 (for RTS in
the
> above
> > example).

> > For lots more information, you may be interested in my book.  See
below.
> > --
> > Richard Grier (Microsoft Visual Basic MVP)
> > 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 ISBN 1-890422-25-8 (355 pages).
> > For information look on my homepage at

http://www.*-*-*.com/ .

Quote:
> > Use the Books link to order.  For faster service contact the
publisher at
> > http://www.*-*-*.com/

--
Roger Abbott, RHA (Minisystems) Ltd - http://www.*-*-*.com/
DDE Client and Server ActiveX controls for Visual Basic
DDE FAQ and DDE utility tools, browser URL monitor,
Program launcher/setup menu, other freeware and shareware

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Fri, 23 May 2003 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Sending signals to com or lpt port

2. Controlling the Com port signals

3. ?MSCOMM - Read Signals From Serial Ports

4. HELP! reading special port signals in vb4

5. reading a signal from the paralell port

6. Finding COM Ports - Mouse dies when VB talks to its COM Port

7. Can VB Read a grocery store scanner via COM port

8. how to set serial port signals with VB?

9. Can Access use com ports to read data ?

10. Read COM (serial) port using CreateFile?

11. reading and writing to COM ports

12. reading a COM port

 

 
Powered by phpBB® Forum Software