How can I get data from an RS232 port in VB6?
RS232 port
Collapse
X
-
You use the communications controlOriginally posted by johnfotlHow can I get data from an RS232 port in VB6? -
hiOriginally posted by willakawillYou use the communications control
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 SubComment
Comment