Holaaaaaa:
Algúno de los cerebros en VB, podría decirme por qué el programa no me agrega nada en el txt?.
Me aparece como si se grabó algo, pero cuando abro el txt no hay nada.
Gracias anticipadas por responder.
Option Explicit
'''Boton Closecomm1
Private Sub Closecomm1_Click()
'''Close the port if it is open
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
'''Close le userform at the end of the reception
'Form1.Hide
End Sub
'''Boton Opencomm1
Private Sub Opencomm1_Click()
If MSComm1.PortOpen = False Then MSComm1.PortOpen = True
Call Receive
End Sub
Private Sub Form_Load()
'''Chose correct settings for your device
Dim Settings As String
Settings = "9600,n,8,1"
MSComm1.CommPort = 1
MSComm1.Settings = Settings
With MSComm1
'''Receive chr by chr
MSComm1.InputLen = 1
MSComm1.RThreshold = 0
MSComm1.SThreshold = 0
MSComm1.InBufferSize = 1024 '''10kb
MSComm1.InputMode = comInputModeText
MSComm1.Handshaking = 0 '''None
End With
End Sub
Private Sub Receive()
Dim FileName As String
Dim RxTxt As Variant
Dim inbuff As Variant
FileName = App.Path & "\RS232.txt"
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
Print #1, inbuff
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 inbuff = 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 #1
End Sub
Bye('_').