Possible Duplicate:
C# serialport and hyperterminal
Problem
I'm having trouble with my serial connection. I can send data to my device, but I can't read data. If I use Hyperterm, everyting work fine - I see the data coming in and going out.
Using my code, however, my serial port object never receives any data, but data I send is received by the device.
Any ideas?
Project Info:
- WPF
- .NET 3.5 (not the Client Profile version)
- Developing on Windows 7
- Visual Studio 2010
- DA-15 serial to USB
Hyperterm settings:
- COM20
- Bits per second: 115200
- Data bits: 8
- Parity: None
- Stop bits: 1
- Flow control: None
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:
I noted it above, but just to make sure everyone knows, I am using a USB to Serial Port cable. I don't think this is the issue because it works on Hyperterm, but just in case.