MSComm and Modem Communications 
Author Message
 MSComm and Modem Communications

I need as much help as possible with modem communications and
good code practices for dealing with serial port communication.  
It looks like the serial port has to drive the code - but I want
the code to drive the serial port.  Please help.

Is there a good source for this somewhere?  I am developing a
user "friendly" interface for HVAC building control equipment.

-Shak



Sat, 14 Nov 1998 03:00:00 GMT  
 MSComm and Modem Communications


Quote:

>I need as much help as possible with modem communications and
>good code practices for dealing with serial port communication.  
>It looks like the serial port has to drive the code - but I want
>the code to drive the serial port.  Please help.

>Is there a good source for this somewhere?  I am developing a
>user "friendly" interface for HVAC building control equipment.

>-Shak

Well, I'm not ready to give you a lot of good code, but there is a sample
application for modem communications in the samples that came with your Visual
Basic.  It should show you how to make connections and get data in and out of
the port.  Of course you will have to figure out how to do the processing
after that.

Good luck,  there isn't an extreme lot of experience with serial port
communications using Visual Basic, so you won't have as much help on this as
on some things, but the people who are working it usually check in and help
out when they get time.

Bill Gill



Sun, 15 Nov 1998 03:00:00 GMT  
 MSComm and Modem Communications

Quote:


> >I need as much help as possible with modem communications and
> >good code practices for dealing with serial port communication.
> >It looks like the serial port has to drive the code - but I want
> >the code to drive the serial port.  Please help.

> >Is there a good source for this somewhere?  I am developing a
> >user "friendly" interface for HVAC building control equipment.

> >-Shak

> Well, I'm not ready to give you a lot of good code, but there is a sample
> application for modem communications in the samples that came with your Visual
> Basic.  It should show you how to make connections and get data in and out of
> the port.  Of course you will have to figure out how to do the processing
> after that.

> Good luck,  there isn't an extreme lot of experience with serial port
> communications using Visual Basic, so you won't have as much help on this as
> on some things, but the people who are working it usually check in and help
> out when they get time.

> Bill Gill

If you have VB3/4Pro with the MSComm custom control, you can try this test program for
transmission of binary values.  The following code assumes you have two serial ports available
on the same PC, one for transmit and one for receive.  If you only have one port, you should be
able to make this work using a serial loopback plug.  Your milage may vary.

Create a Form containing a command button labelled "Quit" and named cmdQuit, a command button
labelled "Transmit" and named cmdXmt, and two MSComm controls.  One MSComm control (named
MSComm1) should be set for Comm1 & the other (named MSComm2) for Comm2.  Set the RThreshold on
MSComm2 to '1' to force an OnComm event each time a character is received.  Then, enter the
following code:

Option Explicit

Private Sub cmdQuit_Click()
    Unload Me
End Sub

Private Sub cmdXmt_Click()
    Dim Outstring As String
    Dim ByteVal As Byte

    ByteVal = 223
    Outstring$ = Chr$(&HFF) & Chr$(&HFF) & Chr$(ByteVal)
    MSComm1.Output = Outstring
End Sub

Private Sub Form_Load()

    MSComm1.PortOpen = True
    MSComm2.PortOpen = True

End Sub

Private Sub MSComm2_OnComm()
    Static Instring As String
    Dim a As Long
    Dim R As Byte

    Instring$ = Instring$ & MSComm2.Input
    If Len(Instring$) > 0 Then
        Debug.Print ("Instring = " & Instring$)
        Debug.Print ("Instring length (Byte)= " & CStr(LenB(Instring$)))
        a& = &H100 * CLng(Asc(Mid$(Instring$, 2, 1))) _
                        + CLng(Asc(Mid$(Instring$, 1, 1)))
        R = Asc(Mid$(Instring, 3, 1))
        Debug.Print ("header = " & CStr(a&))
        Debug.Print ("Byte val = " & CStr(R))

    End If
    Instring = ""

End Sub

Notes:

1). The first two characters in the transmit string are meant to simulate a 'header' byte for my
application, and the third character (ByteVal) is meant to simulate the start of data.  Each
time the "Transmit" button is pressed, the transmit string is generated and sent to Comm1.  
Comm2's OnComm event is then triggered and moves the data from the commport receive buffer to
Instring$.  The data values and the length of the string (in characters) is printed to the debug
window.

2).  I was unable to get binary transmission to work using the ChrB$ conversion.  It seems that
the MSComm control likes 2-byte characters and won't play well with 1-byte characters.  This
unfortunately means that the effective data throughput is halved <sigh>.  If anyone has a way of
doing 1-byte character transmission using MSComm controls, I'd love to hear about it!

3) More information on using the MSComm control can be gotten from MSKB article Q143113
'Troubleshooting Tips for the MSComm Control'

good luck

Frank



Sun, 15 Nov 1998 03:00:00 GMT  
 MSComm and Modem Communications


Quote:
> 2).  I was unable to get binary transmission to work using the ChrB$

conversion.  It seems that
Quote:
> the MSComm control likes 2-byte characters and won't play well with

1-byte characters.  This
Quote:
> unfortunately means that the effective data throughput is halved <sigh>.

 If anyone has a way of
Quote:
> doing 1-byte character transmission using MSComm controls, I'd love to

hear about it!

MSComm converts from Unicode to Ansi internally before transmission so you
don't have to do it. Your thoughput is not halved.

--
David Cleary   ~   PDQComm 3.1 - Now with TAPI support
Senior Software Engineer
Crescent Division of Progress Software Corp.

Purchase and download components from our secure web sever
http://crescent.progress.com



Sun, 15 Nov 1998 03:00:00 GMT  
 MSComm and Modem Communications


Quote:
> I need as much help as possible with modem communications and
> good code practices for dealing with serial port communication.  
> It looks like the serial port has to drive the code - but I want
> the code to drive the serial port.  Please help.

> Is there a good source for this somewhere?  I am developing a
> user "friendly" interface for HVAC building control equipment.

If you are looking for canned forms and routines to use in your
application, you may want to check out our PDQComm product. Not only do
you get a better com control, you also get our ModemWare collection of
forms and source code to make ypour life easier, as well as much better
documentation, online help and numerous demos. For more info, check out
the URL below.

--
David Cleary   ~   PDQComm 3.1 - Now with TAPI support
Senior Software Engineer
Crescent Division of Progress Software Corp.

Purchase and download components from our secure web sever
http://crescent.progress.com



Sun, 15 Nov 1998 03:00:00 GMT  
 MSComm and Modem Communications



Quote:
> I need as much help as possible with modem communications and
> good code practices for dealing with serial port communication.  
> It looks like the serial port has to drive the code - but I want
> the code to drive the serial port.  Please help.

> Is there a good source for this somewhere?  I am developing a
> user "friendly" interface for HVAC building control equipment.

Shak:

It's not clear what you mean when you discuss which "drives" which, but
you shouldn't have any problem doing your project. I assume you are
using VB 3.0, and if you have the professional edition you can easily
use the MSCOMM.VBX control. There is a sample application that is a lot
of help.

I am doing machine control through the serial port and a controller card
that sends commands to X and Y stepper motor indexers and all I use is
the MSCOMM.VBX for serial control. You can set it to operate in a
polling mode or let it respond to events at the port (notification). In
either case, experimenting with the settings is essential and timing is
always an issue. A lot depends on what kind of hardware you are
connecting to. Send more details.

By the way, be sure you have the updated control, which is dated
5/12/93.

- David

--

05/30/96 20:11



Tue, 17 Nov 1998 03:00:00 GMT  
 MSComm and Modem Communications


Quote:
>I need as much help as possible with modem communications and
>good code practices for dealing with serial port communication.  
>It looks like the serial port has to drive the code - but I want
>the code to drive the serial port.  Please help.
>Is there a good source for this somewhere?  I am developing a
>user "friendly" interface for HVAC building control equipment.
>-Shak

Sending data to the port:
Use MsComm1.Output= "your output data"

Receiving data:
One way is to set up a timer to check on the port every so often. In the
timer event handler:
if MsComm1.InBuffercount then indata$=indata$ + MsComm1.Input

Make indata$ a global string and in the normal code use:

do
  if instr(indata$,"token") then
    p%=instr(indata$,"token")
    target$= left$(indata$,p%)
    indata$=mid$(indata$,p%+1)
  endif
  doevents
while <some break condition>

The token string may be the <CR><LF> sequence for example.



Wed, 25 Nov 1998 03:00:00 GMT  
 MSComm and Modem Communications

Is there a freely available example of a terminal program with some
basic features (protocol downloads, terminal emulations, whatever)
that I could tinker with and add features to? Should be for VB 3.0
running on Win 3.1

Thanks for any pointers!

-Ric


| Graffiti Online!               http://www.mindspring.com/~graffiti
| 5295 Highway 78 Suite D-306    770-972-9709 voice  770-736-2910 fax
| Stone Mountain GA 30087        770-972-4999 (2400)  or -9838 (14.4)



Fri, 27 Nov 1998 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

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

2. Modem, serial port, MSComm and VB Communications

3. Serial port, MSComm, Modem and VB communication

4. Modem to Modem Communications

5. Modem-Modem communication

6. Modem -Modem Communication

7. How to build modem communication program

8. Access 2000: Communication with Modem

9. Serial Communication - VB.NET - Detect if fax/modem or voice or busy or fast busy

10. voice - modem communication?

11. Help needed! Communication with modems

12. Modem Communications Tutorial

 

 
Powered by phpBB® Forum Software