Cuando arranco el programa empiezo a leer la trama recibida por el serial que es: 10000 pero a veces parece que justo arranco el programa cuando el envio de la trama va por la mitad y recibo en el textbox 01000 y la sigo recibiendo de esa forma aunque varien los valores en el string o sea que no se "acomoda" estoy trabajando con 300 baudios como prueba y al correrse los bytes me interpreta cualquier cosa. A ver si me dan una ayudita con esto ya que no vi nada de esto en los posteos existentes.
Aca esta el codigo
Option Explicit
Private Sub Command1_Click()
End
End Sub
Private Sub Form_Load()
With MSComm1
.RThreshold = 4
.InputLen = 4
.Settings = "300,N,8,1"
.DTREnable = False
.CommPort = 2
.PortOpen = True
End With
End Sub
Private Sub MSComm1_OnComm()
Dim Num1 As String
Dim Num2 As String
Dim Num3 As String
Dim Num4 As String
Dim sData As String
Dim Cadena As String
Dim Todo As String
Dim Fecha As String
Dim pregunta As String
'pregunta = FF
'MSComm1.Output = pregunta
'MSComm1.InBufferCount = 0 'resetea el bufer de recepcion
If MSComm1.CommEvent = comEvReceive Then
sData = MSComm1.Input
'If Mid(sData, 1, 1) = 1 Then End
sData = Pasar2Asc(sData)
'antes era abajo Texto_Recibido.Text = Texto_Recibido.Text & sData & vbCrLf
Todo = sData & vbCrLf
Texto_Recibido.Text = Todo
Beep
Num1 = Mid(sData, 1, 1)
Num2 = Mid(sData, 2, 1)
Num3 = Mid(sData, 3, 1)
Num4 = Mid(sData, 4, 1)
Byte1.Text = Num1 'Mid(sData, 1, 1)
Byte2.Text = Num2 'Mid(sData, 2, 1)
Byte3.Text = Num3 'Mid(sData, 3, 1)
Byte4.Text = Num4 'Mid(sData, 4, 1)
Text5.Text = Date + Time
'Fecha = NOW
'Text6.Text = (Fecha)
If Num1 = 1 Then Text1.Text = "EQUIPO1" Else If Num1 = 0 Then Text1.Text = "OK"
If Num2 = 1 Then Text2.Text = "ALARMA": shpLuz(1).FillColor = RGB(255, 0, 0) Else If Num2 = 0 Then Text2.Text = "OK": shpLuz(1).FillColor = RGB(0, 255, 0)
If Num3 = 1 Then Text3.Text = "ALARMA": shpLuz(2).FillColor = RGB(255, 0, 0) Else If Num3 = 0 Then Text3.Text = "OK": shpLuz(2).FillColor = RGB(0, 255, 0)
'End If
End If
End Sub
Private Function Pasar2Asc(Cadena As String) As String
Dim Recorre As Integer
For Recorre = 1 To Len(Cadena)
Pasar2Asc = Pasar2Asc & Asc(Mid(Cadena, Recorre, 1))
Next
End Function
Sub Apagar1()
shpLuz(1).FillColor = RGB(0, 0, 0)
End Sub
Sub Apagar2()
shpLuz(2).FillColor = RGB(0, 0, 0)
End Sub
Saludos