Exemplo n.º 1
0
        internal AnalogOutput(NeuronGroup neuronGroup, int number, ushort registerNumber, NeuronSpiConnector spiConnector, DriverLogger logger)
        {
            _registerNumber = registerNumber;
            _logger         = logger;
            _logger.LogInstantiating(this);
            _neuronGroup  = neuronGroup;
            _spiConnector = spiConnector;

            UniqueIdentifyer = new UniqueIdentifier(neuronGroup, NeuronResource.AnalogOutput, number);

            var vOffset = _spiConnector.GetSingleRegisterValue(neuronGroup, 1021);
            var vDef    = _spiConnector.GetSingleRegisterValue(neuronGroup, 1020);
            var vRef    = _spiConnector.GetSingleRegisterValue(neuronGroup, 1009);
            var vRefInt = _spiConnector.GetSingleRegisterValue(neuronGroup, 5);

            if (vRefInt == null || vRef == null || vOffset == null || vDef == null)
            {
                throw new Exception("failure while getting the calibration Values from the Registers!");
            }

            _vOffset = BitConverter.ToInt16(BitConverter.GetBytes(vOffset.Value), 0);
            _vDev    = BitConverter.ToInt16(BitConverter.GetBytes(vDef.Value), 0);

            _vRealInt = 3.3 * ((double)vRef / (double)vRefInt);
        }
Exemplo n.º 2
0
        internal NeuronGroupBoardBase(NeuronGroup neuronGroup, IBoardInformation boardSystemInformation, NeuronSpiConnector spiConnector, I2CConnector i2CConnector, DriverLogger logger)
        {
            NeuronGroup  = neuronGroup;
            SpiConnector = spiConnector;
            I2CConnector = i2CConnector;
            Logger       = logger;

            _observeLocker = new object();

            _registersToObserve = new Dictionary <ushort, List <IObservedRegisterObject> >();

            BoardSystemInformation = boardSystemInformation;

            DigitalInputDictionary      = new Dictionary <IUniqueIdentifier, IDigitalInput>();
            DigitalOutputsDictionary    = new Dictionary <IUniqueIdentifier, IDigitalOutput>();
            RelayOutputsDictionary      = new Dictionary <IUniqueIdentifier, IDigitalOutput>();
            UserLedsDictionary          = new Dictionary <IUniqueIdentifier, IUserLed>();
            AnalogInputsDictionary      = new Dictionary <IUniqueIdentifier, IAnalogInput>();
            AnalogOutputsDictionary     = new Dictionary <IUniqueIdentifier, IAnalogOutput>();
            OneWireConnectorsDictionary = new Dictionary <IUniqueIdentifier, IOneWireConnector>();
            ModbusConnectorsDictionary  = new Dictionary <IUniqueIdentifier, IModbusConnector>();

            _pollInProgess = false;
            _pollingTimer  = new Timer(PollInformation, new object(), 50, 50);
        }
Exemplo n.º 3
0
 public NeuronSpiConnector(DriverLogger driverLogger)
 {
     _spiDeviceLocker = new object();
     _devices         = new Dictionary <NeuronGroup, SpiDevice>();
     _destination     = new Queue <byte>(new byte[8]);
     _driverLogger    = driverLogger;
 }
Exemplo n.º 4
0
        public NeuronDevice(bool autoInitialize = false)
        {
            _boards = new List <INeuronGroupBoard>();

            _driverLogger = new DriverLogger(LogLevel.Debug);

            _driverLogger.OnLogInformation += OnLogInformation;

            _spiConnector = new NeuronSpiConnector(_driverLogger);
            _i2CConnector = new I2CConnector(_driverLogger);

            if (autoInitialize)
            {
                Task.Factory?.StartNew(Initialize);
            }
        }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
        internal DigitalOutput(int numberOfOutputOnGroup, NeuronGroup neuronGroup, ushort coilNumber, NeuronSpiConnector neuronSpiConnector, DriverLogger logger, DigitalRelayOutputType digitalRelayOutputType, ushort registerNumber, ushort bitNumber)
        {
            _neuronGroup        = neuronGroup;
            _coilNumber         = coilNumber;
            _neuronSpiConnector = neuronSpiConnector;
            _registerNumber     = registerNumber;
            _bitNumber          = bitNumber;
            logger.LogInstantiating(this);


            UniqueIdentifyer = digitalRelayOutputType == DigitalRelayOutputType.DigitalOutput ?
                               new UniqueIdentifier(_neuronGroup, NeuronResource.DigitalOutput, numberOfOutputOnGroup) :
                               new UniqueIdentifier(_neuronGroup, NeuronResource.RelayOutput, numberOfOutputOnGroup);

            UpdateLocalValue();
        }
Exemplo n.º 7
0
        internal static BoardInformation GetBoardInfoFromRegisters(SpiRegisterSet registerSet, DriverLogger logger, NeuronGroup neuronGroup)
        {
            try
            {
                if (registerSet == null || registerSet.Count != 5)
                {
                    return(null);
                }


                if (!registerSet.ContainsRegister(1000) ||
                    !registerSet.ContainsRegister(1001) ||
                    !registerSet.ContainsRegister(1002) ||
                    !registerSet.ContainsRegister(1003) ||
                    !registerSet.ContainsRegister(1004))
                {
                    logger.LogError(null, "i got the wrong registerSet to create the system information!");
                    return(null);
                }

                var configRegisters = registerSet.ToRegisterValueArray();

                int swSubver;
                int hwVersion;
                int hwSubver;

                var swVersion = configRegisters[0] >> 8;
                var diCount   = configRegisters[1] >> 8;
                var doCount   = configRegisters[1] & 0xff;
                var aiCount   = configRegisters[2] >> 8;
                var aoCount   = (configRegisters[2] & 0xff) >> 4;

                var uledCount = 0;

                if (swVersion < 4)
                {
                    swSubver  = 0;
                    hwVersion = (configRegisters[0] & 0xff) >> 4;
                    hwSubver  = configRegisters[0] & 0xf;
                }
                else
                {
                    swSubver  = configRegisters[0] & 0xff;
                    hwVersion = configRegisters[3] >> 8;
                    hwSubver  = configRegisters[3] & 0xff;

                    if (hwSubver < 3)
                    {
                    }
                    if (hwVersion == 0)
                    {
                        if (configRegisters[0] != 0x0400)
                        {
                            uledCount = 4;
                        }
                    }
                }


                var firmwareVersion    = new Version(swVersion, swSubver);
                var digitalInputCount  = diCount;
                var digitalOutputCount = doCount;
                var analogInputCount   = aiCount;
                var analogOutputCount  = aoCount;
                var userLedCount       = uledCount;
                var hardwareVersion    = new Version(hwVersion, hwSubver);


                return(new BoardInformation(firmwareVersion, hardwareVersion, digitalInputCount, digitalOutputCount, analogInputCount, analogOutputCount, userLedCount, hwVersion, neuronGroup));
            }
            catch (Exception e)
            {
                logger.LogException(null, e);
                return(null);
            }
        }
Exemplo n.º 8
0
 public GeneralFactory(I2CConnector i2CConnector, NeuronSpiConnector spiConnector, DriverLogger logger)
 {
     _i2CConnector = i2CConnector;
     _spiConnector = spiConnector;
     _logger       = logger;
 }
        public UniversalNeuronGroupDiRoBoard(int digitalInCount, int relayOutCount, NeuronGroup neuronGroup, IBoardInformation boardSystemInformation, NeuronSpiConnector spiConnector, I2CConnector i2CConnector, DriverLogger logger) : base(neuronGroup, boardSystemInformation, spiConnector, i2CConnector, logger)
        {
            #region Digital Inputs

            for (ushort i = 0; i < digitalInCount; i++)
            {
                var input = new DigitalInput(i + 1, neuronGroup, 0, i);
                SetObservation(0, input);
                DigitalInputDictionary.Add(input.UniqueIdentifyer, input);
            }

            #endregion Digital Inputs

            #region Relay Outputs

            for (ushort i = 0; i < relayOutCount; i++)
            {
                var digitalOutput = new DigitalOutput(1 + i, neuronGroup, i, spiConnector, logger, DigitalRelayOutputType.RelayOutput, 1, i);
                DigitalOutputsDictionary.Add(digitalOutput.UniqueIdentifyer, digitalOutput);
            }

            #endregion Relay Outputs
        }
Exemplo n.º 10
0
 internal I2CConnector(DriverLogger logger)
 {
     _logger  = logger;
     _busLock = new object();
     _devices = new Dictionary <UnipiI2CDevice, I2cDevice>();
 }
Exemplo n.º 11
0
        public B10001GroupBoard(NeuronGroup neuronGroup, IBoardInformation boardSystemInformation, NeuronSpiConnector spiConnector, I2CConnector i2CConnector, DriverLogger logger) : base(neuronGroup, boardSystemInformation, spiConnector, i2CConnector, logger)
        {
            #region Digital Inputs

            for (ushort i = 0; i < AnzahlDigitalInputs; i++)
            {
                var input = new DigitalInput(i + 1, neuronGroup, 0, i);
                SetObservation(0, input);
                DigitalInputDictionary.Add(input.UniqueIdentifyer, input);
            }

            #endregion Digital Inputs

            #region Digital Outputs

            for (ushort i = 0; i < AnzahlDigitalOutputs; i++)
            {
                var digitalOutput = new DigitalOutput(1 + i, neuronGroup, i, spiConnector, logger, DigitalRelayOutputType.DigitalOutput, 1, i);
                DigitalOutputsDictionary.Add(digitalOutput.UniqueIdentifyer, digitalOutput);
            }

            #endregion Digital Outputs

            #region One Wire

            var oneWireConnector = new OneWireConnector(neuronGroup, 1, Logger, I2CConnector);
            OneWireConnectorsDictionary.Add(oneWireConnector.UniqueIdentifyer, oneWireConnector);

            #endregion One Wire

            #region User LED's

            for (ushort i = 0; i < UserLedsCount; i++)
            {
                var userLed = new UserLed(i + 1, neuronGroup, (ushort)(8 + i), spiConnector, 20, i);
                UserLedsDictionary.Add(userLed.UniqueIdentifyer, userLed);
            }

            #endregion User LED's

            #region Analog Output

            var analogOutput = new AnalogOutput(neuronGroup, 1, 2, spiConnector, logger);
            AnalogOutputsDictionary.Add(analogOutput.UniqueIdentifyer, analogOutput);

            #endregion Analog Output

            #region Analog Input

            var analogInput = new AnalogInput(neuronGroup, 1, 3, spiConnector);
            SetObservation(3, analogInput);
            AnalogInputsDictionary.Add(analogInput.UniqueIdentifyer, analogInput);

            #endregion Analog Input
        }