처음 초기화
public async Task InitIO()
{
...
...
try
{
settings = new SpiConnectionSettings(SPI_CHIP_SELECT_LINE);
settings.ClockFrequency = 1000000;
settings.Mode = SpiMode.Mode0;
String spiDeviceSelector = SpiDevice.GetDeviceSelector();
IReadOnlyList<DeviceInformation> devices = await DeviceInformation.FindAllAsync(spiDeviceSelector);
_spi = await SpiDevice.FromIdAsync(devices[0].Id, settings);
}
catch (Exception ex)
{
throw new Exception("SPI Initialization Failed", ex);
}
...
...
}
두 번째 시간 초기화 :
public async Task ReInitSpi()
{
_spi.Dispose(); //Here is important.
try
{
if (settings.ChipSelectLine == 0)
{
settings = new SpiConnectionSettings(1); //CS1
}
else
{
settings = new SpiConnectionSettings(SPI_CHIP_SELECT_LINE); //CS0
}
settings.ClockFrequency = 1000000;
settings.Mode = SpiMode.Mode0;
String spiDeviceSelector = SpiDevice.GetDeviceSelector();
IReadOnlyList<DeviceInformation> devices = await DeviceInformation.FindAllAsync(spiDeviceSelector);
_spi = await SpiDevice.FromIdAsync(devices[0].Id, settings);
}
/* If initialization fails, display the exception and stop running */
catch (Exception ex)
{
throw new Exception("SPI Initialization Failed", ex);
}
}
때마다이 같은 그것을, 예를 들어, 사용 :
await mfrc.ReInitSpi();
var writeBuffer = new byte[] { 0x55, 0xaa };
mfrc._spi.Write(writeBuffer);
이 작품을 나를 위해. 나는 그것이 당신에게 도움이되기를 바랍니다.
라인 0은 Rpi2의 물리적 핀 번호 24 (CS0)에 매핑되고 라인 1은 물리적 핀 번호 26 (CS1)에 매핑됩니다. 칩 선택 라인은 초기화 할 때 SPI 디바이스에 바인딩되기 때문에. 초기화 된 SPI 디바이스를'Dispose '하고 칩 선택 라인을 변경하고 다시 초기화 할 수 있습니다. –
작동하지 않습니다. 다음 초기화 프로그램이 중지되는 동안. – Jarek