C # UWP program. Runs on raspberry under Windows IoT. When adding a third device (card) to connect via i2c, the program hangs on startup, that is, the program interface does not load. Addresses for all devices are different. There are no errors.
Class 1:
public interface II2CDeviceService { Task<I2cDevice> Create(int slaveAddress); } Class 2:
public class I2CDeviceService: II2CDeviceService { /// <summary> /// /// </summary> /// <param name="slaveAddress">Адрес ведомого устройства</param> /// <returns></returns> public async Task<I2cDevice> Create(int slaveAddress) { var settings = new I2cConnectionSettings(slaveAddress); settings.BusSpeed = I2cBusSpeed.StandardMode; var i2CController = await I2cController.GetDefaultAsync(); return i2CController.GetDevice(settings); } } A short version of the class where all the program logic is spinning:
public class MainPageViewModel : ViewModelBase { private readonly II2CDeviceService i2CDeviceService; private CoreDispatcher Dispatcher { get; set; } public I2cDevice I2CDeviceForAddress15 { get; private set; } public I2cDevice I2CDeviceForAddress18 { get; private set; } public I2cDevice I2CDeviceForAddress19 { get; private set; } public MainPageViewModel(II2CDeviceService i2CDeviceService) { this.i2CDeviceService = i2CDeviceService; try { Dispatcher = CoreWindow.GetForCurrentThread().Dispatcher; CreateCommands(); I2CDeviceForAddress15 = i2CDeviceService.Create(0x15).Result; I2CDeviceForAddress18 = i2CDeviceService.Create(0x18).Result; I2CDeviceForAddress19 = i2CDeviceService.Create(0x19).Result; I2CDeviceForAddress8 = i2CDeviceService.Create(0x8).Result; Temperature = "Н/Д"; Humidity = "Н/Д"; HumidityLevel1Display = "Н/Д"; HumidityLevel2Display = "Н/Д"; HumidityLevel3Display = "Н/Д"; var dispatcher = CoreWindow.GetForCurrentThread().Dispatcher; Task.Run(() => { ReadFromI2CDeviceForAddress15(); /*ReadFromI2CDeviceForAddress8();*/ }); } catch (Exception e) { new MessageDialog(e.Message).ShowAsync(); } } } If I comment out one of these lines, then everything works fine. But if I add the third line, after the compilation is complete, the program just hangs (the interface does not load):
I2CDeviceForAddress15 = i2CDeviceService.Create(0x15).Result; I2CDeviceForAddress18 = i2CDeviceService.Create(0x18).Result; I2CDeviceForAddress19 = i2CDeviceService.Create(0x19).Result; Apparently there is some kind of conflict when adding 3 devices, but which one I can not understand. Tell me what could be the problem and how can I fix it?
UPD: Using the debugger, I found that the program hangs when switching from the last but one to the last line when accessing the third device (address 0x19) :
public async Task<I2cDevice> Create(int slaveAddress) { var settings = new I2cConnectionSettings(slaveAddress); settings.BusSpeed = I2cBusSpeed.StandardMode; var i2CController = await I2cController.GetDefaultAsync(); return i2CController.GetDevice(settings); }