/// <summary> /// Reads an integer value from the specified port. The value of the port can /// be a number from0 to 7. /// </summary> /// <param name="port">An integer specifying the port to read from. This is /// a value from 0 to 7.</param> /// <returns>The integer value of the specified port.</returns> public Mcp3008Reading Read(IChannel channel) { Mcp3008Reading returnValue = new Mcp3008Reading(0); if (this.Device != null) { // *** // *** Setup the read buffer // *** byte[] readBuffer = new byte[3]; // *** // *** Set up the write buffer // *** byte[] writeBuffer = new byte[3] { (byte)channel.InputConfiguration, (byte)(channel.Id + 8 << 4), 0x00 }; // *** // *** Send and receive the data // *** this.Device.TransferFullDuplex(writeBuffer, readBuffer); // *** // *** Convert the data // *** returnValue.RawValue = ((readBuffer[1] & 3) << 8) + readBuffer[2]; } else { throw new NotInitializedException(); } return(returnValue); }
/// <summary> /// Reads an integer value from the specified port. The value of the port can /// be a number from0 to 7. /// </summary> /// <param name="port">An integer specifying the port to read from. This is /// a value from 0 to 7.</param> /// <returns>The integer value of the specified port.</returns> public Mcp3008Reading Read(IChannel channel) { Mcp3008Reading returnValue = new Mcp3008Reading(0); if (this.Device != null) { // *** // *** Setup the read buffer // *** byte[] readBuffer = new byte[3]; // *** // *** Set up the write buffer // *** byte[] writeBuffer = new byte[3] { (byte)channel.InputConfiguration, (byte)(channel.Id + 8 << 4), 0x00 }; // *** // *** Send and receive the data // *** this.Device.TransferFullDuplex(writeBuffer, readBuffer); // *** // *** Convert the data // *** returnValue.RawValue = ((readBuffer[1] & 3) << 8) + readBuffer[2]; } else { throw new NotInitializedException(); } return returnValue; }