Using MScomm with several serial ports

Posted on 2008-06-20
Last Modified: 2013-11-23
I have an old VB6 aplication that uses MScomm to with a scanner to scan labels. I need to modify the code so that several scanners can be attached via a multi port system. This system uses two timer controls. I have modified the code to use more timer contrls, but it always seems to go through the loop only once and does not extend to the second or third scanner.
Below is the procedure to which scanner and mscomm parameters are passed. Any ideas?
Private Sub StartScanning(mscomm As mscomm, objTimer As Timer, objTimer2 As Timer)

    Dim bStarted As Boolean

    Dim sInstring As String

    Dim bDone As Boolean

    On Error GoTo Errorhandler

    bStarted = False


    objTimer.Enabled = True

    sInstring = ""

    txtInput.Text = ""

    bDone = False

    bStop = False

    'Tell the control to read entire buffer when Input is used

    mscomm.InputLen = 0

    If mscomm.PortOpen = False Then

       mscomm.PortOpen = True

    End If

    StatusBar1.Panels(1).Text = "Waiting for Scanned Labels ..."

    StatusBar1.Panels(1).Width = StatusBar1.Width - (StatusBar1.Panels(2).Width + StatusBar1.Panels(3).Width)

    sInstring = ""

    'Do While Not bDone

    Do While bStop = False


       Do While mscomm.InBufferCount > 0

            StatusBar1.Panels(1).Text = "Reading Scanned Labels ..."

            StatusBar1.Panels(1).Width = StatusBar1.Width - (StatusBar1.Panels(2).Width + StatusBar1.Panels(3).Width)

            bStarted = True


            'do not switch to line after to see newly scanned labels first - did not work

            'sInstring$ = MSComm1.Input & sInstring$

            'next line is the right order

            sInstring$ = sInstring$ & mscomm.Input

            txtInput.Text = sInstring

            objTimer.Interval = 100

            objTimer.Enabled = True

            Do While objTimer2.Enabled = True




       If mscomm.InBufferCount = 0 And bStarted = True Then

          bDone = True

       End If


    txtInput.Text = sInstring

    objTimer.Enabled = False

    If mscomm.PortOpen = True Then

       mscomm.PortOpen = False

    End If

'    ' * make the call to stop based on the control passed as parameter object

'    If bStop = True Then

'        Select Case mscomm

'        Case MSComm1

'            Call cmdStop_Click

'        Case MSComm2

'            Call cmdStop2_Click

'        Case MSComm3

'            Call cmdStop3_Click

'        End Select

'    End If

    Exit Sub


    If Err = 8005 Then

       MsgBox ("Port Already Open - Change Settings and Select a Different Port Number")


       Exit Sub

    End If

    If Err = 8002 Then

       MsgBox ("Invalid Port Number - Change Settings and Select a Different Port Number")


       Exit Sub

    End If


End Sub

 Private Sub cmdStop2_Click()

    Call StopScanning(MSComm2, gsScanner2)

 End Sub

Open in new window

Question by:ochang435
1 Comment

Accepted Solution

Dauhee earned 250 total points
ID: 21837460
you could get a timer to kick off multiple instances of StartScanning but might be easier in long run (but more coding up front) to put into an activeX control and then place multiple controls on the form - 1 for every scanner

basically you need multi-threading so that is a workaround vb6 style :)

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

912 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

20 Experts available now in Live!

Get 1:1 Help Now