[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

Aquiring External Data

I have a weigher which outputs ASCI data to a printer via an RS 232 port.
Is it possible to connect this to a com port and read this data into a VB database thus enabling a file of the data to be kept?
1 Solution
Yes, it is very easy to get it by using the MSComm Control.

Drop it to your form,
Set the setting to the same as your external device, and then read the port.

Search for help on line on MSComm control and then I can help you get it through.  


Read Comm Reoutine:
Public Function fReadCOM(theComm As MSComm, WaitOrNot As Boolean, Optional EndCha As String) As String

'   Name:       fReadCOM
'   Author:     Dalin Nie
'   Written:    4/14/97
'   Purpose:

'       This function read one line of data from the RS-232 Com port;
'   Called procedures and functions:

'   Input:  theComm:  Name of the MSComm control which is connected to the port you want to read
'           Wait--Boolean
'                 True:  Keep reading the port until the EndCha is received or timed out
'                        Soutable for contineous recieveing until the endCha after a command is issued, and

'                 False: Just Read once, get whatever is in the put and then get out, suitable
                         ' for use with OnComm event
'            EndCha: the external devices ending characters, usually vbCR or vbCRLF, optional
'   Output: The string it read
Dim lInput As String
Dim lMessage As String
Dim curReading As Single
Dim lLastTwo As String
Dim I As Integer
Dim lTime As Long

On Error GoTo fReadCOMErrHandler

' Set up output of fReadCOM to be blank by default

'add number of lines you expect to read

lMessage = ""

'Get one Line of Data
If WaitOrNot = True Then
        lTime = Timer
        Do Until Right(lMessage, Len(lStRespEnd)) = lStRespEnd
                If theComm.InBufferCount > 0 Then
                        lInput = theComm.Input
                        lMessage = lMessage + lInput
                    End If ' If frmDeckLayout.Comm1.InBufferCount = dataLen
                'Time out, I use 5 seconds here, change accordingly
                If Timer - lTime > 5 Then Exit Do
        lMessage = theComm.Input
    End If
     ' strip the EndCha, if what we received is ended with the End Cha
   If Right(lMessage, Len(EndCha)) = EndCha Then
         lMessage = Left(lMessage, Len(lMessage) - Len(EndCha))
     End If
  ' If Has a startcha, strip it too
  ' If Left(lMessage, Len(cStRespBegin)) = cStRespBegin Then
   '     lMessage = Right(lMessage, Len(lMessage) - Len(cStRespBegin))
   '   End If

    fReadCOM = lMessage
    'Put the response to some textbox
    'frmMain.txtCaroResp = lMessage
Exit Function

   fReadCOM = "ERROR" & Err.Number & " " & Err.Description
   ' Oprional gui.

End Function


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now