private bool WriteCommandToOutputBuffer(OutCmd command)
        {
            byte[] outputBuffer = new byte[MyHid.Capabilities.OutputReportByteLength];

            outputBuffer[0] = 0;
            outputBuffer[1] = Convert.ToByte(command);
            outputBuffer[2] = 0;
            Write(ref outputBuffer);

            Hid.OutputReportViaInterruptTransfer outputReport = new Hid.OutputReportViaInterruptTransfer();
            return(outputReport.Write(outputBuffer, writeHandle));
        }
        private bool Write(ref byte[] outputBuffer)
        {
            bool success = false;

            try
            {
                // Check write handle
                if (!writeHandle.IsInvalid)
                {
                    if (MyHid.Capabilities.OutputReportByteLength > 0)
                    {
                        Hid.OutputReportViaInterruptTransfer outputReport = new Hid.OutputReportViaInterruptTransfer();
                        success = outputReport.Write(outputBuffer, writeHandle);

                        if (!success)
                        {
                            //response.responseInfo.Add("Write to colorimeter failed.");
                        }
                    }
                    else
                    {
                        //response.responseInfo.Add("This HID device doesn't have an Output report.");
                    }
                }
                else
                {
                    //response.responseInfo.Add("Invalid write handle.");
                }

                return(success);
            }
            catch (Exception ex)
            {
                //response.responseInfo.Add($"Colorimeter.Write() {ex}");
                throw;
            }
        }
        //This method is used for the cases where a single response packet will be enough to contain the results, and we will not have to iterate through a large amount of data
        private string GetSinglePacketResponse(OutCmd outCommand)
        {
            try
            {
                ////build command to send buffer
                byte[] outputBuffer = new byte[MyHid.Capabilities.OutputReportByteLength];
                outputBuffer[0] = 0;
                outputBuffer[1] = Convert.ToByte(outCommand);//the value of the query firmware state
                outputBuffer[2] = 0;


                //Write command to buffer
                Hid.OutputReportViaInterruptTransfer outputReport = new Hid.OutputReportViaInterruptTransfer();
                if (!outputReport.Write(outputBuffer, writeHandle))
                {
                    //Failure writing to the report
                    throw new Exception();
                }


                //Read from the input report
                bool deviceConnected = true;
                bool success         = false;

                Hid.InputReportViaInterruptTransfer myInputReport = new Hid.InputReportViaInterruptTransfer();
                myInputReport.Read(hidHandle, readHandle, writeHandle, ref deviceConnected, ref inputBuffer, ref success);

                if (!success)
                {
                    //failure reading from the report
                    throw new Exception();
                }


                InputReportReceived(ref inputBuffer, success);
                newInputData = true;


                if (outCommand.Equals(OutCmd.SendFwVers) || outCommand.Equals(OutCmd.SendTestFileVers))
                {
                    //Both of these types of queries return the same type of packet, an encoded string
                    return(Encoding.GetEncoding("iso-8859-1").GetString(inputBuffer, 3, inputBuffer[2]));
                }

                if (outCommand.Equals(OutCmd.QueryFirmwareState))
                {
                    switch ((InCmd)inputBuffer[1])
                    {
                    case InCmd.BootloaderRunning:
                        return("BootloaderRunning");

                    case InCmd.MainFwRunning:
                        return("MainFwRunning");

                    default:
                        return("Unknown");
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(null);
        }