Main Site Documentation

Exception AnalogInput 4.3


#1

I am currently trying to migrate the weather station project to a Cobra II with wifi and get this exception when I do a analogRead?

Code is below exception? I assume I am not declaring correctly?

Measurement Start
#### Exception System.ArgumentException - 0x00000000 (1) ####
#### Message:
#### Microsoft.SPOT.Hardware.AnalogInput::.ctor [IP: 0076] ####
#### Gadgeteer.SocketInterfaces.NativeAnalogInput::set_IsActive [IP: 002e] ####

Gadgeteer.SocketInterfaces.NativeAnalogInput::ReadVoltage [IP: 0005]

#### wifi.Program::measurementTimer_Tick [IP: 0014] ####
#### Microsoft.SPOT.DispatcherTimer::FireTick [IP: 0010] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 001d] ####

A first chance exception of type ‘System.ArgumentException’ occurred in Microsoft.SPOT.Hardware.dll
Exception performing Timer operation
Network availability: True
LinkedConnected: True
Network Availability Changed IP Address = 0.0.0.0

CODE:

Variables
GT.SocketInterfaces.AnalogInput windDirection;

SetupPeripherals
windDirection = extender_Four.CreateAnalogInput(GT.Socket.Pin.Five); extender_Four is plugged into a socket with AIT ‘A for analog I hope’ I assume this is not the correct method for 4.3? Or declared correctly?

private void ProcessMeasurements()
{
double dir = windDirection.ReadVoltage(); and it bombs on this line?


#2

@ Robert24 - Looks like it’s a bug in our driver. It’ll be fixed in a coming SDK. In the mean time, you can work around it like this:


using Microsoft.SPOT;
using GT = Gadgeteer;

namespace GadgeteerApp1
{
    public partial class Program
    {
        GT.SocketInterfaces.AnalogInput ain;
        GT.Timer timer;

        void ProgramStarted()
        {
            var extenderSocket = GT.Socket.GetSocket(this.extender.ExtenderSocketB, true, null, null);

            GT.Socket.SocketInterfaces.SetAnalogInputFactors(extenderSocket, 3.3, 0, -1);

            this.ain = this.extender.CreateAnalogInput(GT.Socket.Pin.Five);

            this.timer = new GT.Timer(250);
            this.timer.Tick += this.ProcessMeasurements;
            this.timer.Start();
        }

        private void ProcessMeasurements(object a)
        {
            Debug.Print(this.ain.ReadVoltage().ToString());
        }
    }
}


#3

Thanks, I have already removed the extender and coding to a breakout board and now I am getting values …