Lectura Puerto COM
Publicado por Oscar Danilo (13 intervenciones) el 08/11/2018 21:02:04
Hola Buenas tardes Estimados Colegas, estoy realizando un Sistema en Visual Studio 2017 con Framework 4.5. El cual, captura datos desde el Puerto COM. La problemática consiste, que el Sistema funciona bien en mi laptop, pero a la hora de pasarlo a la máquina cliente(PC de Escritorio), no me lee.
Probé enviar con un Msgbox que estaba leyendo(Si es que estuviese leyendo datos) y, efectivamente estaba leyendo datos solo que no me los muestra.
=======================================================================
Datos a tomar en cuenta:
1 Formulario Principal.
1 Formulario Secundario (Tipo MDI).
1 Módulo(Donde mando a llamar la función para realizar la lectura de datos del Puerto COM)
=======================================================================
Les comparto parte del código:
================Módulo================================================
================Módulo================================================
En el Formulario Secundario
================Formulario Principal================================================
================Formulario Principal================================================
De antemano, muchas gracias por el apoyo.
Probé enviar con un Msgbox que estaba leyendo(Si es que estuviese leyendo datos) y, efectivamente estaba leyendo datos solo que no me los muestra.
=======================================================================
Datos a tomar en cuenta:
1 Formulario Principal.
1 Formulario Secundario (Tipo MDI).
1 Módulo(Donde mando a llamar la función para realizar la lectura de datos del Puerto COM)
=======================================================================
Les comparto parte del código:
================Módulo================================================
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
Module Lectura
'Variables para controlar flujo y conexión al puerto COM
Public Delegate Sub DatoCOMLeido(ByRef DatoLeido As System.IO.Ports.SerialPort)
Public WithEvents Puerto As New System.IO.Ports.SerialPort
Public Form1 as new Form1
Public StrLeer As String, Peso As Integer, EstadoPesaje As Integer, TipoPesaje As Integer
Sub MandarPeso(ByRef Dato As System.IO.Ports.SerialPort)
Dim parts() As String
Dim Pesajes As New List(Of Integer)
Dim i As Integer = 0, x As Integer = 0
StrLeer = Dato.ReadExisting().Trim
parts = Split(StrLeer, " ")
For i = 0 To (parts.Count / 2) - 1
If IsNumeric(parts(i)) = True Then
Peso = CInt(parts(i).ToString)
Pesajes.Add(Peso)
End If
Next
Form1.LblIndicador.Text = Pesajes.Max().ToString
'MsgBox(Pesajes.Max())
End Sub
Public Sub LeerPuertoCOM(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles Puerto.DataReceived
Try
FrmPServicioBascula.LblIndicador.Invoke(New DatoCOMLeido(AddressOf MandarPeso), New Object() {Puerto})
Catch ex As Exception
Exit Sub
End Try
End Sub
Public Sub CerrarPuerto()
If Puerto.IsOpen = True Then
Puerto.Close()
End If
End Sub 'Terminado
Public Sub AbrirPuerto()
Try
With Puerto
If .IsOpen Then
.Close()
End If
.PortName = "COM3"
.BaudRate = 9600
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
.Parity = IO.Ports.Parity.None
.Open()
End With
Catch ex As Exception
MsgBox(ex.ToString)
Exit Sub
End Try
End Sub 'Terminado
Public Sub CargarModulos()
Lectura.Form1.TopLevel = False
FrmPrincipal.PnlFormularios.Controls.Add(Lectura.Form1)
Lecrtura.Form1.Location = New Point(70, 5)
Lectura.Form1.Size = New Size(821, 656)
Lectura.Form1.Show()
End Sub
End Module
En el Formulario Secundario
================Formulario Principal================================================
1
2
3
4
5
6
7
8
Public Class FrmPrincipal
Private Sub MnuPesajeEntradas_Click(sender As Object, e As EventArgs) Handles MnuPesajeEntradas.Click
Lectura.CargarModulos()
Lectura.AbrirPuerto()
End Sub
End Sub
De antemano, muchas gracias por el apoyo.
Valora esta pregunta
0