[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • 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?
0
koolmill
Asked:
koolmill
1 Solution
 
DalinCommented:
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.  

Regards
Dalin

P.S.
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
                DoEvents
                'Time out, I use 5 seconds here, change accordingly
                If Timer - lTime > 5 Then Exit Do
            Loop
       
    Else
       
        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

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

End Function




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!

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