Esempio n. 1
0
        private bool DoCalcStep(Int16[] scaleList)
        {
            Int16[] chValues  = new Int16[100];
            Int16[] refValues = new Int16[100];


            DateTime startTime = DateTime.Now;

            AppendText(this.txtMessage, String.Format("开始读取模拟量,按任意键退出\r\n"));
            waitKey.Reset();
            while ((DateTime.Now - startTime).TotalSeconds < 10)
            {
                if (!Funs485.RdAllCh(cardAddr, out chValues))
                {
                    AppendText(this.txtMessage, String.Format("读取板{0}模拟量数据失败\r\n", cardAddr));
                    return(false);
                }
                if (!Funs485.RdAllCh(refCardNo, out refValues))
                {
                    refValues = new Int16[chValues.Length];
                    for (int i = 0; i < refValues.Length; i++)
                    {
                        refValues[i] = (Int16)Math.Round(realVal);
                    }
                    // AppendText(this.txtMessage, String.Format("读取板{0}模拟量数据失败", cardAddr));
                    //  return false;
                }
                if (chValues.Length != refValues.Length)
                {
                    AppendText(this.txtMessage, String.Format("基准板与待校准板不一致"));
                    return(false);
                }
                for (int i = 0; i < chValues.Length; i++)
                {
                    chValues[i] = (Int16)(chValues[i] & 0x7fff);
                }
                chValues.CopyTo(WaitCalcValues, 0);
                refValues.CopyTo(RefValues, 0);
                InvalidateCtrl(this.gridValueView);
                if (waitKey.WaitOne(0, true))
                {
                    break;
                }
            }
            for (int i = 0; i < chValues.Length; i++)
            {
                double coef    = scaleList[i * 2 + 1] * 1.0;
                float  refVal  = refValues[i];
                float  realVal = chValues[i];
                coef = coef * refVal;
                coef = coef / realVal;
                // coef *= coef * refVal /realVal;
                scaleList[i * 2 + 1] = (Int16)Math.Round(coef);
            }
            scaleList.CopyTo(CoeffValues, 0);
            InvalidateCtrl(this.gridValueView);
            return(true);
        }
Esempio n. 2
0
        public float[] RunSweepMode(Int64 nBaseFrequency,
                                    Int64 nFrequencyStep,
                                    int nCount,
                                    bool bUseInear          = false,
                                    CBackNotifier Notifier  = null,
                                    BackgroundWorker Worker = null,
                                    Int16[] NativeDatas     = null,
                                    bool bUseRawMode        = false,
                                    UInt16 RawModeBase      = 500)
        {
            int nSubBlockSize = 9999;
            int nPass         = nCount / nSubBlockSize;
            int nRest         = nCount % nSubBlockSize;

            float[] fullBuffer = new float[nCount];

            port.DiscardInBuffer();
            port.DiscardOutBuffer();

            port.ReadTimeout = DeviceDef.AcquisitionTimeout;


            for (int nFullBlock = 0; nFullBlock < nPass; nFullBlock++)
            {
                int      nOffset       = nFullBlock * nSubBlockSize;
                Int16[]  SubNativeData = new Int16[nSubBlockSize];
                float [] fSubBuffer    = RunSweepModeBlock(nBaseFrequency + nOffset * nFrequencyStep, nFrequencyStep, nSubBlockSize, nCount, nOffset, bUseInear, Notifier, Worker, SubNativeData, bUseRawMode, RawModeBase);
                fSubBuffer.CopyTo(fullBuffer, nOffset);

                if (NativeDatas != null)
                {
                    SubNativeData.CopyTo(NativeDatas, nOffset);
                }
            }

            if (nRest > 0)
            {
                int     nOffset       = nPass * nSubBlockSize;
                Int16[] SubNativeData = new Int16[nRest];
                float[] fSubBuffer    = RunSweepModeBlock(nBaseFrequency + nOffset * nFrequencyStep, nFrequencyStep, nRest, nCount, nOffset, bUseInear, Notifier, Worker, SubNativeData, bUseRawMode, RawModeBase);
                fSubBuffer.CopyTo(fullBuffer, nOffset);

                if (NativeDatas != null)
                {
                    SubNativeData.CopyTo(NativeDatas, nOffset);
                }
            }

            if (Notifier != null)
            {
                Notifier.SendProgress(0, 0.0f);
            }

            return(fullBuffer);
        }
Esempio n. 3
0
        private bool DoAmpliTstStep(int step, Int16[] scaleList)
        {
            Int16[] chValues  = new Int16[100];
            Int16[] refValues = new Int16[100];
            sigSource.SetAmpli(ampliTable[step] * freqFullValues[step]);
            DateTime startTime = DateTime.Now;

            AppendText(this.txtMessage, String.Format("读值稳定后按任意键进入下一个幅度\r\n"));
            waitKey.Reset();
            while ((DateTime.Now - startTime).TotalSeconds < 10)
            {
                if (!Funs485.RdAllCh(cardAddr, out chValues))
                {
                    AppendText(this.txtMessage, String.Format("读取板{0}模拟量数据失败", cardAddr));
                    return(false);
                }
                if (!Funs485.RdAllCh(refCardNo, out refValues))
                {
                    AppendText(this.txtMessage, String.Format("读取板{0}模拟量数据失败", cardAddr));
                    return(false);
                }
                if (chValues.Length != refValues.Length)
                {
                    AppendText(this.txtMessage, String.Format("基准板与待校准板不一致"));
                    return(false);
                }
                chValues.CopyTo(WaitCalcValues, 0);
                refValues.CopyTo(RefValues, 0);
                InvalidateCtrl(this.gridValueView);
                if (waitKey.WaitOne(0, true))
                {
                    break;
                }
            }
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("幅度误差测试{0}:", step);
            for (int i = 0; i < chValues.Length / 3; i++)
            {
                float refVal  = refValues[i * 3];
                float realVal = chValues[i * 3];
                sb.AppendFormat("{0}/{1}/{2}%,", realVal, refVal, realVal * 100 / refVal);
            }
            sb.AppendLine();
            AppendText(this.txtMessage, sb.ToString());
            WriteToFile(sb.ToString());
            scaleList.CopyTo(CoeffValues, 0);
            InvalidateCtrl(this.gridValueView);
            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// make and send IO Frame to PLC
        /// </summary>
        /// <param name="diot"></param>
        /// <param name="data"></param>
        public void plc_send_IO(DataIOType diot, Int16[] data)
        {
            if (_plc != null)
            {
                Int16[] start    = new Int16[] { Index, (Int16)diot };
                Int16[] complete = new Int16[start.Length + data.Length];
                start.CopyTo(complete, 0);
                data.CopyTo(complete, start.Length);

                Frame f = new Frame(_plc.getClient(), complete);
                f.SetHeaderFlag(FrameHeaderFlag.PdataIO);
                _plc.send(f);
            }
        }
Esempio n. 5
0
        private bool DoCalcStep(int step, Int16[] scaleList)
        {
            Int16[] chValues  = new Int16[100];
            Int16[] refValues = new Int16[100];
            SetFreq(step);

            DateTime startTime = DateTime.Now;

            AppendText(this.txtMessage, String.Format("开始校准频率{0},读值稳定后按任意键进入下一个频率\r\n", freqNameList[step]));
            waitKey.Reset();
            while ((DateTime.Now - startTime).TotalSeconds < 10)
            {
                if (!Funs485.RdAllCh(cardAddr, out chValues))
                {
                    AppendText(this.txtMessage, String.Format("读取板{0}模拟量数据失败", cardAddr));
                    return(false);
                }
                if (!Funs485.RdAllCh(refCardNo, out refValues))
                {
                    AppendText(this.txtMessage, String.Format("读取板{0}模拟量数据失败", cardAddr));
                    return(false);
                }
                if (chValues.Length != refValues.Length)
                {
                    AppendText(this.txtMessage, String.Format("基准板与待校准板不一致"));
                    return(false);
                }
                chValues.CopyTo(WaitCalcValues, 0);
                refValues.CopyTo(RefValues, 0);
                InvalidateCtrl(this.gridValueView);
                if (waitKey.WaitOne(0, true))
                {
                    break;
                }
            }
            for (int i = 0; i < chValues.Length / 3; i++)
            {
                double coef    = scaleList[i * 4 + step] * 1.0;
                float  refVal  = refValues[i * 3];
                float  realVal = chValues[i * 3];
                coef = coef * refVal;
                coef = coef / realVal;
                // coef *= coef * refVal /realVal;
                scaleList[i * 4 + step] = (Int16)Math.Round(coef);
            }
            scaleList.CopyTo(CoeffValues, 0);
            InvalidateCtrl(this.gridValueView);
            return(true);
        }