title: RS232 transmitted packet mismatch
body: <p>I am trying to figure out why a simple RS232 transmission doesn't work. As shown in <a href="https://i.stack.imgur.com/vXKoh.png" rel="nofollow noreferrer">this</a> picture, I'm running a debugger to view the data values to be transmitted. The problem is that the bytes sent and received are completely different. I have no idea what is wrong here. Please let me know if anybody needs more info.</p>
  
  <p>Here is the code segment:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.IO.Ports;
  
  namespace ShimmerAPI
  {
      class Transmission
      {
          const short multiplier = -1020; // 10000/-9.81
  
          byte[] Combine (byte[] a0, byte[] a1, byte[] a2)
          {
              byte[] ret = new byte[a0.Length + a1.Length + a2.Length];
              Array.Copy(a0, 0, ret, 0, a0.Length);
              Array.Copy(a1, 0, ret, a0.Length, a1.Length);
              Array.Copy(a2, 0, ret, a0.Length + a1.Length, a2.Length);
              return ret;
          }
  
          short Multiply (double x)
          {
              if (x &gt; 25 || x &lt; -25)
                  return 0;
              else
                  return Convert.ToInt16(x * multiplier);
          }
  
          public void TransmitData (SerialPort port, ObjectCluster obj)
          {
              double[] data = obj.GetData().ToArray();
  
              short X = Multiply(data[3]);
              short Y = Multiply(data[5]);
              short Z = Multiply(data[7]);
  
              byte[] combBytes = Combine(BitConverter.GetBytes(Z), BitConverter.GetBytes(Y), BitConverter.GetBytes(X));
  
              port.Write(combBytes, 0, 1);
          }
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/vXKoh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vXKoh.png" alt="screenshot of data capture and code"></a></p>