MS Comm dize OnComm event. Property kontrole CommEvent sadrzi informaciju koji je tip eventa u pitanju (comEvReceive kad nesto stigne na port). To nesto sto je stiglo nalazi se u Input propertyu.
Private WithEvents m_Port As MSComm
Private Sub m_Port_OnComm()
Dim msg As String
Dim str As String
str = m_Port.Input
Select Case m_Port.CommEvent
' Errors
Case comEventBreak ' A Break was received.
msg = "ERR event Break"
Case comEventFrame ' Framing Error
msg = "ERR event Frame"
Case comEventOverrun ' Data Lost.
msg = "ERR event Overrun (data lost)"
Case comEventRxOver ' Receive buffer overflow.
msg = "ERR event RxOver (receive buffer overflow)"
Case comEventRxParity ' Parity Error.
msg = "ERR event RxParity (parity error)"
Case comEventTxFull ' Transmit buffer full.
msg = "ERR event TxFull (transmit buffer full)"
Case comEventDCB ' Unexpected error retrieving DCB
msg = "ERR event DCB (unexpected error retrieving DCB)"
'Events
Case comEvCD ' Change in the CD line.
msg = "CD changed (BL " & IIf(m_Port.CDHolding, "True", "False") & ")"
Case comEvCTS ' Change in the CTS line.
msg = "CTS changed (BW " & IIf(m_Port.CTSHolding, "True", "False") & ")"
Case comEvDSR ' Change in the DSR line.
msg = "DSR changed"
Case comEvRing ' Change in the Ring Indicator.
msg = "Ring"
Case comEvReceive ' Received RThreshold # of chars.
msg = "Receive event (Received RThreshold # of chars)"
m_InputStr = m_InputStr & str
m_Events.RaiseCustomEvent Me, "DataReceived", m_InputStr
Debug.Print "m_InputStr", m_InputStr
Case comEvSend ' There are SThreshold number of characters in the transmit buffer.
msg = "Send event"
Case comEvEOF ' An EOF charater was found in the input stream
msg = "EOF found"
Case Else
msg = m_Port.CommEvent
End Select
If m_Port.CommEvent = comEvReceive Then
' neki kod
End If
End Sub