Solved

MSComm OnComm event (Input InBufferCount)

Posted on 2006-11-06
6
1,345 Views
Last Modified: 2012-05-05
I'm trying to understand this OnComm event code. I'm using someone else's code and I need to know what it's doing. I do understand most of it but here's the questions I do have.

Why is stComChar declared with * 1 ?

A CommEvent must be capable of being events other than recieve events. In this code we only trap for the "comEvReceive" event, correct?

When the comEvReceive event fires, the incoming data is only 1 character? So we keep holding each character until a CR is detected?

After processing all incoming data, the InBufferCount is clear until another OnComm event is fired? Does the OnComm event (or shall we say the com device) send an InBufferCount every time it fires?





Private Sub comm1_OnComm()

    Static stEvent As String   'storage for an Modem event
    Dim stComChar As String * 1   'temporary storage for received comm port data
   
    Select Case comm1.CommEvent

        Case comEvReceive                                       ' Received RThreshold # of chars.

            Do
                stComChar = comm1.Input                         'read 1 character .Inputlen = 1

                Select Case stComChar

                    Case vbLf                                   'Ignore linefeeds

                    Case vbCr                                   'The CR indicates the end of the Receive String
                        If Len(stEvent) > 0 Then
                          ProcessEvent stEvent                  'Process the Modem event
                          stEvent = ""
                        End If
                    Case Else
                        stEvent = stEvent + stComChar           'Save everything between CR's
                End Select

            Loop While comm1.InBufferCount                      'Loop until all characters in receive buffer are processed

    End Select
0
Comment
Question by:HKComputer
  • 3
  • 3
6 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 17881996
OnComm probably gets called when u have performed some communications between host and remote, beit a send or receive

CommEvent - is the type of communication

Case comEvReceive - u are checking for the received communication

u then read one character at a time, and if its a carriage return (not linefeed) and
stEvent has a value in it then u process that event

otherwise u set stEvent to be the char just read

basically read the input, string the carriage returns

0
 
LVL 4

Author Comment

by:HKComputer
ID: 17882059
>u then read one character at a time

Is there an option to do otherwise? Does data "stream" in one character at a time?
0
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 500 total points
ID: 17882099
Reason why its reading one char at a time is to strip off the carriage returns
I cant tell u whether there is a good alternative or not as I dont have that kind of setup to test
Also, u need to look at the ProcessEvent function, what does it do with the argument thats passed?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Author Comment

by:HKComputer
ID: 17882237
I do have the ProcessEvent function under control. In fact, the code I posted works very well. It's just there's a few parts of it that didn't make sense and I don't like to use code I don't understand.

I've developed a feature that checks Com ports for available modems, then checks to see if they are CallerID compatible. There is no sure-fire way of knowing if the modem is truly CallerID compatible and/or enabled, at least not for all modems. But you can give the user a pretty good idea using the code I've developed.

Then you can enable your modems (my code supports 2 of them) to monitor your lines for incoming calls. The process event logs the caller's information, then checks to see if it is a customer in the database. If so, there is a feature that can be enabled that pops up that caller's information. It all happens fast enough that you can see that caller's info. by about the second ring. The bad part is that monitoring the modem makes that modem unavailable for any other application to use. I wish there was some cost-effective way of "passively" monitoring the modem.

This is probably old hat for all you other access programmers but if someone wants the code I'd probably be willing to release. For free. Thanks to all the experts at EE for their tireless assistance. -HK
0
 
LVL 4

Author Comment

by:HKComputer
ID: 17882467
I failed to notice the following settings that get set when I "connect" to my modem:

        comm2.DTREnable = True
        comm2.RTSEnable = True
        comm2.RThreshold = 1   ' Generate a receive event on every character received
        comm2.InputLen = 1


Now I see why we are processing 1 character at a time.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17882492
Sure must be cpu hungry then. I know Access is pretty crap at that. I run queries, that may take time to run, it slows down my PC a fair bit (well at work that is!!!)

I guess thats why u need DoEvents in your code to help out a little
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now