How to send data to COM port using VB

Posted on 2004-11-03
Last Modified: 2010-05-02
Hello all,
i need a sample code to send text on COM Port. I am doing a project on Bank and need to display current token no on Display board which is connected to my CPU on COM1 port.

Thanks in advance.
Question by:nirmal_4194
    LVL 48

    Accepted Solution


    Initializing and Opening the Com port

    Create an instance of CRs232 then set COM parameters before invoking the Open method
    Here's an example:
    Dim moRS232 as New Rs232()
    With moRs232
               .Port = 1                                                      '// Uses COM1
               .BaudRate = 2400                                        ' // 2400 baud rate
               .DataBit = 8                                                 ‘// 8 data bits                                                  
               .StopBit = Rs232.DataStopBit.StopBit_1         '// 1 Stop bit
               .Parity = Rs232.DataParity.Parity_None           '// No Parity
               .Timeout = 500                                             '// 500 ms of timeout admitted to get all required bytes
    End With
    '// Initializes and Open
    moRS232.Open ()
    You can, optionally control the state of DTR/RTS lines after the Port is open
      '// Set state of RTS / DTS
    moRS232.Dtr = True
    moRS232.Rts = True

    In case of an error/problems an exception is raised, so i suggest you to enclose the code within a Try...Catch block.

    Transmitting data to COM Port
    The class has 2 buffers one for Tx and one for Rx, to transmit data just set the TxData property with the informations you wish to send then invoke the Tx method.

    LVL 28

    Expert Comment


    Author Comment

    hi Mikal613  feedback

    thanks for your coding.

    i could not able to find the reference of Rs232. Can you tell me what reference or controls i need to add in my project to use this code.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now