[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

How to send data to COM port using VB

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.
1 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.

nirmal_4194Author Commented:
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.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now