May send / Cannot read .NET serial port

Possible duplicate:
C # serialport and hyperterminal

Problem

I'm having problems with my serial connection. I can send data to my device, but I can not read the data. If I use Hyperterm, everything works fine - I see that the data is coming in and out.

However, using my code, my serial port object never receives any data, but the data that I send is accepted by the device.

Any ideas?

Project Information:

  • WPF
  • .NET 3.5 (not client profile version)
  • Windows 7 Development
  • Visual studio 2010
  • DA-15 serial number to USB

Hyperterm Settings:

  • COM20
  • Bits per second: 115200
  • Data Bits: 8
  • Value: no
  • Stop bits: 1
  • Flow control: no

C # code:

SerialPort serial = new SerialPort();

serial.PortName = "COM20";
serial.BaudRate = 115200;
serial.DataBits = 8;
serial.Parity = Parity.None;
serial.StopBits = StopBits.One;
serial.Handshake = Handshake.None;

serial.Open();
serial.Write("Hello World\r\n");    // Echoed on device screen

while (0 == serial.BytesToRead)     // Never receive a response
    System.Threading.Thread.Sleep(100);

char[] first = new char[serial.BytesToRead];
serial.Read(first, 0, first.Length);

Edit:

, , , , USB . , , Hyperterm, .

+5
1
+4

All Articles