DacController.GetDefault() throw Exception

DacController.GetDefault() throw Exception.

Device: SCM20260D Dev Rev C
OS Version: 2.1.0-preview2

#### Exception System.ArgumentException - 0xfd000000 (1) ####
#### Message: 
#### GHIElectronics.TinyCLR.Native.NativeApi::GetDefaultName [IP: 0000] ####
#### GHIElectronics.TinyCLR.Devices.Dac.DacController::GetDefault [IP: 0017] ####
#### TinyCLRDAC.Program::Main [IP: 0004] ####
Exception thrown: 'System.ArgumentException' in GHIElectronics.TinyCLR.Native.dll
An unhandled exception of type 'System.ArgumentException' occurred in GHIElectronics.TinyCLR.Native.dll

Test code:

using GHIElectronics.TinyCLR.Devices.Dac;
using GHIElectronics.TinyCLR.Pins;

namespace TinyCLRDAC
{
    class Program
    {
        static void Main()
        {
            DacChannel dac = DacController.GetDefault().OpenChannel(SC20260.Dac.PA5);

            dac.WriteValue(0xFF);

            while (true) ;
        }
    }
}

while working on previews, there’s not much point working on the older version… I’d upgrade and confirm you have a repro this on Preview3. TinyCLR OS 2.1 Preview 3

Does
DacChannel dac = DacController.FromName(SC20260.Dac.Id).OpenChannel(SC20260.Dac.PA4);
work ?

1 Like

Yes, it work. Thanks

You really shouldn’t use default controller except for GPIO since you know it will always be just the one

Of course, I didn’t know that. The default controller is used in the documentation in all tutorials.

Then we will fix that. I just checked and I only found DAC. Please let us know if you find any others.

All controller with GetDefault in documaentation except gpio controller :wink:

UsbClientController.GetDefault()
software/tinyclr/tutorials/usb-cdc-winusb.md
software/tinyclr/tutorials/usb.md

DisplayController.GetDefault()
software/tinyclr/tutorials/camera.md
software/tinyclr/tutorials/displays.md
software/tinyclr/tutorials/graphics.md
software/tinyclr/tutorials/user-interface.md

RtcController.GetDefault()
software/tinyclr/tutorials/real-time-clock.md

WatchdogController.GetDefault()
software/tinyclr/tutorials/watchdog-timer.md

DacController.GetDefault()
software/tinyclr/tutorials/analog-out.md
software/tinyclr/tutorials/audio-playback.md

AdcController.GetDefault()
software/tinyclr/tutorials/touch-screen.md
software/tinyclr/tutorials/ifttt.md

Search for all GetDefault() in documentation:

Thanks for point them out.

Ideally, if a peripheral has only one controller, then you can use get default, otherwise, you will get an exception.

Watchdog, RTC, gpio… TinyCLR has only one controller for each.

PWM, ADC, I2C… TinyCLR has more than one for each.

But he is using DAC with one controller, right? Why didn’t it work?