Skip to content

Latest commit

 

History

History
148 lines (121 loc) · 10.2 KB

File metadata and controls

148 lines (121 loc) · 10.2 KB

.NET


.NET C#

The .NET DUE library allows full .NET programs to access physical sensors and actuators. This allows complex .NET programs to do all the heavy lifting and send only the necessary components to control devices.

The provided library is implemented in C# but the user can use any .NET system, such as Visual Basic.

Setup

This page assumes the user is already familiar with .NET C# and there is a development machine that is already setup to build and run .NET programs. No changes are needed there but we are using Microsoft Visual Studio Code as a personal preference.

Tip

If this is the first time you use your device, start by visiting the Hardware page and load your device with the appropriate firmware. The Console is also a great place to start.

Start a new project with a simple line of code to test out the project is running

Tip

C# Top level statements feature is being utilized, but not required.

Console.WriteLine("Hello, World!");

Download and install the latest GHIElectronics.DUELink library from NuGet.org. Alternatively, get it from the Downloads page.

Blinky!

Our first program will blink the on-board LED 20 times, where it comes on for 200ms and then it is off for 800ms.

Note

We can access which COM port our DUE enable device is connected to by calling the GetConnectionPort()

using GHIElectronics.DUELink;
Console.WriteLine("Hello DUE!");
var availablePort = DUELinkController.GetConnectionPort();
var dev = new DUELinkController(availablePort);
dev.Led.Set(200, 800, 20);
Console.WriteLine("Bye DUE!");

.NET API

The provided API mirrors DUE Script's Core library. Referencing those APIs is a good place to learn about the available functionality and available arguments.

| .NET API | DUE Script Equivalent |Description | :--- |:--- | | Analog.Read() |ARead() | Reads analog pin | Analog.Write() |AWrite() | Reads analog pin | Button.Enable() |BtnEnable() | Sets up a button to be used | Button.JustPressed() |BtnDown() | Detects if button was pressed | Button.JustReleased() |BtnDown() | Detects if button is released | DeviceConfig.IsEdge() |Version() | Checks for specific hardware | DeviceConfig.IsFlea() |Version() | Checks for specific hardware | DeviceConfig.IsPico() |Version() | Checks for specific hardware | DeviceConfig.IsPulse() |Version() | Checks for specific hardware | DeviceConfig.MaxPinIO() |NA | Returns # available GPIOs | DeviceConfig.MaxPinAnalog() |NA | Returns # available Analog pins | Digital.Read() |DRead() | Reads digital pin | Digital.Write() |DWrite() | Writes to digital pin | Display.Clear() |LcdClear() | Clears the display black or white | Display.Configuration() |LcdConfig() | Set display configuration | Display.DrawBuffer() |LcdStream() | Updates the entire display, takes an array, using stream, with automatic Show() | Display.DrawBufferBytes() |LcdStream() | Updates the entire display, takes bytes, using stream, with automatic Show() | Display.DrawCircle() |LcdCircle() | Draws a circle on the display | Display.DrawFillRect() |LcdFill() | Draws a filled rectangle on the display | Display.DrawImage() |LcdImg() | Draws an image using an array | Display.DrawImageBytes() |LcdImg() | Draws an image using bytes | Display.DrawImageScale() |LcdImg() | Works same as DrawImage() adds scaling | Display.DrawLine() |LcdLine() | Draws a line on the display | Display.DrawRectangle() |LcdRect() | Draws a rectangle on the display | Display.DrawText() |LcdText() | Draws a text on the display | Display.DrawTextScale() |LcdTextS() | Draws scaled text on the display | Display.SetPixel() |LcdPixel() | Draws pixel on the display | Display.Show() |LcdShow() | Sends the display buffer | Distance.Read() |Distance() | Used to read distance sensors | Frequency.Write() |Freq() | Hardware generated PWM signal | I2c.Write() |I2cStream() | I2C write, using stream | I2c.Read() |I2cStream() | I2C read, using stream | I2c.WriteRead() |I2cStream() | I2C write/read, using stream | Infrared.Enable() |IrEnable() | Enables pin for IR signal capture | Infrared.Read() |IrRead() | Reads value from IR enabled pin | Led.Set() |LED() | Controls the on-board LED | Neo.Clear() |NeoClear() | Clears all LED's in memory | Neo.SetColor() |NeoSet() | Set's a specific LED to a color | Neo.Show() |NeoShow() | Transfers the internal pattern to LEDs | Neo.SetMultiple() |NeoStream() | Updates all LEDs, using streams, with automatic Show() | Led.Set() |LED() | Controls the on-board LED | Servo.Set() |ServoSet() | Sets servo motor connected to a pin | Spi.Configuration() |SpiCfg() | Configures SPI bus | Spi.Palette() |Palette() | Sets the desired color for a palette | Spi.Read() |SpiByte() | Reads SPI byte | Spi.Write() |SpiByte() | Sends SPI byte | Spi.Write4bpp() |Spi4Bpp() | Streams and converts data from 4BPP to 16BPP | Spi.WriteRead() |SpiStream() | Write & Read SPI bytes | System.Beep() |Beep() | Uses any pin to generate a tone | System.GetTickMicroseconds() |TickUs() | Returns system time in microseconds | System.GetTickMilliseconds() |TickMs() | Returns system time in milliseconds | System.Print() |Print() | Print to LCD display and Debug Output on the same line | System.PrintLn() |PrintLn() | Print to LCD display and Debug Output then moves to next line | System.Reset() |Reset() | Resets the board | System.Wait() |Wait() | Pause the system in milliseconds | Touch.Read() |TouchRead() | Initialize a pin for touch | Uart.BytesToRead() |UartCount() | How many bytes buffered and ready to read | Uart.Enable() |UartInit() | Initialize UART | Uart.Read() |UartRead() | Read UART data | Uart.Write() |UartWrite() | Write UART data | Version() |Version() | Returns the current DUE firmware version

Note

For convenience, the Pin Enum includes, ButtonA, ButtonB and Led. For example: dev.Digital.Write(dev.Pin.Led, True)

DUE Script Control

These methods allow developers to control DUE Scripts right from within .NET

Method Description
Script.Execute() Executes the single line of code immediately
Script.IsRunning() Checks if DUE Script is running
Script.Load() Loads the line into internal buffer
Script.New() Clears the program stored in flash
Script.Read() Read the program stored in flash and return as string
Script.Record() Sends the internal buffer to the device, overwriting any previous programs
Script.Run() Runs the program stored in flash

This example will load a simple program line by line and then record it.

dev.Script.Load("c = 10");
dev.Script.Load("@Blink");
dev.Script.Load("Led(100,100,c)");
dev.Script.Record();

This is an example to execute a single line(immediate mode). This does not modify the application stored in flash.

dev.Script.Execute("LED(200,200,10)");

You can also access a previously recorder program using goto (to label) or by calling a function that has a return. This example calls the recorded program above.

dev.Script.Execute("c=5:goto Blink");