Hi All,

Using C# and .NET 2.0 on WindowsXP SP3.

I am trying to send a command to a device on a IP and Port and then
get a response.

I can successfully communicate with the device using Hyper terminal.

I have created a text file with the command that I use <ESC>B<ENQ>
then used the Send Text file option and I get the response that I
expect back.

When using the code below I simply get no response at all and it hangs
on the stream.Read method call.

Any ideas will be a appreciated.
Thanks in advance.

----
              String cmd = Char.ConvertFromUtf32(5);
              cmd += Char.ConvertFromUtf32(66);
              cmd += Char.ConvertFromUtf32(27);

              TcpClient client = new TcpClient("192.168.5.80", 6001);

              Byte[] data = System.Text.Encoding.ASCII.GetBytes(cmd);

              NetworkStream stream = client.GetStream();

              // Send the message to the connected TcpServer.
              stream.Write(data, 0, data.Length);

              Console.WriteLine("Sent: {0}", cmd);


              // Buffer to store the response bytes.
              data = new Byte[100];

              // String to store the response ASCII representation.
              String responseData = String.Empty;

              // Read the first batch of the TcpServer response bytes.
              Int32 bytes = stream.Read(data, 0, data.Length);

              responseData = System.Text.Encoding.ASCII.GetString
(data, 0, bytes);
              Console.WriteLine("Received: {0}", responseData);

              // Close everything.
              stream.Close();
              client.Close();


Reply via email to