1
Reply

How do I read data from USB Virtual COM in C#?

naouf gyd

naouf gyd

Dec 23 2015 10:41 AM
651
I searched for a solution on the internet but no luck.

I am using windows form with Serial Port control and richTextBox. I am trying to read the phone number from caller ID device (CTI comet caller ID) which decodes the Caller's telephone number from the telephone line and presenting it on a virtual COM5 Port of my PC because the Caller ID is a COM device.

The caller ID is connected to my PC via USB to COM Adapter because my PC doesn't have physical COM ports. Also the USB to COM Adapter driver is installed well .Note that the telephone line supports the caller ID feature.

When the phone rings the phone number should show up in richTextBox, I tried the following code but nothing happens (phone number did not appear) Am I missing something?.

My question:

How can I read data from virtual COM5 port in C#? Please help me to modify this code to make it work. Thank you
 
 
public partial class Form1 : Form  
   {       public  SerialPort mySerialPort = new SerialPort("COM5");      
 public Form1()  
   {         InitializeComponent();       
    mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataR);     
    mySerialPort.Open();    
  }      

 public void DataR(object sender, SerialDataReceivedEventArgs e)    
   {           if (richTextBox1.InvokeRequired)        
          {     richTextBox1.Invoke(new SerialDataReceivedEventHandler(DataR), sender, e);      
    }           
 else         
 {              
 richTextBox1.AppendText(mySerialPort.ReadExisting()); //recieve data in real time.       
     }      
 }       
 private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)   
  {       } 
}
 

Answers (1)