public async Task Initialize() { try { var i2Init = _i2CConnector.Initialize(); var spiInit = _spiConnector.Initialize(); await spiInit; await i2Init; var factory = new GeneralFactory(_i2CConnector, _spiConnector, _driverLogger); foreach (var foundGroupId in _spiConnector.GetFoundGroupIds()) { var board = factory.CreateNeuronBoard(foundGroupId); if (board == null) { continue; } _driverLogger.LogInformation(this, "Found Board " + board.BoardSystemInformation?.HardwareName + " on group " + foundGroupId); _boards.Add(board); } OnInitializationFinish?.Invoke(); } catch (Exception exception) { _driverLogger.LogException(this, exception); } }
/// <summary> /// Reads the data. /// </summary> /// <param name="romNumber">The rom number.<see cref="Byte"/></param> /// <param name="command">The command.<see cref="Byte"/></param> /// <param name="byteLength">Length of the byte.</param> /// <returns></returns> public byte[] ReadData(byte[] romNumber, int byteLength, params byte[] commands) { lock (_controllerLock) { _logger.LogInformation(this, "reading data from device with rom number " + string.Join("-", romNumber) + " with commands " + string.Join("-", commands)); _logger.LogDebug(this, "reset one wire bus"); _neuronConnectedOneWireDevice.OneWireResetBus(); _logger.LogDebug(this, "writing rom command match"); _neuronConnectedOneWireDevice.OneWireWriteByte(0x55); _logger.LogDebug(this, "write romNumber " + string.Join("-", romNumber) + " for rom command match"); foreach (var item in romNumber) { _neuronConnectedOneWireDevice.OneWireWriteByte(item); } foreach (var command in commands) { _logger.LogDebug(this, "writing command " + command.ToString("x2")); _neuronConnectedOneWireDevice.OneWireWriteByte(command); } _logger.LogDebug(this, "read " + byteLength + " byte of data"); var data = new byte[byteLength]; for (var i = 0; i < byteLength; i++) { var dataByte = _neuronConnectedOneWireDevice.OneWireReadByte(); data[i] = dataByte; } _logger.LogDebug(this, "data = " + string.Join("-", data)); return(data); } }
internal OneWireConnector(NeuronGroup neuronGroup, int number, DriverLogger logger, I2CConnector i2CGateway) { _logger = logger; _logger.LogInformation(this, "create Instance..."); UniqueIdentifyer = new UniqueIdentifier(neuronGroup, NeuronResource.OneWireConnector, number); OneWirePeriodicBusScan = true; _timerState = new object(); _controllerLock = new object(); Devices = new List <IOneWireDevice>(); _neuronConnectedOneWireDevice = new NeuronConnectedOneWireDevice(i2CGateway); _logger.LogInformation(this, "scanning bus on startup"); ScanForNewOrDeadDevices(); PeriodicBusScanIntervalSeconds = 60; }
internal INeuronGroupBoard CreateNeuronBoard(NeuronGroup neuronGroup) { try { var boardInformationRegisterSet = _spiConnector.GetRegisterValues(neuronGroup, 1000, 5); var boardInformation = GetBoardInfoFromRegisters(boardInformationRegisterSet, _logger, neuronGroup); if (boardInformation != null) { switch (boardInformation.BoardType) { case BoardType.UnknownBoard: _logger.LogInformation(this, "Board " + boardInformation.BoardType + " not supported!"); break; case BoardType.B10001: return(new B10001GroupBoard(neuronGroup, boardInformation, _spiConnector, _i2CConnector, _logger)); case BoardType.E8Di8Ro1: return(new UniversalNeuronGroupDiRoBoard(8, 8, neuronGroup, boardInformation, _spiConnector, _i2CConnector, _logger)); case BoardType.E14Ro1: return(new UniversalNeuronGroupDiRoBoard(0, 16, neuronGroup, boardInformation, _spiConnector, _i2CConnector, _logger)); case BoardType.E16Di1: return(new UniversalNeuronGroupDiRoBoard(16, 0, neuronGroup, boardInformation, _spiConnector, _i2CConnector, _logger)); case BoardType.E8Di8Ro1P11DiMb485: _logger.LogInformation(this, "Board " + boardInformation.BoardType + " not supported!"); break; case BoardType.E14Ro1P11DiR4851: _logger.LogInformation(this, "Board " + boardInformation.BoardType + " not supported!"); break; case BoardType.E16Di1P11DiR4851: _logger.LogInformation(this, "Board " + boardInformation.BoardType + " not supported!"); break; case BoardType.E14Ro1U14Ro1: _logger.LogInformation(this, "Board " + boardInformation.BoardType + " not supported!"); break; case BoardType.E16Di1U14Ro1: return(new UniversalNeuronGroupDiRoBoard(16, 14, neuronGroup, boardInformation, _spiConnector, _i2CConnector, _logger)); case BoardType.E14Ro1U14Di1: return(new UniversalNeuronGroupDiRoBoard(14, 14, neuronGroup, boardInformation, _spiConnector, _i2CConnector, _logger)); case BoardType.E16Di1U14Di1: _logger.LogInformation(this, "Board " + boardInformation.BoardType + " not supported!"); break; default: throw new ArgumentOutOfRangeException(); } } } catch (Exception e) { _logger.LogException(this, e); return(null); } return(null); }