FEZ Raptor: missing a using directive or an assembly reference?

Hardware: FEZ Raptor
SDK: 4.3

I am attempting to use Ascended Temperature MCP9701(https://www.ghielectronics.com/community/codeshare/entry/81) in my project, but I am running into these two errors:

and

tempSensor.cs code:

//           Ascended International
//
//             Copyright (c) 2010
//
//            All Rights Reserved
// ------------------------------------------------------------------------------
//    * DO NOT REMOVE THIS HEADER. DO NOT MODIFY THIS HEADER *
/**********************************************************************************
 * You may use this class for non-commercial purposes. If you wish to use this    *
 * software for a commercial purpose please contact Ascended International at:    *
 * mark@ ascended.com.au                                                           *
 *                                                                                *
 * When using this free class, no warranty express or implied is offered.         *
 * In no event shall Ascended International, any of it's employees or shareholders*
 * be held liable for any direct, indirect, special, exemplary, incidental or     *
 * consequential damages however caused.                                          *
 *                                                                                *
 * If you modify this class, please add your name and the date below as a         *
 * contributor, without removing this notice or modifying it in any way, shape    *
 * or form.                                                                       *
 **********************************************************************************/
using System;
using Microsoft.SPOT.Hardware;

 #if NETDUINO  
using SecretLabs.NETMF.Hardware;  
 #else
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.System;
 #endif

namespace Ascended.SPOT.Sensors.Temperature
{
    public interface ITemperatureSensor : IDisposable
    {
        float GetTemperatureInC();
        float GetTemperatureInF();

        int MaximumTemperatureCapability { get; }
        int MinimumTemperatureCapability { get; }
    }

    public class MCP9701 : ITemperatureSensor
    {
 #if NETDUINO  
        protected AnalogInput sensor;  
 #else
        protected AnalogIn sensor;
 #endif

        /// <summary>  
        /// Create a new base instance of the temperature sensor.  
        /// </summary>  
        /// <param name="pin">Pin the sensor's vout is connected to.  
        public MCP9701(Cpu.Pin pin)
        {
            // http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en022289
            MaximumTemperatureCapability = 125;
            MinimumTemperatureCapability = -40;
            RequiredVoltage = 2.7f;

 #if NETDUINO  
            sensor = new AnalogInput(pin);  
            sensor.SetRange(0, 3300);  
 #else
            sensor = new AnalogIn((AnalogIn.Pin)pin);
            sensor.SetLinearScale(0, 3300);
 #endif
        }

        public float GetTemperatureInC()
        {
            // gain = 19.53 mV/Deg C  
            int mv = sensor.Read() - 400; // 400 = 0c  

            return mv / 19.53f;
        }

        public float GetTemperatureInF()
        {
            return GetTemperatureInC() * 9 / 5 + 32;
        }

        public int MaximumTemperatureCapability { get; protected set; }

        public int MinimumTemperatureCapability { get; protected set; }

        public float RequiredVoltage { get; protected set; }

        public void Dispose()
        {
            sensor.Dispose();
            sensor = null;
        }

    }
}

Program.cs code:

using System;
using System.Collections;
using System.Text;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using Microsoft.SPOT.Hardware;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using Gadgeteer.SocketInterfaces;
using GHIElectronics.NETMF.Hardware;

using Ascended.SPOT.Sensors.Temperature;

namespace iog
{
    public partial class Program
    {
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            Mainboard.SetDebugLED(true);
            this.usbSerial.Configure(9600, SerialParity.None, SerialStopBits.One, 8, HardwareFlowControl.NotRequired);
            this.usbSerial.Port.NewLine = "\r";

            this.usbSerial.Port.LineReceived += this.Port_lineReceived;

        }

        private void Port_lineReceived(Serial sender, string line)
        {
            /*Demo usbSerial communication to test I/O data which works :-)*/
            Debug.Print(line);
            if (line == "Off") Mainboard.SetDebugLED(false);
            else if (line == "On") Mainboard.SetDebugLED(true);
            /*End usbSerial Demo*/
            
            /*Now get MCP9701 value and send the value  usbSerial*/
            using (ITemperatureSensor sensor = new MCP9701((Cpu.Pin)AnalogIn.Pin.Ain0))
            {
                while (true)
                {
                    Debug.Print("Temperature: " + sensor.GetTemperatureInC() + "c");
                    Thread.Sleep(1000);
                }
            }
            
        }
    }
}

Errors:

[quote]Error 1 The type or namespace name ‘NETMF’ does not exist in the namespace ‘GHIElectronics’ (are you missing an assembly reference?)

C:\Users\Rich\documents\visual studio 2012\Projects\iog\iog\tempSensor.cs 28 22 iog
Error 2 The type or namespace name ‘NETMF’ does not exist in the namespace ‘GHIElectronics’ (are you missing an assembly reference?)

C:\Users\Rich\documents\visual studio 2012\Projects\iog\iog\tempSensor.cs 29 22 iog
Error 3 The type or namespace name ‘AnalogIn’ could not be found (are you missing a using directive or an assembly reference?)

C:\Users\Rich\documents\visual studio 2012\Projects\iog\iog\tempSensor.cs 48 19 iog
Error 4 The type or namespace name ‘AnalogIn’ could not be found (are you missing a using directive or an assembly reference?)

C:\Users\Rich\documents\visual studio 2012\Projects\iog\iog\tempSensor.cs 66 26 iog
Error 5 The type or namespace name ‘AnalogIn’ could not be found (are you missing a using directive or an assembly reference?)

C:\Users\Rich\documents\visual studio 2012\Projects\iog\iog\tempSensor.cs 66 36 iog
Error 6 The type or namespace name ‘NETMF’ does not exist in the namespace ‘GHIElectronics’ (are you missing an assembly reference?)

C:\Users\Rich\documents\visual studio 2012\Projects\iog\iog\Program.cs 19 22 iog
Error 7 The name ‘AnalogIn’ does not exist in the current context C:\Users\Rich\documents\visual studio 2012\Projects\iog\iog\Program.cs 47 69 iog[/quote]

I attached an image of my included References.

Namespaces changed between versions. I would remove the namespace in question and resolve “unknown” classes by looking them in the latest GHI SDK.

1 Like

Does removing unused references or like “using …” statements make any performance improvements? Why not have ALL of the references at once?

1 Like

The only negative of having unused assemblies/references included is slightly slower compile time… and maybe any other programmer looking at your code wondering “why did he include that?”

@ Architec
I read through the 4.3 API and I was needing to use AnalogInput not Analogin. I changed some of the code in the tempSensor.cs class in an attempt to get the class to work with 4.3. I now have two more errors.

I know SetLinearScale isn’t a method and I can’t use Scale because Scale is a non-invocable member and cannot be used as a method. As far as the second error, I have no idea what that means or what a ‘cast’ has to do with this. I still have a lot to learn with C#.

[quote]The new errors that I am receiving are:
Error 1 ‘Microsoft.SPOT.Hardware.AnalogInput’ does not contain a definition for ‘SetLinearScale’ and no extension method ‘SetLinearScale’ accepting a first argument of type ‘Microsoft.SPOT.Hardware.AnalogInput’ could be found (are you missing a using directive or an assembly reference?) C:\Users\Rich\Documents\Visual Studio 2012\Projects\iog\iog\tempSensor.cs 55 20 iog

Error 2 Cannot implicitly convert type ‘double’ to ‘int’. An explicit conversion exists (are you missing a cast?) C:\Users\Rich\Documents\Visual Studio 2012\Projects\iog\iog\tempSensor.cs 61 22 iog
[/quote]

tempSensor.cs:

//           Ascended International
//
//             Copyright (c) 2010
//
//            All Rights Reserved
// ------------------------------------------------------------------------------
//    * DO NOT REMOVE THIS HEADER. DO NOT MODIFY THIS HEADER *
/**********************************************************************************
 * You may use this class for non-commercial purposes. If you wish to use this    *
 * software for a commercial purpose please contact Ascended International at:    *
 * mark@ ascended.com.au                                                           *
 *                                                                                *
 * When using this free class, no warranty express or implied is offered.         *
 * In no event shall Ascended International, any of it's employees or shareholders*
 * be held liable for any direct, indirect, special, exemplary, incidental or     *
 * consequential damages however caused.                                          *
 *                                                                                *
 * If you modify this class, please add your name and the date below as a         *
 * contributor, without removing this notice or modifying it in any way, shape    *
 * or form.                                                                       *
 **********************************************************************************/
using System;
using Microsoft.SPOT.Hardware;

namespace Ascended.SPOT.Sensors.Temperature
{
    public interface ITemperatureSensor : IDisposable
    {
        float GetTemperatureInC();
        float GetTemperatureInF();

        int MaximumTemperatureCapability { get; }
        int MinimumTemperatureCapability { get; }
    }

    public class MCP9701 : ITemperatureSensor
    {
        protected AnalogInput sensor;

        /// <summary>  
        /// Create a new base instance of the temperature sensor.  
        /// </summary>  
        /// <param name="pin">Pin the sensor's vout is connected to.  
        public MCP9701(Cpu.AnalogChannel pin)
        //public MCP9701(Cpu.Pin pin)
        {
            // http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en022289
            MaximumTemperatureCapability = 125;
            MinimumTemperatureCapability = -40;
            RequiredVoltage = 2.7f;

            //sensor = new AnalogInput((AnalogInput.Pin)pin);
            sensor = new AnalogInput(pin);
            //sensor.Scale(0, 3300);
            sensor.SetLinearScale(0, 3300);
        }

        public float GetTemperatureInC()
        {
            // gain = 19.53 mV/Deg C  
            int mv = sensor.Read() - 400; // 400 = 0c  

            return mv / 19.53f;
        }

        public float GetTemperatureInF()
        {
            return GetTemperatureInC() * 9 / 5 + 32;
        }

        public int MaximumTemperatureCapability { get; protected set; }

        public int MinimumTemperatureCapability { get; protected set; }

        public float RequiredVoltage { get; protected set; }

        public void Dispose()
        {
            sensor.Dispose();
            sensor = null;
        }

    }
}

I researched a bit to find out what a ‘cast’ is. To my understanding a cast has to be used to convert a double to int. So I did:



That fix the casting issue.  One more error that I need to fix:

[quote]Error	1	'Microsoft.SPOT.Hardware.AnalogInput' does not contain a definition for 'SetLinearScale' and no extension method 'SetLinearScale' accepting a first argument of type 'Microsoft.SPOT.Hardware.AnalogInput' could be found (are you missing a using directive or an assembly reference?)	C:\Users\Rich\Documents\Visual Studio 2012\Projects\iog\iog\tempSensor.cs	56	20	iog[/quote]

That error points to:

```cs]sensor.SetLinearScale(0, 3300);[/code



I am still stuck on that and I have no idea what to do to fix it :/

Set Linear Scale simply “converted” an integer number (the return of the RAW ADC value) into a number that has a different lower and upper bound. In this case it was scaling the (most likely 10-bit) number instead of going from 0 to 1023 (10 bits - may be different depending on your hardware) to run from 0 to 3300. You can do this in maths yourself.

1 Like

Here’s an old post from @ Godefroi with a simple maths example https://www.ghielectronics.com/community/forum/topic?id=7832 and an alternative to scaling (since Read() already is a 0 to 1 scaled output)

1 Like