I use 2 readers .. and I do not how to find out if the connection is successful or not as I require multiple com ports for connection to the reader..

This what I have done so far ... I tried to read the card automatically ..

    Public Class Form1
        Dim Rx(20) As Byte
        Dim i As Integer
        Dim j As Integer
        Dim transmitt As Integer
        Dim WithEvents ComPort As New IO.Ports.SerialPort

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            SerialPort1.PortName = "COM1"
            SerialPort1.BaudRate = 19200
            SerialPort1.Parity = IO.Ports.Parity.None
            SerialPort1.StopBits = IO.Ports.StopBits.One
            SerialPort1.DataBits = 8

            SerialPort2.PortName = "COM2"
            SerialPort2.BaudRate = 19200
            SerialPort2.Parity = IO.Ports.Parity.None
            SerialPort2.StopBits = IO.Ports.StopBits.One
            SerialPort2.DataBits = 8


            Button1.Enabled = True
            Button2.Enabled = False
            Button3.Enabled = True
            Button4.Enabled = False

            Timer1.Interval = 10
            Timer2.Interval = 10

        End Sub

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            SerialPort1.Open()
            Timer1.Start()
            Button1.Enabled = False
            Button2.Enabled = True

            TextBox1.Text = "connected"


        End Sub

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            SerialPort1.Close()
            Timer1.Stop()
            Button1.Enabled = True
            Button2.Enabled = False

            TextBox1.Text = "disconnected"

        End Sub

        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            SerialPort2.Open()
            Timer2.Start()
            Button3.Enabled = False
            Button4.Enabled = True

            TextBox4.Text = "connected"
        End Sub

        Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
            SerialPort2.Close()
            Timer2.Stop()
            Button3.Enabled = True
            Button4.Enabled = False

            TextBox4.Text = "disconnected"
        End Sub

        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Dim InputString As String
            If SerialPort1.IsOpen > 0 Then
                InputString = SerialPort1.IsOpen

            End If
        End Sub

        Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
            Dim InputString As String
            If SerialPort2.IsOpen > 0 Then
                InputString = SerialPort2.IsOpen
            End If

        End Sub
    End Class

what if your device is assigned to com9 port and you are trying to open it on com1 and com2..for that you have to make sure what port it is, you can set it manually go to devices and printers- your device properties - port tab
or you can choose it programmatically by

IO.Ports.SerialPort.GetPortNames

I have set my device on COM1 and COM2 manually...and i have tried to run the program without the device and there is an error .. but when i connect my device it is no error .. it this situation can prove that my connection COM1 and com2 successful?

 Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        ReceivedText(SerialPort1.ReadExisting())
    End Sub

    Private Sub ReceivedText(ByVal p1 As String)
        If Me.rtbReceived1.InvokeRequired Then
            Dim x As New SetTextCallback(AddressOf ReceivedText)
            Me.Invoke(x, New Object() {(Text)})
        Else
            Me.rtbReceived1.Text &= [Text]
        End If

I try to do the same for serial port2 but receivedtext( Private Sub ReceivedText) for serialport2 not out as serialport1 .. I do not know what happened

no errors .. but, when I want to read the tag id number (id number of the post in textboxt) it did not happen ...
based on the datasheet of the device (software protocol) there are command (read, write, anttena on / off etc.) in hexadecimal form .. but I do not understand and do not know how to do coding.

Ok try this

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.PortName = "COM1"
        SerialPort1.BaudRate = 19200
        SerialPort1.Parity = IO.Ports.Parity.None
        SerialPort1.StopBits = IO.Ports.StopBits.One
        SerialPort1.DataBits = 8
    End Sub
    Private Sub DataReceived(ByVal sender As Object, _
                      ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
                      Handles SerialPort1.DataReceived
        If SerialPort1.BytesToRead > 0 Then
            Dim buff(SerialPort1.BytesToRead - 1) As Byte
            SerialPort1.Read(buff, 0, buff.Length)
            Me.BeginInvoke(New myDelegate(AddressOf SerialPortDelegate), buff)
        End If
    End Sub
    Public Delegate Sub myDelegate(ByVal buff() As Byte)
    Public Sub SerialPortDelegate(ByVal buff() As Byte)
        RichTextBox1.Text = System.Text.Encoding.ASCII.GetString(buff, 0, buff.Length)
    End Sub
End Class

still nothing...I appreciate what you have helped me so far...
this is written in the datasheet ... is there any ideas and suggestions about it.

SOFTWARE (PROTOCOL)
CR038 uses packetized UART communication. This means command/functions and results are communicated in several bytes of data with header, length, data, also checksum.

Data Packet
Transmission Rate : Default 19200.N.8.1
Data Format : HEX

Data Packet. The packet general contains header, followed by length, Node ID (CR038 ID number), function/command Code, the data or parameters, lastly the checksum, it uses XOR. The CR038 will only execute a command/function if and only if it receive whole packet of data correctly.
It must comes with 2 bytes of header 0xAA, and 0xBB, follow by 2 bytes of data length, Node ID,Function Code, Data (optional) and result of XOR. The XOR is result (1 byte) from performing exclusive OR operation from Node ID byte until last byte of Data.

This article has been dead for over six months. Start a new discussion instead.