By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,295 Members | 717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,295 IT Pros & Developers. It's quick & easy.

RS232 port

P: 1
How can I get data from an RS232 port in VB6?
Oct 19 '06 #1
Share this Question
Share on Google+
2 Replies

100+
P: 1,646
How can I get data from an RS232 port in VB6?
You use the communications control
Oct 19 '06 #2

100+
P: 267
You use the communications control
hi
small sample - you may need to append settings etc..

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Settings = "9600,n,8,1"
  3. MSComm1.Settings = Settings
  4. MSComm1.Commport = 1
  5.  
  6. With MSComm1
  7.     .InputLen = 1
  8.     .RThreshold = 0
  9.     .SThreshold = 0
  10.     .InBufferSize = 10240  
  11.     .InputMode = comInputModeText
  12.     .Handshaking = 0
  13. End With
  14. End Sub
  15.  
  16. Private Sub Receive()
  17. FileName = App.Path & "\RS232.dat"
  18. Open FileName For Output As #1
  19.     Do
  20.     DoEvents
  21.     RxTxt = MSComm1.Input
  22. ' start capture if you get some input
  23. ' you may also wait for some other specific character
  24.     Loop Until RxTxt > vbNullString
  25.     inbuff = vbNullString
  26.  
  27.     Do
  28.     DoEvents
  29.     RxTxt = MSComm1.Input
  30. ' data is supposed to be separated by Chr(10)
  31. ' chose another separationmark if neccesary
  32.         If RxTxt = Chr(10) And Len(inbuff) > 0 Then
  33.             If Left(inbuff, 1) = Chr(10) Then inbuff = Right(inbuff, Len(inbuff) - 1)
  34.             Print #1, inbuff
  35.             inbuff = vbNullString
  36.         Else
  37.             If Len(RxTxt) > 0 Then
  38.             inbuff = inbuff + RxTxt
  39.             End If
  40.         End If
  41. ' data is supposed to end with Chr(3)
  42. ' chose another endmark if neccesary
  43.     Loop Until RxTxt = Chr(3)
  44. Close
  45. End Sub
  46.  
Oct 25 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.