Exemplo n.º 1
0
		private async Task UpdateUI(Mcp3008Reading reference, Mcp3008Reading reading, float adjustedReading)
		{
			if (this.Dispatcher != null)
			{
				await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
				{
					// ***
					// *** Update the sensor reading
					// ***
					this.SensorReading = adjustedReading;

					// ***
					// *** Update the dashboard values
					// ***
					this.RawSensorDisplayValue = reading.RawValue.ToString();
					this.RawReferenceDisplayValue = reference.RawValue.ToString();
					this.NormalizedSensorReadingDisplayValue = reading.NormalizedValue.ToString("0.000");
					this.AdjustedSensorReadingDisplayValue = adjustedReading.ToString("0.000");
					this.StabilityDisplayValue = string.Format("{0:0.000}", _stabilityMeter.Stability);
				});
			}
		}
Exemplo n.º 2
0
		/// <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(Channel channel)
		{
			Mcp3008Reading returnValue = new Mcp3008Reading(0);

			if (_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
				// ***
				_device.TransferFullDuplex(writeBuffer, readBuffer);

				// ***
				// *** Convert the data
				// ***
				returnValue.RawValue = ((readBuffer[1] & 3) << 8) + readBuffer[2];
			}
			else
			{
				throw new NotInitializedException();
			}

			return returnValue;
		}