¡HOLA!
Yo tomo valores de 4 termocuplas, espero ayudarte:
Option Explicit
Dim nVAL001, nVAL002, nVAL003, nVAL004 As Long
Dim nValPro As Single
Dim VALRECI As String
Dim nCon001 As Long
Dim nConEve As Long
Dim nSuiEve As Long
Private Sub cAbP_Click()
If MSComm1.PortOpen = True Then
Else
MSComm1.PortOpen = True
SB11.Panels(1).Text = "Se abrió el puerto COM1"
End If
End Sub
Private Sub cCeP_Click()
If MSComm1.PortOpen = False Then
Else
MSComm1.PortOpen = False
SB11.Panels(1).Text = "Se cerró el puerto COM1"
End If
End Sub
Private Sub cSalir_Click()
Unload Me
End Sub
Private Sub Form_Load()
Me.Top = 0
Me.Left = 0
nConEve = 0
nSuiEve = 0
nCon001 = 0
SB11.Panels(1).MinWidth = Me.Width
SB11.Panels(1).Text = ""
cAbP.Caption = "Abrir Puerto COM1" & vbCrLf & "RS232"
cCeP.Caption = "Cerrar Puerto COM1" & vbCrLf & "RS232"
'----------------------------------------------------------------------------------
'Configuración de control MSComm
MSComm1.InputLen = 0 'Leer todo el buffer
MSComm1.RThreshold = 1 'Recibir
MSComm1.SThreshold = 1 'Enviar
MSComm1.CommPort = 1 'Puerto COM1
MSComm1.Settings = "2400,N,8,1" 'Yo trabajo a esta veloidad
'----------------------------------------------------------------------------------
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
End Sub
Private Sub Form_Resize()
If Me.WindowState = 1 Then
Else
SB11.Panels(1).MinWidth = Me.Width
End If
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
nConEve = nConEve + 1
'Aquí tomo los valores del puerto por cada evento...
VALRECI = MSComm1.Input
If Val(VALRECI) = 1 Then
nConEve = 0
nSuiEve = 1
Else
If nSuiEve = 0 Then
Else
Select Case nConEve
Case 1
nVAL001 = Val(VALRECI)
Case 2
nVAL002 = Val(VALRECI)
Case 3
nVAL003 = Val(VALRECI)
Case 4
nVAL004 = Val(VALRECI)
nValPro = (nVAL001 + nVAL002 + nVAL003) / 3
nValPro = Round(nValPro, 2)
nVAL001 = 0
nVAL002 = 0
nVAL003 = 0
nVAL004 = 0
nSuiEve = 0
End Select
End If
End If
End Select
End Sub
Si necesitas más ayuda:
arm_saq@yahoo.com