Ejemplo n.º 1
0
        // Dispose(bool disposing) executes in two distinct scenarios.
        // If disposing equals true, the method has been called directly
        // or indirectly by a user's code. Managed and unmanaged resources
        // can be disposed.
        // If disposing equals false, the method has been called by the
        // runtime from inside the finalizer and you should not reference
        // other objects. Only unmanaged resources can be disposed.
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!FDisposed)
            {
                if (disposing)
                {
                    // Dispose managed resources.
                }
                // Release unmanaged resources. If disposing is false,
                // only the following code is executed.

                if (FHost != null)
                {
                    FHost.Log(TLogType.Debug, "IO Phidget Encoder HighSpeed is being deleted");
                }

                if (m_IKitData != null)
                {
                    m_IKitData.Close();
                    m_IKitData = null;
                }

                // Note that this is not thread safe.
                // Another thread could start disposing the object
                // after the managed resources are disposed,
                // but before the disposed flag is set to true.
                // If thread safety is necessary, it must be
                // implemented by the client.
            }
            FDisposed = true;
        }
Ejemplo n.º 2
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            double Enable;
            double Serial;

            //FConnected.SliceCount = 1;

            FSerial.GetValue(0, out Serial);
            FEnable.GetValue(0, out Enable);

            try
            {
                if (FSerial.PinIsChanged || FEnable.PinIsChanged)
                {
                    if (FSerial.PinIsChanged)
                    {
                        if (m_IKitData != null)
                        {
                            m_IKitData.Close();
                            m_IKitData = null;
                        }
                    }

                    if (Enable > 0.5)
                    {
                        if (m_IKitData == null)
                        {
                            m_IKitData = new GetEncoderHSData();
                            m_IKitData.Open(Serial);
                        }
                    }
                    else
                    {
                        if (m_IKitData != null)
                        {
                            FInfo.SliceCount = 1;
                            FInfo.SetString(0, "Disabled");
                            m_IKitData.Close();
                            m_IKitData = null;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                FHost.Log(TLogType.Error, "Error by initialising Phidget");
                FHost.Log(TLogType.Error, ex.Message.ToString());
            }



            if (Enable == 1 && m_IKitData.Attached)
            {
                //

                int SliceCountAnalogIn = m_IKitData.InfoDevice.ToArray()[0].EncoderInputs;
                try
                {
                    try
                    {
                        //getting Encoder Position
                        if (m_IKitData.InfoDevice.ToArray()[0].EncoderInputs != 0)
                        {
                            FPositionOut.SliceCount = SliceCountAnalogIn;
                            for (int i = 0; i < SliceCountAnalogIn; i++)
                            {
                                FPositionOut.SetValue(i, m_IKitData.EncoderInputs[i]);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        FHost.Log(TLogType.Error, "Error in " + m_IKitData.InfoDevice.ToArray()[0].Name + " getting encoder Position");
                        FHost.Log(TLogType.Error, ex.Message.ToString());
                    }


                    try
                    {
                        // set Position
                        if (FSetPosition.PinIsChanged)
                        {
                            double setPosition;
                            FSetPosition.GetValue(0, out setPosition);

                            if (setPosition > 0.5)
                            {
                                double   SliceCountSense = FPositionIn.SliceCount;
                                double[] tPosition       = new double[SliceCountAnalogIn];
                                for (int i = 0; i < SliceCountAnalogIn; i++)
                                {
                                    double sense;
                                    FPositionIn.GetValue(i, out sense);
                                    tPosition[i] = sense;
                                }
                                m_IKitData.SetPosition(tPosition);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        FHost.Log(TLogType.Error, "Error in " + m_IKitData.InfoDevice.ToArray()[0].Name + " setting encoder Position");
                        FHost.Log(TLogType.Error, ex.Message.ToString());
                    }


                    //setting Phidget Infos
                    try
                    {
                        int SpreadSizeInfo = 3;
                        for (int i = 0; i < SpreadSizeInfo; i++)
                        {
                            FInfo.SliceCount = 3;
                            switch (i)
                            {
                            case 0:
                                FInfo.SetString(i, "Name: " + m_IKitData.InfoDevice.ToArray()[0].Name);
                                break;

                            case 1:
                                FInfo.SetString(i, "Serial: " + m_IKitData.InfoDevice.ToArray()[0].SerialNumber.ToString());
                                break;

                            case 2:
                                FInfo.SetString(i, "Version: " + m_IKitData.InfoDevice.ToArray()[0].Version.ToString());
                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        FHost.Log(TLogType.Error, "Error in Phidget " + m_IKitData.InfoDevice.ToArray()[0].Name + " setting Phidget Infos");
                        FHost.Log(TLogType.Error, ex.Message.ToString());
                    }
                }
                catch (Exception ex)
                {
                    FHost.Log(TLogType.Error, "Error in Phidget " + m_IKitData.InfoDevice.ToArray()[0].Name);
                    FHost.Log(TLogType.Error, ex.Message.ToString());
                }
            }
        }