예제 #1
0
 //-------------------------------------------------------------------------------------------------------------------------------------------
 private void SendResponse(byte command_byte, byte[] buffer, ushort value)
 {
     char[] value_array = NumberConversions.ShortToCharArray(value);
     byte[] response    = new byte[] { (byte)(command_byte + 0x10), buffer[1], buffer[2], (byte)value_array[0], (byte)value_array[1], (byte)value_array[2], (byte)value_array[3] };
     Debug.Print("Sending response: ");
     NumberConversions.PrintByteArray(response);
     _port.Write(response, 0, response.Length);
 }
예제 #2
0
        //-------------------------------------------------------------------------------------------------------------------------------------------
        private void SendResponse(byte command_byte, byte[] buffer, ushort[] value)
        {
            int value_length = value.Length;

            byte[] response = new byte[3 + value_length * 4 + 1]; // need to create extra space since each byte is broken up into high and low nibbles for high and low bytes, plus 1 for null terminator
            response[0] = (byte)(command_byte + 0x10);
            response[1] = buffer[1];
            response[2] = buffer[2];

            for (int i = 0; i < value_length; i++)
            {
                char[] element_nibbles = NumberConversions.ShortToCharArray(value[i]);
                response[3 + (i * 4)]     = (byte)element_nibbles[0];
                response[3 + (i * 4) + 1] = (byte)element_nibbles[1];
                response[3 + (i * 4) + 2] = (byte)element_nibbles[2];
                response[3 + (i * 4) + 4] = (byte)element_nibbles[3];
            }

            Debug.Print("Sending response: ");
            NumberConversions.PrintByteArray(response);
            _port.Write(response, 0, response.Length);
        }