Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

詳説 .NET 5 のIoTサポート

2020/12/19 【オンライン】.NET 5 技術セミナー!最新の技術情報を共有しよう!# .NET Conf2020
https://algyan.connpass.com/event/190970/

  • Be the first to comment

詳説 .NET 5 のIoTサポート

  1. 1. 詳説? .NET 5 のIoTサポート 2020/12/19 Takashi Matsuoka
  2. 2. Takashi Matsuoka (@matsujirushi12) 2017~ MVP for Windows Development 2020~ for Microsoft Azure 「e」3つ
  3. 3. .NET 5 とは、どんなモノなのでしょうか。 IoT で使えるのでしょうか。 #ALGYAN
  4. 4. https://docs.microsoft.com/ja-jp/archive/msdn-magazine/2019/july/csharp-net-reunified-microsoft%E2%80%99s-plans-for-net-5
  5. 5. MCU MPU Cortex-M Flash内蔵 (e.g. 2MB) RAM内蔵 (e.g. 256KB) ベアメタル, RTOS US$1~10 Cortex-A, Celeron Flash外付 (e.g. 64GB eMMC) RAM外付 (e.g. 8GB) Windows, Linux US$30~ MT3620 (Azure Sphere) Cortex-A7 + M4 Flash内蔵 (16MB) RAM内蔵 (4MB) 小さいLinux US$10 Windows, Linux, macOS .NET 5
  6. 6. OS .NET 5 Network Connectivity Architectures Hardware Interfaces System.Net System.IO.Ports <UART> System.Device.Gpio Iot.Device <GPIO, PWM, I2C, SPI> ( .NET Platform Extensions 5.0 ) ( .NET Core IoT Libraries ) Windows, Linux, macOS x86, x64, Arm32, Arm64 .NET 5 - Supported OS versions
  7. 7. .NET Core IoT Libraries https://github.com/dotnet/iot/blob/master/Documentation/roadmap.md
  8. 8. ODYSSEY - X86 (+Ubuntu 18.04) LED .NET 5 VSCode
  9. 9. Remote Development using SSH
  10. 10. Feature request: support Linux ARM / ARM64
  11. 11. DigitalWrite $ git clone https://github.com/dotnet/iot $ dotnet new console -o DigitalWrite $ cd DigitalWrite $ dotnet add package System.Device.Gpio or $ dotnet add reference ../iot/src/System.Device.Gpio/System.Device.Gpio.csproj using System; using System.Device.Gpio; using System.Threading; const int pin = 337; // Pin7 using var controller = new GpioController(); controller.OpenPin(pin, PinMode.Output); bool ledOn = true; while (true) { ledOn = !ledOn; controller.Write(pin, ledOn ? PinValue.High : PinValue.Low); Thread.Sleep(100); } Program.cs Shell C# 9 : Top-level statements
  12. 12. DEMO
  13. 13. DigitalWrite - Thread.Sleep(100)
  14. 14. DigitalWrite - Thread.Sleep(100)
  15. 15. DigitalWrite – Python(sysfs)
  16. 16. tasks.json ... { "label": "build", "command": “/usr/bin/dotnet", "type": "process", "args": [ "build", "${workspaceFolder}/DigitalWrite.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile" }, ... ターミナル プロセスが起動に失敗しました: Path to shell executable "dotnet" is not a file of a symlink。 "dotnet" is not a file
  17. 17. UnauthorizedAccessException
  18. 18. UnauthorizedAccessException $ wget https://aka.ms/getvsdbgsh -O - 2>/dev/null | /bin/sh /dev/stdin -v latest -l ~/vsdbg $ chmod 700 ~/.ssh $ chmod 600 ~/.ssh/id_rsa $ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys $ sudo vi /etc/sudoers ubuntu ALL=NOPASSWD: ALL ← 最下行に追加
  19. 19. UnauthorizedAccessException ... { "name": ".NET Core Remote Launch (console)", "type": "coreclr", "request": "launch", "preLaunchTask": "build", "program": "${workspaceFolder}/bin/Debug/net5.0/DigitalWrite.dll", "args": [], "cwd": "${workspaceFolder}", "console": "internalConsole", "stopAtEntry": false, "pipeTransport": { "pipeCwd": "${workspaceRoot}", "pipeProgram": "ssh", "pipeArgs": [ "-T", "-i", "~/.ssh/id_rsa", "ubuntu@localhost" ], "debuggerPath": "sudo ~/vsdbg/vsdbg", "quoteArgs": false } }, ... launch.json
  20. 20. ODYSSEY - X86 (+Ubuntu 18.04) Azure IoT Hub
  21. 21. SendTelemetry $ git clone https://github.com/dotnet/iot $ dotnet new console -o SendTelemetry $ cd SendTelemetry $ dotnet add package Microsoft.Azure.Devices.Client using System; using System.Text; using System.Text.Json; using System.Threading.Tasks; using Microsoft.Azure.Devices.Client; const string CONNECTION_STRING = "HostName=matsujirushi-iothub.azure- devices.net;DeviceId=sim;SharedAccessKey=..."; Console.WriteLine("Create DeviceClient"); var client = DeviceClient.CreateFromConnectionString(CONNECTION_STRING, TransportType.Mqtt); var rand = new Random(); while (true) { double currentTemperature = 20 + rand.NextDouble() * 15; double currentHumidity = 60 + rand.NextDouble() * 20; Console.WriteLine("Create telemetry message"); var messageBody = JsonSerializer.Serialize(new { temperature = currentTemperature, humidity = curre ntHumidity, }); using var message = new Message(Encoding.ASCII.GetBytes(messageBody)) { ContentType = "application/json", ContentEncoding = "utf-8", }; Console.WriteLine($"Send telemetry message {DateTime.Now}"); await client.SendEventAsync(message); await Task.Delay(1000); } Program.csShell CONNECT CREATE MESSSGE SEND
  22. 22. DEMO
  23. 23. .NET 5 とは、どんなモノなのでしょうか。 IoT で使えるのでしょうか。 • OS / Architectures • Network Connectivity • Hardware Interfaces • Development Environment
  24. 24. 少しだけDive!
  25. 25. https://devblogs.microsoft.com/dotnet/announcing-net-5-0/ “As a way to try out the new release ourselves, a few of us decided to update the dotnet/iot repo to use new C# 9 syntax and target .NET 5.0. The changes resulted in removing >2k lines of code, just by adopting new syntax. It uses top-level programs, records, patterns, and switch expressions.”
  26. 26. GpioDriver GPIO - .NET Core IoT Libraries GpioController (.cs) GpioController (.Linux.cs) GpioController (.Windows.cs) RaspberryPi3Driver (.cs) RaspberryPi3Driver (.Linux.cs) UnixDriver LibGpiodDriver (.Linux.cs) SysFsDriver (.Linux.cs) RaspberryPi3Driver (.Windows.cs) Windows10Driver (.Windows.cs) partial Create instance
  27. 27. GPIO - .NET Core IoT Libraries https://github.com/dotnet/iot/tree/master/src/System.Device.Gpio
  28. 28. GPIO - .NET Core IoT Libraries
  29. 29. GPIO - .NET Core IoT Libraries
  30. 30. GPIO - .NET Core IoT Libraries
  31. 31. GpioDriver GPIO - .NET Core IoT Libraries GpioController (.cs) GpioController (.Linux.cs) GpioController (.Windows.cs) RaspberryPi3Driver (.cs) RaspberryPi3Driver (.Linux.cs) LibGpiodDriver (.cs) SysFsDriver (.cs) RaspberryPi3Driver (.Windows.cs) Windowsのときの 振る舞いは 割愛♪ partial Create instance RaspberryPi3 LinuxDriver (.cs) RaspberryPiCM3 Driver (.cs) UnixDriver (.cs)
  32. 32. sysfs is dead! long live libgpiod!
  33. 33. sysfs is dead! long live libgpiod! LibGpiodDriver.cs
  34. 34. [DllImport("libgpiod")] # export LD_DEBUG=files # ./DigitalWrite 2780: file=/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.0/libgpiod.so [0]; dynamically loaded by /usr/sh 2780: file=/home/ubuntu/dotnet/DigitalWrite/bin/Debug/net5.0/libgpiod.so [0]; dynamically loaded by /usr/share 2780: file=libgpiod.so [0]; dynamically loaded by /usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.0/libcore 2780: file=/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.0/liblibgpiod.so [0]; dynamically loaded by /usr 2780: file=/home/ubuntu/dotnet/DigitalWrite/bin/Debug/net5.0/liblibgpiod.so [0]; dynamically loaded by /usr/sh 2780: file=liblibgpiod.so [0]; dynamically loaded by /usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.0/libc 2780: file=/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.0/libgpiod [0]; dynamically loaded by /usr/share 2780: file=/home/ubuntu/dotnet/DigitalWrite/bin/Debug/net5.0/libgpiod [0]; dynamically loaded by /usr/share/do 2780: file=libgpiod [0]; dynamically loaded by /usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.0/libcoreclr 2780: file=/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.0/liblibgpiod [0]; dynamically loaded by /usr/sh 2780: file=/home/ubuntu/dotnet/DigitalWrite/bin/Debug/net5.0/liblibgpiod [0]; dynamically loaded by /usr/share 2780: file=liblibgpiod [0]; dynamically loaded by /usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.0/libcore

    Be the first to comment

  • ryotakinukawa

    Dec. 19, 2020
  • hideogawa

    Dec. 27, 2020

2020/12/19 【オンライン】.NET 5 技術セミナー!最新の技術情報を共有しよう!# .NET Conf2020 https://algyan.connpass.com/event/190970/

Views

Total views

475

On Slideshare

0

From embeds

0

Number of embeds

135

Actions

Downloads

8

Shares

0

Comments

0

Likes

2

×