Newbie's MSComm / serial port woes... 
Author Message
 Newbie's MSComm / serial port woes...

Hey gang! I've got a Newbie problem, and am looking for advice. I'm using
the MSComm control (in VB 5.0) to communicate ASCII characters via Comport
1 to a Keyence Programmable Logic Controller (PLC). Output to the PLC works
like a charm, and the PLC returns exactly what it's programmed to return,
as seen with the Win95 HyperTerminal (already checked NULL modem cable and
PLC's return characters on two terminal emulators). However, I can't seem
to catch the returned characters in my app. I'm using the following code:

While frmMain.comPLC.InBufferCount <= 0
    DoEvents
Wend

Character = frmMain.comPLC.Input

Please let me know if I've made a big goof. Thanks!!!

Jeff



Fri, 09 Mar 2001 03:00:00 GMT  
 Newbie's MSComm / serial port woes...
Hi Jeff,

It is much cleaner (and more reliable) to wait for a specific set of data.
For example you might want to:

Dim Buffer As String
Do
    Buffer = Buffer & MSComm1.Input
    If InStr(Buffer, vbCrLf) Then Exit Do
    DoEvents
Loop
Debug.Print Buffer

However, you might want to consider using OnComm receive processing for
this.  It is simpler, and requires no loop (set RThreshold = 1).

I have lots of examples in my book that you might find to be helpful.  See
below for information.

--
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.
For information, look on my homepage at
http://ourworld.compuserve.com/homepages/richard_grier.
Use the Books link to order from Amazon.com.  For faster service, contact
the publisher at http://www.mabry.com.



Fri, 09 Mar 2001 03:00:00 GMT  
 Newbie's MSComm / serial port woes...
You probably do not have the MSCOMM control set up properly.
There is an excellent book called the Visual Basic Programmers Guide
To Serial Communications by Richard Grier. You can find it a
www.amazon.com
You want to set up the MSCOMM control to generate an event when data
is received and then in the OnComm event handler you want to read in
the characters. Make sure that you set the InputLength property to 1
or an appropriate value for the data that you are reading.
DoEvents loops are  "Evil" and should be avoided at all costs.

If you want to purchase a good serial communications tool that
requires almost no programming, the company that I work for sells a
product called the Software Wedge that you may find a great deal
easier. If you are interested visit http://www.taltech.com



Quote:
>Hey gang! I've got a Newbie problem, and am looking for advice. I'm using
>the MSComm control (in VB 5.0) to communicate ASCII characters via Comport
>1 to a Keyence Programmable Logic Controller (PLC). Output to the PLC works
>like a charm, and the PLC returns exactly what it's programmed to return,
>as seen with the Win95 HyperTerminal (already checked NULL modem cable and
>PLC's return characters on two terminal emulators). However, I can't seem
>to catch the returned characters in my app. I'm using the following code:

>While frmMain.comPLC.InBufferCount <= 0
>    DoEvents
>Wend

>Character = frmMain.comPLC.Input

>Please let me know if I've made a big goof. Thanks!!!

>Jeff



Mon, 12 Mar 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Mscomm doesn't hear my serial port

2. Help: serial port woes

3. mscomm - send/receive from serial port

4. ?MSCOMM - Read Signals From Serial Ports

5. Mscomm, serial port question

6. Using serial port without using MSCOMM

7. MSComm problem with multi-port serial card

8. VB Communications, MSComm, Serial Ports and Modems...

9. Modems, Serial Ports, MSComm and VB

10. Modem, serial port, MSComm and VB Communications

11. Serial port, MSComm, Modem and VB communication

12. VB3 Serial Port Control without MSCOMM.VBX

 

 
Powered by phpBB® Forum Software