MScomm doesn't work on non-vb computer
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: MScomm doesn't work on non-vb computer

  1. #1
    Join Date
    Nov 2012
    Posts
    2

    MScomm doesn't work on non-vb computer

    Hello,

    I developed a vb6 application using the MScomm control which works great, through the vb IDE and the compiled version. I plan on using this program on a few other computers that do not have VB installed so I used the package and deployment wizard to create the necessary CAB files, etc.

    I installed the program on another computer (also Win XP) and the application works with the exception of the serial communications. I don't get any errors it just does not work.

    The MScomm32.ocx is in the correct directory and I even registered it manually based on some things I came across searching on the internet.

    The question is, why won't the MScomm control work on machines that don't have VB installed even when the ocx is there and registered?

    Thanks in advance!

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,981

    Re: MScomm doesn't work on non-vb computer

    sure the machines have the same device on the same port? you can't hard code that, if you want it to work on other devices
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Nov 2012
    Posts
    2

    Re: MScomm doesn't work on non-vb computer

    The program loads the available COM ports and the user can select the COM port they want. I have verified the correct COM port by using hyperterminal so I know that is not the issue.

    I've read there are a lot of reliability issues with MSComm so I decided to go the direct Win32 API route. I wrote a little test program that uses direct API calls to read/write to a serial port to see if that would work on the other computer....and it does not, despite working great on my other computer that has VB6 installed.

    So now I'm not so sure it is an MSComm issue...

    I don't have any issues connecting to serial devices on either computer using TeraTerm, HyperTerm, etc.

    Thanks for the reply.

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,981

    Re: MScomm doesn't work on non-vb computer

    Might want to include the VB6 Runtime Update. Never had a problem with this, to test a modem:

    Code:
    ' Select the right COM port in the Properties of the control!
    
    Private Sub Command1_Click()
      MSComm1.PortOpen = True
      MSComm1.Output = "AT" & Chr$(13)
      Do
        DoEvents
      Loop Until MSComm1.InBufferCount > 1
      Text1.Text = MSComm1.Input
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,823

    Re: MScomm doesn't work on non-vb computer

    Well you surely do not need VB installed to get the MSComm control to work. I have used this control in many projects and have had many customers use it under Win2K, XP Sp1,Sp2,Sp3, XP MCE, Vista and 7. The only issue I have saw to date was a USB com port adapter, can't remember the make but some of these have been know to have issues.

    There are several things that may be an issue, port setting, baud rate, data bits, stop bits parity...

    What do you mean when you say it doesn't work? Is it not sending anything? Not receiveing anything? sending/receiving garbage? How are you testing and what results are you getting?
    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    May 2013
    Posts
    6

    Re: MScomm doesn't work on non-vb computer

    Hi,
    I have the same above problem, the computer send date through the serial port, but cant receive any thing.
    Thank you.

  7. #7
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,823

    Re: MScomm doesn't work on non-vb computer

    How are you checking to see if anything is received?
    What is your RThreshold set to?
    Always use [code][/code] tags when posting code.

  8. #8
    Join Date
    May 2013
    Posts
    6

    Re: MScomm doesn't work on non-vb computer

    RT=1
    I'm using logic analyzer to check the send. Also I'm sending data using MCU and "supposing" the program doesn't receive any thing.

    Ps. Thank you for the quick reply.
    Regards

  9. #9
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,823

    Re: MScomm doesn't work on non-vb computer

    Again how are you checking to see if the program is receiving anything?
    If you have not written code to process the data that is received then there is no way you would know if it was getting there or not unless you know that it is not being sent from the other side in which case the problem would be on that end.
    Always use [code][/code] tags when posting code.

  10. #10
    Join Date
    May 2013
    Posts
    6

    Re: MScomm doesn't work on non-vb computer

    Hi,
    The PC program suppose reads data from a Microcontroller and plot the received data on the screen, also it supposed to present a progress bar on the screen.
    Ill try to upload a segments from the program soon.

  11. #11
    Join Date
    May 2013
    Posts
    6

    Re: MScomm doesn't work on non-vb computer

    Hi,
    This is the structure of the program, with all the necessary code segments:
    Code:
     
    'written by Jim Rowe
    
    Option Explicit
    Dim intSampleCounter As Integer:            'data array counter/pointer
    Dim intCOMPort As Integer:                  'current COM port for USB sampler
    Dim intGain As Integer:                     'current gain setting
    Dim intResp As Integer:                     'response variable from dialog boxes
    Dim strPrompt As String:                    'prompt string for dialog boxes etc
    Dim strCrLf As String:                      'string for Cr & Lf
    Dim strBaud As String:                      'current baud rate setting for COM port
    Dim strSaveFileName As String:              'filename for saving a set of samples
    Dim strSampleRateCode As String:            'sample rate code to send to Sampler
    Dim strPrintFontName As String:             'user selected printer font
    Dim bytSamples(0 To 8191) As Byte:          'array for storage of data samples
    
    Private Sub Form_Load()
        Dim strFetchStrg As String
        Call ClearDataArray
        Call DisplayData
        strSaveFileName = ""
        strCrLf = Chr(13) + Chr(10)
        strSampleRateCode = "1":                'code for default sampling rate
        intCOMPort = 5:                         'default COM port setting for USB
        strBaud = "38400":                      'default baud rate
        intGain = 2000:                         'and gain setting
        On Error GoTo ErrorHandler
        Open "ECGSAMPL.cfg" For Input As #3:    'if there's a config file, open it
            Input #3, strFetchStrg:             'skip past header line
            Input #3, strFetchStrg:             'and date/time stamp line
            Input #3, strSaveFileName:          'get name of last data file used
            Input #3, intCOMPort:               'and last COM port used
            Input #3, strBaud:                  'and its baud setting
            Input #3, strSampleRateCode:        'and last sampling rate code
            Input #3, intGain:                  'and last gain settings
            Input #3, strPrintFontName:         'finally last printer font used
        Close #3
        lblPortDisplay.Caption = CStr(intCOMPort)
        Call ShowPortSettings
        With MSComm1:                           'now set up COM port control
            .CommPort = intCOMPort:             'set COM port number
            .RThreshold = 1:                    'set Rx threshold to 1 char
            .SThreshold = 2:                    'and Tx threshold to 2 chars
            .Handshaking = comNone:             'set for no handshaking
            .InBufferSize = 8192:               'set input buffer for 8192 samples
            .InputLen = 8192:                   '& getting 8192 bytes at a time
            .InputMode = comInputModeBinary:    'set for binary input
        End With
        Call ShowSampleRate
        Call ShowGainSetting
        Call DisplayData:                       'show blank display
        Exit Sub:                               'this is normal exit
        
    ErrorHandler:
        Close #3:                               'no config file, or corrupted; so
        Call DisplayData:                       'show blank display only
    End Sub
    
    Private Sub mnu1000SamplesPerSec_Click()
       .
       .
       .
    End Sub
    
    Private Sub mnu2000SamplesPerSec_Click()
       .
       .
       .
    End Sub
    
    Private Sub mnu500SamplesPerSec_Click()
       .
       .
       .
    
    End Sub
    
    Private Sub mnuAbout_Click()
       .
       .
       .
    End Sub
    
    Private Sub mnuPrint_Click()
       .
       .
       .
    End Sub
    
    Private Sub mnuSet28800_Click()
       .
       .
       .
        
    End Sub
    
    Private Sub mnuSet38400_Click()
       .
       .
       .
    End Sub
    
    Private Sub mnuSet9600_Click()
       .
       .
       .
    
    End Sub
    
    Private Sub mnuSetComPort_Click()
        Dim strDefault As String, intPortEntry As Integer
        strPrompt = "Set virtual COM port to which USB Sampler is connected:"
        strPrompt = strPrompt + strCrLf + "1-15"
        strDefault = "5"
        intPortEntry = CInt(InputBox(strPrompt, "Set COM Port", strDefault))
        If intPortEntry < 1 Or intPortEntry > 15 Then Exit Sub
        intCOMPort = intPortEntry
        lblPortDisplay.Caption = CStr(intCOMPort)
        MSComm1.CommPort = intCOMPort
    End Sub
    
    Private Sub mnuExit_Click()
       .
       .
       .
    End Sub
    
    Private Sub cmdGoSample_Click()
        If MSComm1.PortOpen = False Then MSComm1.PortOpen = True: 'open port if nec
        MSComm1.Output = "C" + strSampleRateCode:   'send command string to sampler
        MSComm1.DTREnable = True:                   'then set DTR true
        intSampleCounter = 0:                       'reset data array pointer
        pbSampleProgress.Value = 0:                 'reset progress bar
    End Sub
    
    Private Sub FileOpen_Click()
       .
       .
       .
    
    End Sub
    
    Public Sub ClearDataArray()
        For intSampleCounter = 0 To 8191
            bytSamples(intSampleCounter) = 128
        Next intSampleCounter
        
    End Sub
    
    Public Sub OpenDataFile()
       .
       .
       .
    End Sub
    
    Public Sub SaveData()
       .
       .
       .
    End Sub
    
    Private Sub mnuSave_Click()
       .
       .
       .
    
    End Sub
    
    Public Sub DisplayData()
        picDisplay.Cls
        Call ShowGraticule
        For intSampleCounter = 0 To 8191
            Call PlotSample
        Next intSampleCounter
        
    End Sub
    
    Public Sub ShowGraticule()
        Dim intLineCtr As Integer
        Dim intXval As Integer, intYval As Integer
        picDisplay.DrawWidth = 1:                       'now set line width to 1
       picDisplay.ForeColor = &H80C0FF:                   'set colour to light orange
        For intLineCtr = 1 To 81
            intXval = 600 + (intLineCtr * 100):            'draw light vert lines
            picDisplay.Line (intXval, 100)-(intXval, 6500)
        Next intLineCtr
          For intLineCtr = 0 To 24
            intYval = 228 + (intLineCtr * 256):            '& light horiz lines
            picDisplay.Line (600, intYval)-(8792, intYval)
        Next intLineCtr
        picDisplay.ForeColor = &H80FF&:                    'set colour to orange
        picDisplay.DrawWidth = 2:                       '& set line width to 2
        picDisplay.Line (600, 100)-(8792, 100):         'then draw main frame
        picDisplay.Line (8792, 100)-(8792, 6500)
        picDisplay.Line (8792, 6500)-(600, 6500)
        picDisplay.Line (600, 6500)-(600, 100)
        For intLineCtr = 1 To 8
            intXval = 600 + (intLineCtr * 1000):             'draw main vert lines
            picDisplay.Line (intXval, 100)-(intXval, 6575)
        Next intLineCtr
        For intLineCtr = 0 To 4
            intYval = 740 + (intLineCtr * 1280):             '& main horiz lines
            picDisplay.Line (525, intYval)-(8792, intYval)
        Next intLineCtr
     
        picDisplay.ForeColor = &HFFFFFF:                    'change colour to white
        picDisplay.FontSize = 10: picDisplay.FontBold = True    'then print legends
        picDisplay.CurrentX = 250: picDisplay.CurrentY = 3200
        picDisplay.Print "0"
        picDisplay.CurrentX = 200: picDisplay.CurrentY = 20
        picDisplay.Print "mV"
        picDisplay.CurrentX = 200: picDisplay.CurrentY = 6380
        picDisplay.Print "mV"
        picDisplay.FontBold = False
        If intGain = 2000 Then
            picDisplay.CurrentX = 100: picDisplay.CurrentY = 625
            picDisplay.Print "+1.0"
            picDisplay.CurrentX = 100: picDisplay.CurrentY = 1900
            picDisplay.Print "+0.5"
        Else
            picDisplay.CurrentX = 100: picDisplay.CurrentY = 625
            picDisplay.Print "+0.5"
            picDisplay.CurrentX = 20: picDisplay.CurrentY = 1900
            picDisplay.Print "+0.25"
        End If
        If intGain = 2000 Then
            picDisplay.CurrentX = 120: picDisplay.CurrentY = 5750
            picDisplay.Print "-1.0"
            picDisplay.CurrentX = 120: picDisplay.CurrentY = 4475
            picDisplay.Print "-0.5"
        Else
            picDisplay.CurrentX = 120: picDisplay.CurrentY = 5750
            picDisplay.Print "-0.5"
            picDisplay.CurrentX = 40: picDisplay.CurrentY = 4475
            picDisplay.Print "-0.25"
        End If
        picDisplay.CurrentX = 7050: picDisplay.CurrentY = 6850
        picDisplay.FontBold = True
        picDisplay.Print "SECONDS"
        picDisplay.FontBold = False
        Select Case strSampleRateCode
            Case "5"
                For intLineCtr = 0 To 16
                    picDisplay.CurrentX = 550 + (intLineCtr * 498)
                    picDisplay.CurrentY = 6580
                    picDisplay.Print CStr(intLineCtr)
                Next intLineCtr
            Case "1"
                For intLineCtr = 0 To 8
                    picDisplay.CurrentX = 550 + (intLineCtr * 999)
                    picDisplay.CurrentY = 6580
                    picDisplay.Print CStr(intLineCtr)
                Next intLineCtr
            Case "2"
                For intLineCtr = 0 To 4
                    picDisplay.CurrentX = 550 + (intLineCtr * 2000)
                    picDisplay.CurrentY = 6580
                    picDisplay.Print CStr(intLineCtr)
                Next intLineCtr
        End Select
        
    End Sub
    
    Public Sub PlotSample()
        Dim intXvalue As Integer, intYvalue As Integer
        Dim bytData As Byte
        picDisplay.ForeColor = &HFF00&                  'set colour to green
        intXvalue = 600 + intSampleCounter:             'get X position
        bytData = bytSamples(intSampleCounter)
        intYvalue = 6500 - (bytData * 25):              'and Y position
        picDisplay.Circle (intXvalue, intYvalue), 1:    'then plot, as tiny circle
        
    End Sub
    
    
    Private Sub mnuSetHighGain_Click()
       .
       .
       .
    End Sub
    
    Private Sub mnuSetLowGain_Click()
       .
       .
       .
    End Sub
    
    Private Sub mnuSetPrintFont_Click()
       .
       .
       .
    End Sub
    
    Private Sub MSComm1_OnComm()
        Dim bytInput() As Byte
        Dim lngCharCtr As Long
        If MSComm1.CommEvent = comEvReceive Then            'make sure it's data coming
            pbSampleProgress.Max = 100:                     'if so, initialise prog bar
            pbSampleProgress.Visible = True:                '& make it visible
            MSComm1.InBufferCount = 0:                      'clear Rx buffer
            lngCharCtr = 1:                                 'reset timing counter
            'now wait until all samples are in buffer
            Do While MSComm1.InBufferCount < 8160
                pbSampleProgress.Value = CInt(100 * (MSComm1.InBufferCount / 8192))
            Loop
            lngCharCtr = CLng(MSComm1.InBufferCount)
            bytInput() = MSComm1.Input:                     'now get data from Rx buffer
            MSComm1.PortOpen = False:                       'close port
            'now transfer from one array to the other
            For intSampleCounter = 0 To CInt(lngCharCtr - 1)
                bytSamples(intSampleCounter) = bytInput(intSampleCounter)
                pbSampleProgress.Value = CInt(100 * (intSampleCounter / 8192))
            Next intSampleCounter:                          'do all samples
            pbSampleProgress.Visible = False:               'finally hide progress bar
            Call DisplayData:                               'and display new data
        End If
    End Sub
    
    Public Sub ShowSampleRate()
       .
       .
       .
    End Sub
    
    Public Sub ShowPortSettings()
       .
       .
       .
    End Sub
    
    Public Sub ShowGainSetting()
       .
       .
       .
    End Sub
    
    Public Sub ShowErrorMsg()
       .
       .
       .
    End Sub

  12. #12
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,981

    Re: MScomm doesn't work on non-vb computer

    Maybe hard coding the modem port isn't the best way to do that.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  13. #13
    Join Date
    May 2013
    Posts
    6

    Re: MScomm doesn't work on non-vb computer

    What modem? Can you explain Please?
    This program reads a stream of data (8192 bytes) through a virtual serial port (USB to RS232 converter), and display the data as a graph on the screen.
    Regards.

  14. #14
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,823

    Re: MScomm doesn't work on non-vb computer

    Have you set a breakpoint in the oncomm event to see if it is firing?

    What happens when the code is ran?


    btw this is not needed
    Code:
    strCrLf = Chr(13) + Chr(10)
    there is already a constant for this

    VBCRLF
    Always use [code][/code] tags when posting code.

  15. #15
    Join Date
    May 2013
    Posts
    6

    Re: MScomm doesn't work on non-vb computer

    No, I didint set any breakpoint. I need some debugging advice at this point.
    I tried to convert the project to VB2008 using VS2008 to overcome what l think , is compatibility issue, but VB2008 returned lots of errors. Is it an MScomm issue? ...I dont know.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center