Welcome to Dream.In.Code
Become a VB Expert!

Join 137,233 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,739 people online right now. Registration is fast and FREE... Join Now!




MSComm control

 
Reply to this topicStart new topic

MSComm control

cathy
2 Mar, 2007 - 06:25 AM
Post #1

New D.I.C Head
*

Joined: 21 Feb, 2007
Posts: 9


My Contributions
I have some microcontroller that has some data in its memory. I need to read this data through the serial port using an application and display it. I tried doing this in VB using the MSComm control and the following code

CODE

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Fire Rx Event Every Two Bytes
        MSComm1.RThreshold = 2

        ' When Inputting Data, Input 2 Bytes at a time
        MSComm1.InputLen = 2

        ' 2400 Baud, No Parity, 8 Data Bits, 1 Stop Bit
        MSComm1.Settings = "1200,N,8,2"
        ' Disable DTR
        MSComm1.DTREnable = False

        ' Open COM1
        MSComm1.CommPort = 1
        MSComm1.PortOpen = True

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MSComm1.PortOpen = False
    End Sub

    Private Sub MSComm1_OnComm(ByVal sender As Object, ByVal e As System.EventArgs) Handles MSComm1.OnComm
        Dim sData As String ' Holds our incoming data
        Dim lHighByte As Long   ' Holds HighByte value
        Dim lLowByte As Long    ' Holds LowByte value
        Dim lWord As Long       ' Holds the Word result

        ' If comEvReceive Event then get data and display
        If MSComm1.CommEvent = comEvReceive Then

            sData = MSComm1.Input ' Get data (2 bytes)
            lHighByte = Asc(Mid$(sData, 1, 1)) ' get 1st byte
            lLowByte = Asc(Mid$(sData, 2, 1))  ' Get 2nd byte

            ' Combine bytes into a word
            lWord = (lHighByte * &H100) Or lLowByte

            ' Convert value to a string and display
            RichTextBox1.Text = CStr(lWord)

        End If
    End Sub
End Class





But i'm getting an error stating that comEvReceive is not declared. what should i do now?
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: MSComm Control
3 Mar, 2007 - 03:18 AM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,859



Thanked: 50 times
Dream Kudos: 550
My Contributions
Well I can't imagine what caused that...

I know the following questions can seem simple but lets make sure:

Have you added the MSComm component to your tool bar? (Mine is labeled "Microsoft Comm Control 6"). If you need to search for it it should be in the MSCOMM32.OCX file in the system32 directory.

Have you added the MSComm control to your form?

When you bring up the "Object Browser" can do you see "MSCommlib" in the libraries combo-box? If so search for "comEvReceive". If it finds anything then... try substituting comEvReceive with 2.

If when you searched for "comEvReceive" you recieved more than one then try removing any duplicate referances/ components (such as older versions of the same thing).

I am afraid that is all I can think of.

This post has been edited by NickDMax: 3 Mar, 2007 - 03:19 AM
User is offlineProfile CardPM
+Quote Post

sweetie
RE: MSComm Control
9 Mar, 2007 - 12:04 AM
Post #3

New D.I.C Head
*

Joined: 8 Mar, 2007
Posts: 1


My Contributions
hi.. i've got a similar problem.. i'm not very good in vb, so i don kno wat code to add... i hav done a vb program and linked it to a database. i need to get info from a microcontroller via rs232 and store this info (which i don kno in wat order it is recieved) store it in the database and later view it. i tried mscomm but not sure how to go abt writing the code. help please!!!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 03:47PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month