Example #1
0
        public void SetActiveDevice(IHardwareInterface iface)
        {
            if (!connectedList.Contains(iface))
            {
                return;
            }

            // Don't handle a second activation if the interface
            // has already been activated
            if (activeDevice != null && activeDevice.HardwareInterface == iface)
            {
                return;
            }

            // Activate new device
            Type DeviceType = null;
            Type ifaceType  = iface.GetType();

            foreach (Type t in this.InterfaceActivators.Keys)
            {
                if (ifaceType == t || ifaceType.IsSubclassOf(t) || ifaceType.GetInterfaces().Contains(t))
                {
                    DeviceType = InterfaceActivators[t];
                    break;
                }
            }

            if (DeviceType == null)
            {
                Logger.Error("Unsupported interface type " + iface.GetType().FullName);
                return;
            }

            try
            {
                IDevice newDevice = (IDevice)Activator.CreateInstance(DeviceType, iface);

                if (activeDevice != null)
                {
                    if (DeviceConnected != null)
                    {
                        DeviceConnected(activeDevice, false);
                    }
                    if (activeDevice is IDisposable)
                    {
                        (activeDevice as IDisposable).Dispose();
                    }
                }

                activeDevice = newDevice;
                if (DeviceConnected != null)
                {
                    DeviceConnected(activeDevice, true);
                }
            }
            catch (Exception e)
            {
                Logger.Error("Failed to create device: " + e.Message);
            }
        }
Example #2
0
        public Motor(byte id)
        {
            this.hardwareInterface = ServiceLocator.Get <IHardwareInterface>();

            this.id = id;

            this.pwm = 0;
        }
Example #3
0
        private void DisposeHardwareInterface()
        {
            ServiceLocator.Unregister <IHardwareInterface>(this.hardwareInterface);
            this.hardwareInterface.Close();

            this.hardwareInterface = null;

            this.logger.LogDebug("Disposed hardware interface");
        }
Example #4
0
        private void InitializeHardwareInterface(string port, int baudRate)
        {
            this.hardwareInterface = new TeensyInterface(port, baudRate);
            //this.hardwareInterface = new VoidInterface();
            this.hardwareInterface.Open();

            ServiceLocator.Register <IHardwareInterface>(this.hardwareInterface);

            this.logger.LogDebug("Initialized hardware interface");
        }
Example #5
0
        public Joystick(int id, int minValue, int maxValue)
        {
            this.hardwareInterface = ServiceLocator.Get <IHardwareInterface>();

            this.id = id;

            this.value    = (int)this.Map(0.5f, 0.0f, 1.0f, minValue, maxValue);
            this.minValue = minValue;
            this.maxValue = maxValue;

            this.hardwareInterface.joystickValueReceived += OnJoystickValueReceived;
        }
Example #6
0
        private static void Chipleser_verbinden()
        {
            var ergebnis = Chipleser.Initialisiere_Chipleser(OnChipAufgelegt, OnChipEntfernt, OnReaderGetrennt, OnMehrereChips);

            if (ergebnis == null)
            {
                var dialogResult = Kein_Reader_gefunden_Dialog_ausgeben();
                if (dialogResult == DialogResult.Retry)
                {
                    Chipleser_verbinden();
                }
                else
                {
                    Beenden();
                }
            }
            else
            {
                _chipleser = ergebnis.Item1;
                var verbindungsinfo = ergebnis.Item2;

                Console.Write(@"Verbinde mit Chipleser... ");
                var openPortResult = _chipleser.Open();

                if (openPortResult.Ergebnis == Ergebnis.Erfolg)
                {
                    var meldung = $"Verbunden: {verbindungsinfo}";
                    Console.WriteLine(meldung);
                    Balloninfo("Com-Ports", meldung, 2000);
                }
                else
                {
                    Console.WriteLine(openPortResult.Meldung);
                    var dialogResult = Kein_Zugriff_auf_Port_Dialog_ausgeben(openPortResult.Meldung);
                    if (dialogResult == DialogResult.Retry)
                    {
                        Chipleser_verbinden();
                    }
                    else
                    {
                        Beenden();
                    }
                }
            }
        }
Example #7
0
        public Servo(byte id, bool winding, IAngle rootAngle, IAngle minAngle, IAngle maxAngle)
        {
            this.hardwareInterface = ServiceLocator.Get <IHardwareInterface>();

            this.id      = id;
            this.winding = winding;

            this.rootAngle = rootAngle;
            this.minAngle  = minAngle;
            this.maxAngle  = maxAngle;

            this.targetAngle = new Radians(0.0f);
            this.angle       = new Radians(0.0f);

            this.ledState = false;

            this.speed = 1023 / 4;

            this.hardwareInterface.servoPositionUpdated += OnServoPositionUpdated;
            //this.SetTargetAngle(rootAngle);
            //this.FlushState();
        }
Example #8
0
        private void OnInterfaceChanged(IHardwareInterface hardwareInterface, bool connected)
        {
            if (connected)
            {
                connectedList.Add(hardwareInterface);

                #if WINDOWS
                lastSmartScopeDetectedThroughWinUsb = DateTime.Now;
                                #endif
            }
            else
            {
                if (connectedList.Contains(hardwareInterface))
                {
                    connectedList.Remove(hardwareInterface);
                }

                #if WINDOWS
                lastSmartScopeDetectedThroughWinUsb = null;
                                #endif
            }

            /* If application handles interface preferences, pass it the updated
             * list of connected interfaces for it to decide who to call SetActiveDevice
             * with
             */
            if (InterfaceChanged != null)
            {
                InterfaceChanged(this, connectedList);
            }
            /* Else activate the lastly connected interface */
            else
            {
                SetActiveDevice(connectedList.Last());
            }
        }
 public ShutdownCommand(IHardwareInterface hardwareInterface) : base(1)
 {
     this.hardwareInterface = hardwareInterface;
 }
Example #10
0
 public DCMotorsCommand(IHardwareInterface hardwareInterface) : base(1)
 {
     this.hardwareInterface = hardwareInterface;
 }
Example #11
0
 public ServoCommand(IHardwareInterface hardwareInterface) : base(1)
 {
     this.hardwareInterface = hardwareInterface;
 }
Example #12
0
 public RemoteTimeout(IHardwareInterface hardwareInterface) : base(0)
 {
     this.hardwareInterface = hardwareInterface;
 }
 public UpdateLoadCellValue(IHardwareInterface hardwareInterface) : base(4)
 {
     this.hardwareInterface = hardwareInterface;
 }
Example #14
0
 public ModusCommand(IHardwareInterface hardwareInterface) : base(1)
 {
     this.hardwareInterface = hardwareInterface;
 }
 public ReceiveJoystickPosition(IHardwareInterface hardwareInterface) : base(2)
 {
     this.hardwareInterface = hardwareInterface;
 }
Example #16
0
 public UpdateServoPosition(IHardwareInterface hardwareInterface) : base(3)
 {
     this.hardwareInterface = hardwareInterface;
 }