MSComm Serial Com Port!!!


Thread Starter

Tina Tang

<p>I got a VB code that can receive data from a coordinator. However, it can only be read once. For example, after I connected to the Com Port, it takes in the data but after that it did not refresh and the data is still the same even though I have varied the data.

<p>What I need is to be able to read the received data and the data need to be refreshed every time because it is connected to the sensors. Sensors' value may varied any time of the day.

<p>Below is the program code.
Private Sub MSComm1_OnComm()
Dim buffer() As Byte
Dim text As String
Select Case MSComm1.CommEvent
Case comBreak
MsgBox ("Break received")
Case comEventFrame
MsgBox ("comEventFrame Received")
Case comEventOverrun
MsgBox ("comEventOverrun Received")
Case comEventRxOver
MsgBox ("comEventRxOver Received")
Case comEventRxParity
MsgBox ("comEventRxParity received")
Case comEventTxFull
MsgBox ("comEventTxFull Received")
Case comEventDCB
MsgBox ("comEventDCB received")
Case comEvCD
MsgBox ("comEvCD Received")
Case comEvCTS
MsgBox ("comEvCTS received")
Case comEvDSR
MsgBox ("comEvDSR Received")
Case comEvRing
MsgBox ("comEvRing received")
Case comEvReceive
On Error Resume Next
j = MSComm1.InBufferCount
buffer = MSComm1.Input
For i = 0 to j
Rx.SelStart = Len(Rx.text)
text = Hex$(buffer(1))
If Len(text) = 1 Then
text = "0" & text
End If
Rx.SelText = text
Next i
Rx.SelStart = Len(Rx.text)
Rx.text = Rx.text & vbCrLf

End Select

End Sub

<p>Any kind soul, if you know how to solve my problem could you kindly email me about it?
As this concerns my Final Year Project and it means a lot to me. Thank You!