Solved

Using MScomm with several serial ports

Posted on 2008-06-20
1
646 Views
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
 
    DoEvents
    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
       DoEvents
       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
            DoEvents
 
            '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
               DoEvents
            Loop
       Loop
       If mscomm.InBufferCount = 0 And bStarted = True Then
          bDone = True
       End If
    Loop
 
    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
 
Errorhandler:
    If Err = 8005 Then
       MsgBox ("Port Already Open - Change Settings and Select a Different Port Number")
       Err.Clear
       Exit Sub
    End If
    If Err = 8002 Then
       MsgBox ("Invalid Port Number - Change Settings and Select a Different Port Number")
       Err.Clear
       Exit Sub
    End If
 
    Err.Clear
End Sub
 
 Private Sub cmdStop2_Click()
    Call StopScanning(MSComm2, gsScanner2)
 End Sub

Open in new window

0
Comment
Question by:ochang435
1 Comment
 
LVL 7

Accepted Solution

by:
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 :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mirrorEnds challenge 6 145
sum67 challenge 35 116
no14 challenge 14 73
troubleshoot a python script 8 72
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

762 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