RS232 port

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johnfotl
    New Member
    • Oct 2006
    • 1

    #1

    RS232 port

    How can I get data from an RS232 port in VB6?
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by johnfotl
    How can I get data from an RS232 port in VB6?
    You use the communications control

    Comment

    • albertw
      Contributor
      • Oct 2006
      • 267

      #3
      Originally posted by willakawill
      You use the communications control
      hi
      small sample - you may need to append settings etc..

      Code:
      Private Sub Form_Load()
      Settings = "9600,n,8,1"
      MSComm1.Settings = Settings
      MSComm1.Commport = 1
      
      With MSComm1
          .InputLen = 1
          .RThreshold = 0
          .SThreshold = 0
          .InBufferSize = 10240  
          .InputMode = comInputModeText
          .Handshaking = 0
      End With
      End Sub
      
      Private Sub Receive()
      FileName = App.Path & "\RS232.dat"
      Open FileName For Output As #1
          Do
          DoEvents
          RxTxt = MSComm1.Input
      ' start capture if you get some input
      ' you may also wait for some other specific character
          Loop Until RxTxt > vbNullString
          inbuff = vbNullString
         
          Do
          DoEvents
          RxTxt = MSComm1.Input
      ' data is supposed to be separated by Chr(10)
      ' chose another separationmark if neccesary
              If RxTxt = Chr(10) And Len(inbuff) > 0 Then
                  If Left(inbuff, 1) = Chr(10) Then inbuff = Right(inbuff, Len(inbuff) - 1)
                  Print #1, inbuff
                  inbuff = vbNullString
              Else
                  If Len(RxTxt) > 0 Then
                  inbuff = inbuff + RxTxt
                  End If
              End If
      ' data is supposed to end with Chr(3)
      ' chose another endmark if neccesary
          Loop Until RxTxt = Chr(3)
      Close
      End Sub

      Comment

      Working...