after a while I decided to start playing with Raspberry Pi2 and FEZ Cream, I know FEZ Cream is no longer supported, but I won’t throw it away yet .
I wanted to try to setup a device using SerialDevice but I got an exception:
Exception thrown: 'System.ArgumentOutOfRangeException' in System.Private.CoreLib.ni.dll
Exception thrown: 'System.ArgumentOutOfRangeException' in Ph Sensor Test.exe
Exception thrown: 'System.ArgumentOutOfRangeException' in System.Private.CoreLib.ni.dll
Specified argument was out of the range of valid values.
Parameter name: index
code, where it happened:
protected async override Task Initialize(ISocket parentSocket)
{
parentSocket.EnsureTypeIsSupported(SocketType.U);
pinX = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Three, false);
pinY = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Six, false);
serial = await parentSocket.CreateSerialDeviceAsync(); //exception is thrown here
}
Could you please advise, what’s happening or what did I do wrong or forgot to do?
at System.Runtime.InteropServices.WindowsRuntime.IVectorViewToIReadOnlyListAdapter.Indexer_Get[T](Int32 index)
at GHIElectronics.UWP.GadgeteerCore.NativeInterfaces.SerialDevice.<CreateInterfaceAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at GHIElectronics.UWP.GadgeteerCore.Socket.<CreateSerialDeviceAsync>d__59.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Ph_Sensor_Test.PhSensorTest.<Initialize>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at GHIElectronics.UWP.GadgeteerCore.Module.<CreateAsync>d__16`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Ph_Sensor_Test.MainPage.<Setup>d__3.MoveNext()
This is actually the only code I have in the project, because I just wanted to test UART.
using GHIElectronics.UWP.GadgeteerCore;
using System.Text;
using System.Threading.Tasks;
using SI = GHIElectronics.UWP.GadgeteerCore.SocketInterfaces;
namespace Ph_Sensor_Test
{
public class PhSensor : Module
{
private SI.SerialDevice serial;
private SI.DigitalIO pinX;
private SI.DigitalIO pinY;
public override string Name => "";
public override string Manufacturer => "";
protected async override Task Initialize(ISocket parentSocket)
{
parentSocket.EnsureTypeIsSupported(SocketType.U);
pinX = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Three, false);
pinY = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Six, false);
serial = await parentSocket.CreateSerialDeviceAsync(); //throws exception here
}
public void SendQuery()
{
serial.Write(Encoding.UTF8.GetBytes("status\r"));
}
}
}
and it’s used in MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using GHIElectronics.UWP.Gadgeteer.Mainboards;
using GHIElectronics.UWP.GadgeteerCore;
using System.Diagnostics;
namespace Ph_Sensor_Test
{
public sealed partial class MainPage : Page
{
private FEZCream mainboard;
private PhSensor phSensor;
public MainPage()
{
InitializeComponent();
Setup();
}
private async void Setup()
{
mainboard = await Module.CreateAsync<FEZCream>();
try
{
phSensor = await Module.CreateAsync<PhSensor>(mainboard.GetProvidedSocket(2));
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
phSensor.SendQuery();
Output.Text = "Query sent.";
}
}
}
I have considered that, but I don’t know, how I can install older version. IoT Dashboard doesn’t let me choose any older version than 15063.
I’m going to try Insider preview (16267) and will report back.
Specified argument was out of the range of valid values.
Parameter name: index
StackTrace:
at System.Runtime.InteropServices.WindowsRuntime.IVectorViewToIReadOnlyListAdapter.Indexer_Get[T](Int32 index)
at GHIElectronics.UWP.GadgeteerCore.NativeInterfaces.SerialDevice.d__18.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at GHIElectronics.UWP.GadgeteerCore.Socket.d__59.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at GHIElectronics.UWP.Gadgeteer.Modules.Breakout.d__13.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Ph_Sensor_Test.MainPage.d__4.MoveNext()
code:
public sealed partial class MainPage : Page
{
private FEZCream mainboard;
private PhSensor phSensor;
private Breakout breakout;
Since the Breakout fails too, it seems like something changed in one of the latest IoT Core releases that broke the Gadgeteering code. You can always get the code from its GitHub and take a look.