示例#1
0
        private string GetError()
        {
            StringBuilder sbSensorError = new StringBuilder(1024);

            MEDAQLibDLL.GetError(_iSensor, sbSensorError, (UInt32)sbSensorError.Capacity);

            return(sbSensorError.ToString());
        }
示例#2
0
 private void SetParameterString(string paramName, string val)
 {
     if (_iSensor == 0)
     {
         return;
     }
     lock (_lockCommands)
     {
         MEDAQLibDLL.ERR_CODE iRet = MEDAQLibDLL.ERR_CODE.ERR_NOERROR;
         iRet = MEDAQLibDLL.SetParameterString(_iSensor, paramName, val);
         if (iRet != MEDAQLibDLL.ERR_CODE.ERR_NOERROR)
         {
             throw new MCoreExceptionPopup("Error with SetParameterString('{0}', '{1}') : '{2}'", paramName, val, GetError());
         }
     }
 }
示例#3
0
        private MEDAQLibDLL.ERR_CODE Open()
        {
            if (_iSensor == 0)
            {
                return(MEDAQLibDLL.ERR_CODE.ERR_CANNOT_OPEN);
            }
            MEDAQLibDLL.ERR_CODE iRet = MEDAQLibDLL.ERR_CODE.ERR_NOERROR;
            iRet = MEDAQLibDLL.ClearAllParameters(_iSensor);
            if (iRet != MEDAQLibDLL.ERR_CODE.ERR_NOERROR)
            {
                throw new Exception("MEDAQLibDLL.ClearAllParameters");
            }

            SetParameterString("IP_Interface", "RS232");
            SetParameterString("IP_Port", Port.CommPort.ToString());

            //iRet = MEDAQLibDLL.SetParameterInt(_iSensor, "IP_Baudrate", (int)CommSettings.BaudRate);
            //if (iRet != MEDAQLibDLL.ERR_CODE.ERR_NOERROR)
            //{
            //    throw new Exception("SetParameterInt(IP_Baudrate)");
            //}

            //iRet = MEDAQLibDLL.SetParameterInt(_iSensor, "IP_Stopbits", (int)CommSettings.StopBits);
            //if (iRet != MEDAQLibDLL.ERR_CODE.ERR_NOERROR)
            //{
            //    throw new Exception("SetParameterInt(IP_Stopbits)");
            //}

            //iRet = MEDAQLibDLL.SetParameterInt(_iSensor, "IP_Parity", (int)CommSettings.Parity);
            //if (iRet != MEDAQLibDLL.ERR_CODE.ERR_NOERROR)
            //{
            //    throw new Exception("SetParameterInt(IP_Parity)");
            //}

            //iRet = MEDAQLibDLL.SetParameterInt(_iSensor, "IP_ByteSize", (int)CommSettings.DataLength);
            //if (iRet != MEDAQLibDLL.ERR_CODE.ERR_NOERROR)
            //{
            //    throw new Exception("SetParameterInt(IP_ByteSize)");
            //}

            iRet = MEDAQLibDLL.OpenSensor(_iSensor);
            if (iRet != MEDAQLibDLL.ERR_CODE.ERR_NOERROR)
            {
                throw new Exception(string.Format("OpenSensor {0}", Port.ToString()));
            }
            return(MEDAQLibDLL.ERR_CODE.ERR_NOERROR);
        }
示例#4
0
 private void SensorCommand(string cmd)
 {
     if (_iSensor == 0)
     {
         return;
     }
     SetParameterString("S_Command", cmd);
     lock (_lockCommands)
     {
         MEDAQLibDLL.ERR_CODE iRet = MEDAQLibDLL.ERR_CODE.ERR_NOERROR;
         iRet = MEDAQLibDLL.SensorCommand(_iSensor);
         if (iRet != MEDAQLibDLL.ERR_CODE.ERR_NOERROR)
         {
             throw new MCoreExceptionPopup("Error with SensorCommand : '{0}'", GetError());
         }
     }
 }
示例#5
0
        private int GetParameterInt(string paramName)
        {
            if (_iSensor == 0)
            {
                return(0);
            }
            int iVal = 0;

            lock (_lockCommands)
            {
                MEDAQLibDLL.ERR_CODE iRet = MEDAQLibDLL.GetParameterInt(_iSensor, paramName, ref iVal);
                if (iRet != MEDAQLibDLL.ERR_CODE.ERR_NOERROR)
                {
                    throw new MCoreExceptionPopup("Error with GetParameterInt('{0}' : '{1}'", paramName, GetError());
                }
            }
            return(iVal);
        }
示例#6
0
        /// <summary>
        /// Update the "Laser Level" data parameter
        /// </summary>
        /// <param name="input"></param>
        private void WaitForData(object sender, DoWorkEventArgs e)
        {
            while (!IsDestroying)
            {
                try
                {
                    switch (MEDAQLibDLL.WaitForSingleObject(_hSensorDataReady, 500))
                    {
                    case MEDAQLibDLL.WAIT_OBJECT_0:
                        lock (_waitMeasureDone)
                        {
                            double[] vals = GetData();
                            if (vals != null && vals.Length > 0)
                            {
                                double val = vals[vals.Length - 1];
                                MMInput.Value = val;
                                if (val != -1.0)
                                {
                                    _waitMeasureDone.Set();
                                }
                            }
                        }
                        break;

                    case MEDAQLibDLL.WAIT_TIMEOUT:
                        Thread.Sleep(20);
                        break;

                    case MEDAQLibDLL.WAIT_FAILED:
                        Thread.Sleep(20);
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    U.LogError(ex, "Problem reading sensor.");
                    Thread.Sleep(500);
                }
            }
            U.LogInfo("{0} thread completed.", Nickname);
        }
示例#7
0
        private UInt32 GetParameterDWORD(string paramName)
        {
            if (_iSensor == 0)
            {
                return(0);
            }
            UInt32 dword = 0;

            lock (_lockCommands)
            {
                MEDAQLibDLL.ERR_CODE iRet = MEDAQLibDLL.ERR_CODE.ERR_NOERROR;
                iRet = MEDAQLibDLL.GetParameterDWORD(_iSensor, paramName, ref dword);
                if (iRet != MEDAQLibDLL.ERR_CODE.ERR_NOERROR)
                {
                    throw new MCoreExceptionPopup("Error with GetParameterDWORD('{0}' : '{1}'", paramName, GetError());
                }
            }
            return(dword);
        }
示例#8
0
        private string GetParameterString(string paramName)
        {
            if (_iSensor == 0)
            {
                return(string.Empty);
            }
            string ret = string.Empty;

            lock (_lockCommands)
            {
                UInt32               iMaxLen = 1024;
                StringBuilder        sb      = new StringBuilder((int)iMaxLen);
                MEDAQLibDLL.ERR_CODE iRet    = MEDAQLibDLL.GetParameterString(_iSensor, paramName, sb, ref iMaxLen);
                if (iRet != MEDAQLibDLL.ERR_CODE.ERR_NOERROR)
                {
                    throw new MCoreExceptionPopup("Error with GetParameterString('{0}' : '{1}'", paramName, GetError());
                }
                ret = sb.ToString();
            }
            return(ret);
        }
示例#9
0
 /// <summary>
 /// Get the current data values
 /// </summary>
 /// <returns></returns>
 public double[] GetData()
 {
     lock (_lockCommands)
     {
         int iAvail = 0;
         int iRead  = 0;
         MEDAQLibDLL.ERR_CODE iRet = MEDAQLibDLL.DataAvail(_iSensor, ref iAvail);
         if (iRet == MEDAQLibDLL.ERR_CODE.ERR_NOERROR)
         {
             // Get no more than 10
             int      iMax        = System.Math.Min(iAvail, 10);
             int[]    iRawData    = new Int32[iMax];
             double[] dScaledData = new double[iMax];
             iRet = MEDAQLibDLL.TransferData(_iSensor, iRawData, dScaledData, iMax, ref iRead);
             if (iRet == MEDAQLibDLL.ERR_CODE.ERR_NOERROR)
             {
                 return(dScaledData);
             }
         }
     }
     return(null);
 }
示例#10
0
        /// <summary>
        /// Destroy this component
        /// </summary>
        public override void Destroy()
        {
            base.Destroy();  // Sets IsDestroying flag

            try
            {
                if (_iSensor != 0)
                {
                    if (_hSensorDataReady != 0)
                    {
                        // Complete worker thread
                        MEDAQLibDLL.SetEvent(_hSensorDataReady);
                        Thread.Sleep(50);
                    }
                    MEDAQLibDLL.CloseSensor(_iSensor);
                    MEDAQLibDLL.ReleaseSensorInstance(_iSensor);
                }
                if (_bw != null)
                {
                    if (_bw.IsBusy)
                    {
                        _bw.CancelAsync();
                    }
                    _bw.Dispose();
                    _bw = null;
                }
            }
            catch (Exception ex)
            {
                U.LogError(ex, "Error disposing '{0}'", Nickname);
            }
            finally
            {
                _bw = null;
            }
        }
示例#11
0
        /// <summary>
        /// Initialize this Component
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            // Initialize
            if (Simulate == eSimulate.SimulateDontAsk)
            {
                throw new ForceSimulateException("Always Simulate");
            }

            Port = GetParent <RS232>();
            if (Port == null)
            {
                throw new ForceSimulateException("MEDAQLib needs an RS232 parent");
            }

            try
            {
                _iSensor = MEDAQLibDLL.CreateSensorInstance(MEDAQLibDLL.ME_SENSOR.SENSOR_ILD1402);
                if (_iSensor == 0)
                {
                    throw new Exception("CreateSensorInstance: Error occured, no sensor created");
                }

                lock (_lockCommands)
                {
                    Open();
                }

                SetupGetInfo();
                SetupCallback();

                // Write to controller
                OnMeasurementRate(MeasurementRate);
                SetAverageParameters();
                OnExtInputMode(ExtInputMode);
                _mmInput = this.FilterByTypeSingle <MillimeterInput>();
                if (MMInput == null)
                {
                    throw new ForceSimulateException("MEDAQLib needs a MDoubleInput");
                }

                OnChangedExternalTrigger(_mmInput.ExternalTrigger);
                OnChangedTriggerMode(MMInput.TriggerMode);
                OnOutputTime(MMInput.TriggerInterval);

                U.RegisterOnChanged(() => MMInput.TriggerMode, OnChangedTriggerMode);
                U.RegisterOnChanged(() => MMInput.ExternalTrigger, OnChangedExternalTrigger);
                U.RegisterOnChanged(() => MMInput.TriggerInterval, OnOutputTime);
                U.RegisterOnChanged(() => MeasurementRate, OnMeasurementRate);
                U.RegisterOnChanged(() => MedianAvg, OnMedianAvg);
                U.RegisterOnChanged(() => MovingCount, OnMovingCount);
                U.RegisterOnChanged(() => MedianChoice, OnMedianChoice);
                U.RegisterOnChanged(() => ExtInputMode, OnExtInputMode);
                _bw.RunWorkerAsync();
                Simulate = eSimulate.None;
            }
            catch (ForceSimulateException fsex)
            {
                throw fsex;
            }
            catch (Exception ex)
            {
                throw new ForceSimulateException(ex);
            }
        }