title: Sending CMD to PLC via TCP Client
body: <p>I'm trying to send a command to a PLC that controls electronic lockers via a TCP Client. I am able to connect but it <strong>appears my command is not being read</strong> by the PLC.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>        private const string STX = "0x02";
          private const string ETX = "0x03";
          private const string STATUS = "0x30";
          private const string OPEN = "0x31";
          private const string SUM = STX + ETX;
  
          static void Main(string[] args)
          {
              var tcpClient = new TcpClient();
              tcpClient.Connect("192.168.1.190", 4000);
  
              if (tcpClient.Connected)
              {
                  var networkStream = tcpClient.GetStream();
                  if (networkStream.CanWrite)
                  {
                      var ADDY = "00";
                      var asciiEncode = new ASCIIEncoding();
                      byte[] b = asciiEncode.GetBytes(STX + ADDY + OPEN + ETX + SUM);
                      networkStream.Write(b, 0, b.Length);
                      byte[] b1 = new byte[100];
                      var k = networkStream.Read(b1, 0, 100);
                      for (var i = 0; i &lt; k; i++)
                      {
                          Console.WriteLine(Convert.ToChar(b1[i]));
                      }
                  }
              }
          }
  </code></pre>
  
  <p>STATUS/OPEN are the commands that can be sent. The PLC came with some documentation and here is a <a href="https://i.stack.imgur.com/OQwTQ.png" rel="nofollow noreferrer">picture</a> of it. I assuming my CMD is wrong, how do I fix it? This is my first time trying to connect to and send/retrieve commands from a PLC. Any help is appreciated.</p>