Ver Mensaje Individual
  #11 (permalink)  
Antiguo 11/10/2005, 07:24
Luis E. Díaz
 
Fecha de Ingreso: octubre-2005
Mensajes: 2
Antigüedad: 18 años, 6 meses
Puntos: 0
Rutinas puerto serial

Este es un ejemplo de como capturar los eventos en visual basic con el MSCOM.
Private Sub MSCommARB_OnComm()
Dim IntEvent As Integer
IntEvent = MDIarb.MSCommArb.CommEvent
Select Case IntEvent
Case comEvReceive ' Recive RThreshold # Número de caracteres.

While MDIarb.MSCommArb.InBufferCount ' Toma todos los caracteres del buffer
StrInput = MDIarb.MSCommArb.Input ' Lee .InputLen Numero de caracteres

'El siguiente codigo Determina cuando empieza una cadena de caracteres

Select Case StrInput
Case "+" 'caracter de inicio
StrIdentificador = ""
Case Chr$(10) 'Ignora el caracter lf
' Line Feed Ignorado
Case Chr$(129)

StrIdentificador = ""
Case Chr$(13) 'el CR indica final de la trama
IdentifierEvent (StrIdentificador) ' procesa la trama recibida
MDIarb.MSCommArb.InBufferCount = 0
Case Else
StrIdentificador = StrIdentificador + StrInput 'Save everything between the + and CR
End Select
Wend
'Los ssiguientes Eventos son ignorados, en operación normal no son muy criticos
Case comBreak ' A Break was received.
Case comCDTO ' CD (RLSD) Timeout.
Case comCTSTO ' CTS Timeout.
Case comDSRTO ' DSR Timeout.
Case comFrame ' Framing Error
Case comOverrun ' Data Lost.
Case comRxOver ' Receive buffer overflow.
Case comRxParity ' Parity Error.
Case comTxFull ' Transmit buffer full.
Case comEvCD ' Change in the CD line.
Case comEvCTS ' Change in the CTS line.
Case comEvDSR ' Change in the DSR line.
Case comEvRing ' Change in the Ring Indicator.
Case comEvSend ' chars in send buffer
'ignore these
End Select
End Sub


Private Sub IdentifierEvent(StrEvent As String)
'Llamada desde MSCommARB (MSCommARB control) OnComm Event
Dim ByteStado As String
Dim ByteChequeo As Byte
' si encuentra el caracter de una sentencia escape no procesa la informacion recibida
DirecEquipo = Mid(StrEvent, 2, 3) 'Lee el primer caracter de la cadena
NumeroEquipo = CInt(DirecEquipo)
Comando = Mid(StrEvent, 5, 1)
NumComando = CInt(Comando)
Modulo = Mid(StrEvent, 6, 1)

On Error Resume Next
NumModulo = CInt(Modulo)
If Err Then
MsgBox Modulo
End If
WordComando = Chr(129) & Chr(NumeroEquipo) & Chr(NumComando) & Chr(NumModulo) & Chr(ChkDato) & Chr(255)
If CompararComando(WordComando) Then
Select Case NumComando
Case 0 'Respuesta de la Interfaz al abrir canal.
StrError = Mid$(StrEvent, 8, 2)
If StrError <> "ER" Then
CanalEstado = True
Toolbar1.Buttons(8).Enabled = False
Toolbar1.Buttons(9).Enabled = True
If HypertInstancia = False Then
EsperaTerminaPrograma (PathHyperT + "\" + NombreArchivoHT + PathHyperT + "\" + NombreArchivoHTBayly)
Else
MDIarb.MSCommArb.PortOpen = False
End If
Else

End If
Case 1 'Respuesta de la Interfaz al cerrar canal.
Explorador.PicMod(ModSelec).BorderStyle = 0
StBarArb.Panels(3).Text = StBarArb.Panels(3).Key
Explorador.PicMux.Enabled = True
Toolbar1.Buttons(9).Enabled = False
Toolbar1.Buttons(10).Value = 0
Toolbar1.Buttons(10).Enabled = False
CanalEstado = False
Explorador.TmrLoopARB.Enabled = False
Case 3
'El siguiente bucle determina si un multiplexor posee eventos o no para ser enviados
If NumeroEquipo = EquipoNum Then
Alarma = Mid$(StrEvent, 8, 1)
If Alarma = Chr$(255) Then
Explorador.ShapeAlarmas(0).FillColor = &HFF&

Else
Explorador.ShapeAlarmas(0).FillColor = &HFFFFFF
End If
Alarma1 = Mid$(StrEvent, 9, 1)
If Alarma1 = Chr$(255) Then
Explorador.ShapeAlarmas(1).FillColor = &HFF&
Else
Explorador.ShapeAlarmas(1).FillColor = &HFFFFFF
End If
End If

Case 4
DatoFecha = LeerFecha(StrEvent)
FechaOk = FechaOk & Chr(Mid$(StrEvent, 8, 1))
FechaOk = FechaOk & Chr(Mid$(StrEvent, 9, 1))
If FechaOk = "OK" Then
MsgBox ("Fecha Configurada ")
Else
MsgBox ("Fecha Configurada ")
End If
Explorador.TmrLoopARB.Enabled = True
Case 5
StBarArb.Panels(5).Text = StBarArb.Panels(5).Key
'ChequeoSuma = 0
FechaOk = Mid$(StrEvent, 8, 12)
For I = 1 To 6 Step 2
fechac = fechac & Mid$(FechaOk, I, 2) & "/"
Next
For I = 7 To 12 Step 2
Horac = Horac & Mid$(FechaOk, I, 2) & ":"
Next
fechac = Left(fechac, 8)
Horac = Left(Horac, 8)
FechaRemota = fechac
HoraRemota = Horac
StBarArb.Panels(4).Text = StBarArb.Panels(4).Key & " " & FechaRemota & " " & HoraRemota
'DatoFecha = LeerFecha(StrEvent)
'For I = 1 To 6
'ChequeoSuma = ChequeoSuma + FechaRecibida(I)
'Next
'ChequeoSuma = ChequeoSuma And &HFF
'ByteChequeo = ChequeoSuma
'ByteChequeo = Not ByteChequeo
'ByteChequeo = ByteChequeo + 1
'If ByteChequeo = FechaRecibida(7) Then
'ChecksumOK = ChecksumOK + 1
'Else
'ErrChecksum = ErrChecksum + 1
'End If

Case 9
MsgBox ("Reset OK "), vbInformation
End Select
Else
MsgBox ("No se Recibio una Respuesta Valida "), vbCritical
End If
End Sub

No miren detalladamente el codigo solo lo general.

Algunas varibles se declaran en otro modulo.

Espero les de alguna idea de como utilizar el MSCOM.

Buen día.

Luis E. Díaz.