Setting network parameters in TinyCLROS

I’ve started porting some of our old NETMF stuff to tinyCLROS but network initialization is giving me problems. I simply can’t find info on how to do it. In our old applications we use the NetworkInterface class to configure IP parameters or select dhcp. I also use SPOT to monitor changes in availability. Writing my own monitoring thread is no problem but how do i set the IP configuration?
In essence what i need to do is to get configuration from a file on SD card and set up network. What’s your sugested workflow / how would you go about to

  • find interface (is it allocated automatically like in MF4.3 so it’s enough to use GetAllIntefaces?)
  • enable DHCP
  • set static IP
  • set dns addr

It’s a custom hardware but network design was ripped of FezCobra II schematic

TinyCLR OS currently has all major features minus built-in-networking/usb-host/IFU.

However, we have wrappers for networking ready so devices with built in TCP/IP, like the WiFi module we use on FEZ, can be utilized with a common “.NET-like” interface.

Are you trying to use Ethernet?

1 Like

Yes we have a custom board based on the Fez Cobra II design as a reference. I.e G120 SoC with ENC28J60 Ethernet controller on SPI. Also uses SD card directly connected to G120.
I’m trying to move from .NETMF-4.3 to TinyCLROS
In .NET i instansiate driver from GHI library like
var eth0 = GHI.Networking.EthernetENC28J60(
SPI.SPI_module.SPI2,
G120.P1_10, // chip select
G120.P2_11, // external interrupt
G120.P1_9 // reset
);

I’m also having trouble using SD card. StorageController SDController = StorageController.GetDefault(); throws a nullpointer exception as does every “Name” that i can come up with including @“GHIElectronics.TinyCLR.NativeApis.STM32F4.SdCardStorageController\0” from your tutorial.

Unfortunately the ENC28 is not supported at this time, but additional networking support is on our roadmap.

Can you show a complete example for SD that gives you the exception? Which device are you running it on, G120?

1 Like

Yes it’s on a plain G120. As i mentioned the nullpointer exception is thrown immediately when calling StorageControler.GetDefault(). Hardware adaption class starts with:

GpioController GPIO = GpioController.GetDefault();
StorageController SDController = StorageController.GetDefault();
IDriveProvider SDDrive = null;
GpioPin SDDetect;

Exception comes in the second line

Complete test program, still throws at first line on my G120 board:

using System;
using System.Threading;
using System.Diagnostics;
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Pwm;
using GHIElectronics.TinyCLR.Pins;
using GHIElectronics.TinyCLR.Devices.Storage;
using GHIElectronics.TinyCLR.IO;

namespace TinyCLRApplication1
{
class Program
{
static void Main()
{
StorageController SDController = StorageController.GetDefault();
IDriveProvider SDDrive = null;

        GpioController GPIO = GpioController.GetDefault();
        GpioPin SDDetect = GPIO.OpenPin(G120.GpioPin.P1_8);
        SDDetect.SetDriveMode(GpioPinDriveMode.InputPullUp);

        PwmController pwm1 = PwmController.FromName(G120.PwmChannel.Controller1.Id);
        pwm1.SetDesiredFrequency(1500);
        var R = pwm1.OpenChannel(G120.PwmChannel.Controller1.P3_26);
        R.Start();
        var G = pwm1.OpenChannel(G120.PwmChannel.Controller1.P3_24);
        G.Start();
        var B = pwm1.OpenChannel(G120.PwmChannel.Controller1.P3_25);
        B.Start();

        R.SetActiveDutyCyclePercentage(0.2);
        G.SetActiveDutyCyclePercentage(0.2);
        B.SetActiveDutyCyclePercentage(0.0);


        while (true)
        {
            try // If SD card was removed while mounting, it may throw exceptions
            {

                // make sure it is fully inserted and stable
                if (SDDetect.Read() == GpioPinValue.Low)
                {
                    if (SDDrive == null)
                    {
                        SDDrive = FileSystem.Mount(SDController.Hdc);
                        Debug.WriteLine("Mounted: " + SDDrive.Name);
                        R.SetActiveDutyCyclePercentage(0.0);
                        G.SetActiveDutyCyclePercentage(0.8);
                        B.SetActiveDutyCyclePercentage(0.0);
                    }
                }
                else
                {
                    if (SDDrive != null)
                    {
                        FileSystem.Unmount(SDController.Hdc);
                        SDDrive = null;
                        R.SetActiveDutyCyclePercentage(0.8);
                        G.SetActiveDutyCyclePercentage(0.0);
                        B.SetActiveDutyCyclePercentage(0.8);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
                R.SetActiveDutyCyclePercentage(0.8);
                G.SetActiveDutyCyclePercentage(0.0);
                B.SetActiveDutyCyclePercentage(0.0);
            }
            Thread.Sleep(100);
        }
    }
}

}

Update:
After “using the source” i came up with the following line:

StorageController SDController = StorageController.FromName(“GHIElectronics.TinyCLR.NativeApis.LPC17.SdCardStorageController\0”);

But it was all for naught since it still gives me

An unhandled exception of type ‘System.NullReferenceException’ occurred in GHIElectronics.TinyCLR.Devices.Storage.dll

Try putting an @ before the string: StorageController.FromName(@“GHIElectronics.TinyCLR.NativeApis.LPC17.SdCardStorageController\0”);

Thanks! So close and yet so far :slight_smile:

It seems that this is only a fall forwards… It does not crash when there is a card in the slot but still crashes when there is not with:

An unhandled exception of type ‘System.InvalidOperationException’ occurred in GHIElectronics.TinyCLR.Devices.Storage.dll

When there is no card present an exception is expected right now.