Ejemplo n.º 1
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;
            double Ratiomatric;

            //FConnected.SliceCount = 1;

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



            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 GetInterfaceData();
                            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].AnalogOutputs;
                try
                {
                    //Setting Values of analog inputs

                    if (m_IKitData.InfoDevice.ToArray()[0].AnalogOutputs != 0)
                    {
                        FAnalogIn.SliceCount = SliceCountAnalogIn;
                        for (int i = 0; i < SliceCountAnalogIn; i++)
                        {
                            FAnalogIn.SetValue(i, m_IKitData.AnalogInputs[i]);
                        }
                    }



                    //setting Sensitivity of Analog Inputs
                    try
                    {
                        if (FSensitivity.PinIsChanged)
                        {
                            double   SliceCountSense = FSensitivity.SliceCount;
                            double[] SenseValue      = new double[SliceCountAnalogIn];
                            for (int i = 0; i < SliceCountAnalogIn; i++)
                            {
                                double sense;
                                FSensitivity.GetValue(i, out sense);
                                SenseValue[i] = sense;
                            }
                            m_IKitData.SetSense(SenseValue);
                        }
                    }
                    catch (Exception ex)
                    {
                        FHost.Log(TLogType.Error, "Error in Phidget " + m_IKitData.InfoDevice.ToArray()[0].Name + " setting Analog  Output");
                        FHost.Log(TLogType.Error, ex.Message.ToString());
                    }



                    //Setting Values Digital Inputs
                    try
                    {
                        if (m_IKitData.InfoDevice.ToArray()[0].DigitalInputs != 0)
                        {
                            int SliceCountDigitalIn = m_IKitData.InfoDevice.ToArray()[0].DigitalInputs;
                            FDigitalIn.SliceCount = SliceCountDigitalIn;
                            for (int i = 0; i < SliceCountDigitalIn; i++)
                            {
                                FDigitalIn.SetValue(i, m_IKitData.DigitalInputs[i]);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        FHost.Log(TLogType.Error, "Error in Phidget " + m_IKitData.InfoDevice.ToArray()[0].Name + " setting Digitial Output");
                        FHost.Log(TLogType.Error, ex.Message.ToString());
                    }



                    try
                    {
                        if (m_IKitData.InfoDevice.ToArray()[0].DigitalOutputs != 0)
                        {
                            int SliceCountDigitalOut = m_IKitData.InfoDevice.ToArray()[0].DigitalOutputs;

                            FDigiOutCount.SetValue(1, SliceCountDigitalOut);
                            double[] digiOut = new double[m_IKitData.InfoDevice.ToArray()[0].DigitalInputs];

                            for (int i = 0; i < SliceCountDigitalOut; i++)
                            {
                                FDigitalOut.GetValue(i, out digiOut[i]);
                            }
                            m_IKitData.SetDigitalOutput(digiOut);
                        }
                    }
                    catch (Exception ex)
                    {
                        FHost.Log(TLogType.Error, "Error in Phidget " + m_IKitData.InfoDevice.ToArray()[0].Name + " getting Digitial Output");
                        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());
                    }



                    // setting Radiometric
                    try
                    {
                        if (m_IKitData != null)
                        {
                            //FConnected.SetValue(0, m_IKitData.Status);
                            if (m_IKitData.InfoDevice.ToArray()[0].Name.Contains("8/8/8"))
                            {
                                m_IKitData.SetRatiometric(Ratiomatric);
                            }
                        }
                        else
                        {
                            //FConnected.SetValue(0, 0);
                        }
                    }
                    catch (Exception ex)
                    {
                        FHost.Log(TLogType.Error, "Error in Phidget " + m_IKitData.InfoDevice.ToArray()[0].Name + " setting Radiometric");
                        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());
                }
            }
        }