Пример #1
0
        /// <summary>
        /// Executes a command against the PlasmaTrim device.
        /// </summary>
        /// <param name="command">The command to execute.</param>
        /// <param name="data">The data payload.</param>
        private void SendCommand(PlasmaTrimCommand command, byte[] data = null)
        {
            // Make sure we're connected to the device.
            if (!this.Device.IsOpen)
            {
                throw new InvalidOperationException("PlasmaTrim device is not connected!");
            }

            byte[] commandData = new byte[33];

            // Index 1 is the command we want to send.
            commandData[1] = (byte)command;

            // Copy the data into our command array.
            if (data != null)
            {
                data.CopyTo(commandData, 2);
            }

            // Actually send the command.
            if (!this.Device.Write(commandData))
            {
                throw new Exception("Unable to send command to PlasmaTrim device!");
            }
        }
Пример #2
0
        /// <summary>
        /// Executes a command and then returns the returned data.
        /// </summary>
        /// <param name="command">The command to execute.</param>
        /// <param name="data">The data payload.</param>
        ///         /// <returns>The output of the command</returns>
        private byte[] QueryDevice(PlasmaTrimCommand command, byte[] data = null)
        {
            // Send the command to the device.
            SendCommand(command, data);

            // Now, query the device for output and return it.
            return(this.Device.ReadReport(1).Data);
        }