Como hacer salto de linea sin que se borre los datos recibidos
Publicado por angel uvalle (1 intervención) el 07/12/2019 17:45:12
quiero que me ayuden con este codigo este recibe los datos por medio de serial port este es el codigo completo pero me faltan unas cosas, primero que no borre los datos recibidos quiero que se mantengan mostrados y segundo que hace un salto de linea automaticamente cada que reciba los datos.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
Public Class Form1
Dim StrBufferEntrada As String
Dim StrBufferSalida As String
Private Delegate Sub DelegadoAcesso(ByVal AdicionarTexto As String)
Private Sub AccesoFormPrincipal(ByVal TextoForm As String)
StrBufferEntrada = TextoForm
'---------------------------------------------------
'---------------------------------------------------
TxtDatosRecibidos.Text = StrBufferEntrada
'---------------------------------------------------
'---------------------------------------------------
End Sub
Private Sub PuertaAccesoInterrupcion(ByVal BufferIn As String)
Dim TextoInterrupcion() As Object = {BufferIn}
Dim DelegadoInterrupcion As DelegadoAcesso
DelegadoInterrupcion = New DelegadoAcesso(AddressOf AccesoFormPrincipal)
MyBase.Invoke(DelegadoInterrupcion, TextoInterrupcion)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
StrBufferEntrada = ""
StrBufferSalida = ""
BtnConectar.Enabled = False
BtnEnviarDatos1.Enabled = False
CmbBaud.SelectedItem = ""
End Sub
Private Sub BtnBuscarPuertos_Click(sender As Object, e As EventArgs) Handles BtnBuscarPuertos.Click
For Each PuertoDisponible As String In My.Computer.Ports.SerialPortNames
CboPuertos.Items.Add(PuertoDisponible)
Next
If CboPuertos.Items.Count > 0 Then
CboPuertos.Text = CboPuertos.Items(0)
MessageBox.Show("SELECCIONAR EL PUERTO DE TRABAJO")
BtnConectar.Enabled = True
Else
MessageBox.Show("NINGUN PUERTO ENCONTRADO")
BtnConectar.Enabled = False
BtnEnviarDatos1.Enabled = False
CboPuertos.Items.Clear()
End If
End Sub
Private Sub BtnConectar_Click(sender As Object, e As EventArgs) Handles BtnConectar.Click
If BtnConectar.Text = "CONECTAR" Then
Try
SpPuerto.BaudRate = Convert.ToInt32(CmbBaud.Text)
SpPuerto.DataBits = 8
SpPuerto.Parity = IO.Ports.StopBits.None
SpPuerto.StopBits = IO.Ports.StopBits.One
SpPuerto.PortName = CboPuertos.Text
SpPuerto.Open()
BtnConectar.Text = "DESCONECTAR"
BtnEnviarDatos1.Enabled = True
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
ElseIf BtnConectar.Text = "DESCONECTAR" Then
BtnConectar.Text = "CONECTAR"
BtnEnviarDatos1.Enabled = False
SpPuerto.Close()
End If
End Sub
Private Sub BtnEnviarDatos_Click(sender As Object, e As EventArgs) Handles BtnEnviarDatos1.Click
SpPuerto.DiscardOutBuffer()
StrBufferSalida = TxtEnviarDatos.Text
SpPuerto.Write(StrBufferSalida)
End Sub
Private Sub DatoRecibido(sender As Object, e As IO.Ports.SerialDataReceivedEventArgs) Handles SpPuerto.DataReceived
Dim DatoInterrupcion As String
DatoInterrupcion = SpPuerto.ReadExisting
PuertaAccesoInterrupcion(DatoInterrupcion)
'StrBufferEntrada = SpPuerto.ReadExisting
'MessageBox.Show(StrBufferEntrada)
'TxtDatosRecibidos.Text = StrBufferEntrada
End Sub
Private Sub CboPuertos_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CboPuertos.SelectedIndexChanged
If BtnConectar.Text = "CONECTAR" Then
Try
With SpPuerto
.BaudRate = 9600
.DataBits = 8
.Parity = IO.Ports.StopBits.None
.StopBits = IO.Ports.StopBits.One
.PortName = CboPuertos.Text
.Open()
End With
BtnConectar.Text = "DESCONECTAR"
BtnEnviarDatos1.Enabled = True
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
ElseIf BtnConectar.Text = "DESCONECTAR" Then
BtnConectar.Text = "CONECTAR"
BtnEnviarDatos1.Enabled = False
SpPuerto.Close()
End If
End Sub
Private Sub TxtEnviarDatos_TextChanged(sender As Object, e As EventArgs) Handles TxtEnviarDatos.TextChanged
End Sub
Private Sub TxtDatosRecibidos_TextChanged(sender As Object, e As EventArgs)
End Sub
Private Sub CmbBaud_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CmbBaud.SelectedIndexChanged
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Button1.Text = "ATQ1" Then
Try
Button1.Text = "ATQ0"
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
ElseIf Button1.Text = "ATQ0" Then
Button1.Text = "ATQ1"
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If Button3.Text = "ATE1" Then
Try
Button3.Text = "ATE0"
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
ElseIf Button3.Text = "ATE0" Then
Button3.Text = "ATE1"
End If
End Sub
Private Sub TxtDatosRecibidos_TextChanged_1(sender As Object, e As EventArgs) Handles TxtDatosRecibidos.TextChanged
TxtDatosRecibidos.Text = StrBufferEntrada
End Class
Valora esta pregunta


0