help with winsock events
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
Buffer = Buffer + SIN_CARACT_NULOS(MSComm1.Input)
' connected?..., two enter
If InStr(Buffer, "CONNECT 1200/NONE") > 0 Then
Sleep (2000)
Buffer = ""
Salida = " " & vbCrLf
MSComm1.Output = Salida
Sleep (2000)
MSComm1.Output = Salida
'Login to private system
ElseIf InStr(Buffer, "SIGN ON:") > 0 Then
Buffer = ""
Salida = psw_g & vbCrLf
MSComm1.Output = Salida
Sleep (500)
'send command PH
ElseIf Right(Buffer, 1) = "*" And Not Comando_PH Then
Buffer = ""
Salida = "PH" & vbCrLf
MSComm1.Output = Salida
Comando_PH = True
Sleep (1500)
'First line of command PH
ElseIf Comando_PH And Len(Buffer) > 87 Then
'Clean buffer
Buffer = Mid(Buffer, 4, Len(Buffer))
llego_ok = crc16(Buffer)
If llego_ok Then
Reg(I) = Buffer
I = I + 1
'record is OK
Salida = "A" & vbCrLf
MSComm1.Output = Salida
Else
'Resend record
Salida = "X" & vbCrLf
MSComm1.Output = Salida
End If
Buffer = ""
Sleep (1000)
'if there are more records, i read them
ElseIf Comando_PH And Len(Buffer) > 84 Then
'clean buffer
Buffer = Mid(Buffer, 2, Len(Buffer))
llego_ok = crc16(Buffer)
If llego_ok Then
Reg(I) = Buffer
I = I + 1
End If
'record is OK
Salida = "A" & vbCrLf
MSComm1.Output = Salida
Buffer = ""
Sleep (1000)
'End of records
ElseIf Comando_PH And InStr(Buffer, "**") Then
Bajada_Finalizada = True
End If
Case comEventBreak
error_comm = "Break Received"
Case comEventCDTO
error_comm = "Carrier Detect Timeout"
Case comEventCTSTO
error_comm = "CTS Timeout"
Case comEventDCB
error_comm = "Error retrieving DCB"
Case comEventDSRTO
error_comm = "DSR Timeout"
Case comEventFrame
error_comm = "Framing Error"
Case comEventOverrun
error_comm = "Overrun Error"
Case comEventRxOver
error_comm = "Receive Buffer Overflow"
Case comEventRxParity
error_comm = "Parity Error"
Case comEventTxFull
error_comm = "Transmit Buffer Full"
Case Is > 1000
error_comm = MSComm1.CommEvent
End Select
End Sub

