Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read and Store Specific Values from MSComm into VBA application

Status
Not open for further replies.

NiamhB

Technical User
Mar 14, 2013
2
Hi,

I have a project that sends 4 bytes of data via RS232 to the Serial Port on the computer.
I want to store the values coming in into specific registers. When I receive the decimal value 230 (binary 11100110) I want to store the next two bytes as X and then Y so that I can use this information further.

I can display the data on MSComm in a text box repeatedly but I don't know how to store the X and Y values.

I want to use the X and Y values coming in so that I can double integrate them and relate the relative displacement to the displacement of the mouse pointer.

What I have so far is:
Private Sub MSComm1_OnComm()
Dim sData As String
Dim ID As Long
Dim X As Long
Dim Y As Long
Dim Z As Long

Select Case MSComm1.CommEvent
Case comEvReceive
Buffer = MSComm1.Input

If (Buffer) = 230 Then
ID = Asc(sData)
End Select
End Sub

I don't know how to store the next two bytes in an X and Y Byte

Can anyone help me out please?
 
hi,

how does sData get assigned?

so it seems you might set a flag true when you process a certain value like 230, and start a counter. When the couter is 1, assign X; when the counter is 2, assign Y.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Oh whoops ,I was trying different bits of code and I must have gotten the assignments mixed up sData should be Buffer.

Great thanks, so would it be something like this:

Private Sub MSComm1_OnComm()
Dim sData As String
Dim ID As Long
Dim X As Long
Dim Y As Long
Dim Z As Long
Dim Count as Integer

Select Case MSComm1.CommEvent
Case comEvReceive
Buffer = MSComm1.Input

If (Buffer) = 230 Then
Count =0
End If
If (Count) = 0 Then
Count = Count+1
End IF

If Count = 1 Then
X = Buffer
End IF

If Count = 2 Then
Y = Buffer
Count = 0
End IF

End Select
End Sub

But that doesn't really process the next value in the buffer does it?

I've never used VB before so I'm finding it pretty confusing

Thanks,
Niamh
 
Well you must access the com object in a loop in order to get the next value after 230 in the buffer.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top