I follow the document from Microsoft as below: https://learn.microsoft.com/en-us/windows/iot-core/learn-about-hardware/pinmappings/pinmappingsrpi Here is the code:
using Windows.Devices.Enumeration;
using Windows.Devices.Spi;
public async void SPI()
{
// Use chip select line CS0
var settings = new SpiConnectionSettings(0);
// Set clock to 10MHz
settings.ClockFrequency = 10000000;
// Get a selector string that will return our wanted SPI controller
string aqs = SpiDevice.GetDeviceSelector("SPI0");
// Find the SPI bus controller devices with our selector string
var dis = await DeviceInformation.FindAllAsync(aqs);
// Create an SpiDevice with our selected bus controller and Spi settings
using (SpiDevice device = await SpiDevice.FromIdAsync(dis[0].Id, settings))
{
byte[] writeBuf = { 0x01, 0x02, 0x03, 0x04 };
device.Write(writeBuf);
}
}
This code can build successful. But it does not work in Raspbian with Mono. Looking around, I follow this: https://github.com/dotnet/iot/issues/1089
The way to migrate is to remove all references to winmds and System.Runtime.WindowsRuntime and System.Runtime.InteropServices.WindowsRuntime and instead just reference the Microsoft.Windows.SDK.NET package.
But it fail to build because of below error:
The type 'IAsyncAction' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'
I read below link, but it could not help. IAsyncOperation await in Windows Service: "Type is defined in an assembly that is not referenced..."