コード例 #1
0
        private string GetCaliData()
        {
            try
            {
                //气体1,2,3,4判据数据 4*2*4字节
                byte[] gas_1_lowCC = BitConverter.GetBytes(Convert.ToSingle(gas_1_lowRangCC.Text));
                Array.Reverse(gas_1_lowCC);
                byte[] gas_1_highCC = BitConverter.GetBytes(Convert.ToSingle(gas_1_highRangCC.Text));
                Array.Reverse(gas_1_highCC);

                byte[] gas_2_lowCC = BitConverter.GetBytes(Convert.ToSingle(gas_2_lowRangCC.Text));
                Array.Reverse(gas_2_lowCC);
                byte[] gas_2_highCC = BitConverter.GetBytes(Convert.ToSingle(gas_2_highRangCC.Text));
                Array.Reverse(gas_2_highCC);

                byte[] gas_3_lowCC = BitConverter.GetBytes(Convert.ToSingle(gas_3_lowRangCC.Text));
                Array.Reverse(gas_3_lowCC);
                byte[] gas_3_highCC = BitConverter.GetBytes(Convert.ToSingle(gas_3_highRangCC.Text));
                Array.Reverse(gas_3_highCC);

                byte[] gas_4_lowCC = BitConverter.GetBytes(Convert.ToSingle(gas_4_lowRangCC.Text));
                Array.Reverse(gas_4_lowCC);
                byte[] gas_4_highCC = BitConverter.GetBytes(Convert.ToSingle(gas_4_highRangCC.Text));
                Array.Reverse(gas_4_highCC);

                return(cc_lPInfo.SelectedIndex.ToString("x2") + "0F" + ByteStrUtil.ByteToHexStr(gas_1_lowCC) + ByteStrUtil.ByteToHexStr(gas_1_highCC) + ByteStrUtil.ByteToHexStr(gas_2_lowCC) + ByteStrUtil.ByteToHexStr(gas_2_highCC) + ByteStrUtil.ByteToHexStr(gas_3_lowCC) + ByteStrUtil.ByteToHexStr(gas_3_highCC) + ByteStrUtil.ByteToHexStr(gas_4_lowCC) + ByteStrUtil.ByteToHexStr(gas_4_highCC));
            }
            catch
            {
                MessageBox.Show("请检查输入参数!");
                return("");
            }
        }
コード例 #2
0
 private void SetComm(object sender, Command command)
 {
     byte[] data = ByteStrUtil.HexToByte(command.Data);
     Dispatcher.Invoke(new Action(() =>
     {
         //解析光源信息字
         string[] lightSource       = ByteToBinary(data[0]);
         meamtObjType.SelectedIndex = int.Parse(lightSource[7]);
         lPType.SelectedIndex       = int.Parse(lightSource[6]);
         pixel.SelectedIndex        = Convert.ToInt32(lightSource[4] + lightSource[5], 2);
         sensorType.SelectedIndex   = int.Parse(lightSource[3]);
         lSType.SelectedIndex       = int.Parse(lightSource[2]);
         //设置控制电压参数
         byte[] vol = new byte[4];
         Array.Copy(data, 1, vol, 0, 4);
         Array.Reverse(vol, 0, vol.Length);
         lSControlVol.Text = BitConverter.ToSingle(vol, 0).ToString("f1");
         //解析双光路应用模式信息字
         string[] appModeInfo            = ByteToBinary(Convert.ToByte(data[5]));
         dualLPAppModeInfo.SelectedIndex = Convert.ToInt32(appModeInfo[6] + appModeInfo[7], 2);
         //调零对应浓度计算次数
         byte[] calTimes = new byte[2];
         Array.Copy(data, 6, calTimes, 0, 2);
         Array.Reverse(calTimes, 0, calTimes.Length);
         zeroConcCalTimes.Text = BitConverter.ToUInt16(calTimes, 0).ToString();
     }));
     ExceptionUtil.Instance.LogMethod("读取光谱仪公共参数成功");
 }
コード例 #3
0
 private string GetCommParamData()
 {
     try
     {
         //光源信息字 1字节
         string meamtObjTypeB = Convert.ToString(meamtObjType.SelectedIndex, 2);
         string lPTypeB       = Convert.ToString(lPType.SelectedIndex, 2);
         string pixelB        = Convert.ToString(pixel.SelectedIndex, 2);
         if (pixelB.Length == 1)
         {
             pixelB = "0" + pixelB;
         }
         string sensorTypeB = Convert.ToString(sensorType.SelectedIndex, 2);
         string lSTypeB     = Convert.ToString(lSType.SelectedIndex, 2);
         string lightSource = Convert.ToByte(lSTypeB + sensorTypeB + pixelB + lPTypeB + meamtObjTypeB, 2).ToString("x2").ToUpper();
         //光源控制电压 4字节
         byte[] controlVol = BitConverter.GetBytes(Convert.ToSingle(lSControlVol.Text));
         Array.Reverse(controlVol);
         //应用模式信息字 1字节
         string appModeInfoB = Convert.ToString(dualLPAppModeInfo.SelectedIndex, 2);
         string appModeInfo  = Convert.ToByte(appModeInfoB, 2).ToString("x2").ToUpper();
         //调零次数 2字节
         byte[] calTimes = BitConverter.GetBytes(Convert.ToUInt16(zeroConcCalTimes.Text));
         Array.Reverse(calTimes);
         return(lightSource + ByteStrUtil.ByteToHexStr(controlVol) + appModeInfo + ByteStrUtil.ByteToHexStr(calTimes));
     }
     catch
     {
         MessageBox.Show("请检查输入参数!");
         return("");
     }
 }
コード例 #4
0
        private void SetRange(object sender, Command command)
        {
            byte[] data = ByteStrUtil.HexToByte(command.Data);
            Dispatcher.Invoke(new Action(() =>
            {
                //设置气体1,2,3,4判据数据
                byte[] gas_1_crit = new byte[4];
                Array.Copy(data, 2, gas_1_crit, 0, 4);
                Array.Reverse(gas_1_crit, 0, gas_1_crit.Length);
                gas_1_critData.Text = BitConverter.ToSingle(gas_1_crit, 0).ToString();

                byte[] gas_2_crit = new byte[4];
                Array.Copy(data, 6, gas_2_crit, 0, 4);
                Array.Reverse(gas_2_crit, 0, gas_2_crit.Length);
                gas_2_critData.Text = BitConverter.ToSingle(gas_2_crit, 0).ToString();

                byte[] gas_3_crit = new byte[4];
                Array.Copy(data, 10, gas_3_crit, 0, 4);
                Array.Reverse(gas_3_crit, 0, gas_3_crit.Length);
                gas_3_critData.Text = BitConverter.ToSingle(gas_3_crit, 0).ToString();

                byte[] gas_4_crit = new byte[4];
                Array.Copy(data, 14, gas_4_crit, 0, 4);
                Array.Reverse(gas_4_crit, 0, gas_4_crit.Length);
                gas_4_critData.Text = BitConverter.ToSingle(gas_4_crit, 0).ToString();
            }));
            ExceptionUtil.Instance.LogMethod("读取光谱仪量程切换判据成功");
        }
コード例 #5
0
        /// <summary>
        /// CRC16校验
        /// </summary>
        /// <param name="hexByte">待校验数据</param>
        public static string CRC16(string hexByte)
        {
            byte[] data = ByteStrUtil.HexToByte(hexByte);
            int    len  = data.Length;

            byte[] result = new byte[] { 0, 0 };
            if (len > 0)
            {
                ushort crc = 0xFFFF;

                for (int i = 0; i < len; i++)
                {
                    crc = (ushort)(crc ^ (data[i]));
                    for (int j = 0; j < 8; j++)
                    {
                        crc = (crc & 1) != 0 ? (ushort)((crc >> 1) ^ 0xA001) : (ushort)(crc >> 1);
                    }
                }
                byte hi = (byte)((crc & 0xFF00) >> 8);  //高位置
                byte lo = (byte)(crc & 0x00FF);         //低位置

                result = new byte[] { lo, hi };
            }
            return(ByteStrUtil.ByteToHex(result));
        }
コード例 #6
0
        /// <summary>
        /// 得到一段光谱采集数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="command"></param>
        private void GetSpecData(object sender, Command command)
        {
            resetFlag  = false;
            errorCount = 0;
            byte[] data = ByteStrUtil.HexToByte(command.Data);
            if (data.Length == 1)
            {
                string msg = null;
                switch (data[0])
                {
                case 01:
                    msg = "另一通信口正在读取,请等待";
                    break;

                case 02:
                    msg = "数据没有准备好,请等待";
                    break;

                case 03:
                    msg = "没有处于读光谱数据模式,请等待";
                    break;

                case 04:
                    msg = "下传的当前拆分包号超限,请等待";
                    break;

                case 05:
                    msg = "读取本次光谱超时(时间间隔超时),请重新读取新的光谱数据";
                    break;
                }
                dataCache.ClearAllData();
                currentPackage = 1;
                ExceptionUtil.Instance.ExceptionMethod(msg, true);
                return;
            }
            currentPackage = data[3];
            if (currentPackage < data[4])
            {
                //缓存
                byte[] bytes = new byte[data.Length - 5];
                Array.Copy(data, 5, bytes, 0, bytes.Length);
                dataCache.AddDataArray(bytes);
                //再发送
                currentPackage++;
                SendSpecCmn(lightPath, dataType);
            }
            else if (currentPackage == data[4])
            {
                //添加最后一段数据
                byte[] bytes = new byte[data.Length - 5];
                Array.Copy(data, 5, bytes, 0, bytes.Length);
                dataCache.AddDataArray(bytes);
                //存储本次数据
                currentPackage = 1;
                //从缓存中取出所有数据并解析
                ParseSpecData(dataCache.GetAllData(true));
            }
        }
コード例 #7
0
        /// <summary>
        /// 接收向量数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="command"></param>
        private void GetVectorInfo(object sender, Command command)
        {
            resetFlag  = false;
            errorCount = 0;
            byte[] data = ByteStrUtil.HexToByte(command.Data);
            if (data.Length == 1)
            {
                string msg = null;
                switch (data[0])
                {
                case 01:
                    msg = "另一通信口正在读取,请等待";
                    break;

                case 02:
                    msg = "下传的当前拆分包号超限";
                    break;

                case 03:
                    msg = "读取本次向量超时(时间间隔超时),请重新读取";
                    break;
                }
                vectorInfoQueue.Clear();
                currentPackage = 1;
                ExceptionUtil.Instance.ExceptionMethod(msg, true);
                return;
            }
            currentPackage = data[4];
            if (currentPackage < data[5])
            {
                //缓存
                byte[] bytes = new byte[data.Length - 6];
                Array.Copy(data, 6, bytes, 0, bytes.Length);
                foreach (byte b in bytes)
                {
                    vectorInfoQueue.Enqueue(b);
                }
                //再发送
                currentPackage++;
                SendVectorCmn(null, null, null, null);
            }
            else if (currentPackage == data[4])
            {
                //添加最后一段数据
                byte[] bytes = new byte[data.Length - 6];
                Array.Copy(data, 6, bytes, 0, bytes.Length);
                foreach (byte b in bytes)
                {
                    vectorInfoQueue.Enqueue(b);
                }
                currentPackage = 1;
                //从缓存中取出所有数据并解析
                byte[] datas = vectorInfoQueue.ToArray();
                vectorInfoQueue.Clear();
                ParseVectorData(datas);
            }
        }
コード例 #8
0
        private void Measure()
        {
            //光谱采集与算法生成
            SpecOperatorImpl.Instance.SendSpecCmn(lightPath, specType);
            //浓度测量
            string data = lightPath + ByteStrUtil.ByteToHexStr(tempValues) + ByteStrUtil.ByteToHexStr(pressValues);

            SuperSerialPort.Instance.Send(new Command {
                Cmn = "29", ExpandCmn = "55", Data = data
            }, true);
        }
コード例 #9
0
 /// <summary>
 /// 读取间隔订阅
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="command"></param>
 public void SetReadInterval(object sender, Command command)
 {
     byte[] data         = ByteStrUtil.HexToByte(command.Data);
     byte[] timeInterval = new byte[2];
     if (data[1] == 09)
     {
         Array.Copy(data, 2, timeInterval, 0, 2);
         Array.Reverse(timeInterval, 0, 2);
         Dispatcher.Invoke(new Action(() =>
         {
             ReadInterval.Text = BitConverter.ToUInt16(timeInterval, 0).ToString();
         }));
     }
 }
コード例 #10
0
        private void SetCali(object sender, Command command)
        {
            byte[] data = ByteStrUtil.HexToByte(command.Data);
            Dispatcher.Invoke(new Action(() =>
            {
                //设置气体1,2,3,4标定系数
                byte[] gas_1_lowCC = new byte[4];
                Array.Copy(data, 2, gas_1_lowCC, 0, 4);
                Array.Reverse(gas_1_lowCC, 0, gas_1_lowCC.Length);
                gas_1_lowRangCC.Text = BitConverter.ToSingle(gas_1_lowCC, 0).ToString("f3");
                byte[] gas_1_highCC  = new byte[4];
                Array.Copy(data, 6, gas_1_highCC, 0, 4);
                Array.Reverse(gas_1_highCC, 0, gas_1_highCC.Length);
                gas_1_highRangCC.Text = BitConverter.ToSingle(gas_1_highCC, 0).ToString("f3");

                byte[] gas_2_lowCC = new byte[4];
                Array.Copy(data, 10, gas_2_lowCC, 0, 4);
                Array.Reverse(gas_2_lowCC, 0, gas_2_lowCC.Length);
                gas_2_lowRangCC.Text = BitConverter.ToSingle(gas_2_lowCC, 0).ToString("f3");
                byte[] gas_2_highCC  = new byte[4];
                Array.Copy(data, 14, gas_2_highCC, 0, 4);
                Array.Reverse(gas_2_highCC, 0, gas_2_highCC.Length);
                gas_2_highRangCC.Text = BitConverter.ToSingle(gas_2_highCC, 0).ToString("f3");

                byte[] gas_3_lowCC = new byte[4];
                Array.Copy(data, 18, gas_3_lowCC, 0, 4);
                Array.Reverse(gas_3_lowCC, 0, gas_3_lowCC.Length);
                gas_3_lowRangCC.Text = BitConverter.ToSingle(gas_3_lowCC, 0).ToString("f3");
                byte[] gas_3_highCC  = new byte[4];
                Array.Copy(data, 22, gas_1_highCC, 0, 4);
                Array.Reverse(gas_3_highCC, 0, gas_3_highCC.Length);
                gas_3_highRangCC.Text = BitConverter.ToSingle(gas_3_highCC, 0).ToString("f3");

                byte[] gas_4_lowCC = new byte[4];
                Array.Copy(data, 26, gas_4_lowCC, 0, 4);
                Array.Reverse(gas_4_lowCC, 0, gas_4_lowCC.Length);
                gas_4_lowRangCC.Text = BitConverter.ToSingle(gas_4_lowCC, 0).ToString("f3");
                byte[] gas_4_highCC  = new byte[4];
                Array.Copy(data, 30, gas_4_highCC, 0, 4);
                Array.Reverse(gas_4_highCC, 0, gas_4_highCC.Length);
                gas_1_highRangCC.Text = BitConverter.ToSingle(gas_4_highCC, 0).ToString("f3");
            }));
            ExceptionUtil.Instance.LogMethod("读取光谱仪标定系数成功");
        }
コード例 #11
0
 private string GetRangeSwitchData()
 {
     try
     {
         //气体1,2,3,4判据数据 4*4字节
         byte[] gas_1_crit = BitConverter.GetBytes(Convert.ToSingle(gas_1_critData.Text));
         Array.Reverse(gas_1_crit);
         byte[] gas_2_crit = BitConverter.GetBytes(Convert.ToSingle(gas_2_critData.Text));
         Array.Reverse(gas_2_crit);
         byte[] gas_3_crit = BitConverter.GetBytes(Convert.ToSingle(gas_3_critData.Text));
         Array.Reverse(gas_3_crit);
         byte[] gas_4_crit = BitConverter.GetBytes(Convert.ToSingle(gas_4_critData.Text));
         Array.Reverse(gas_4_crit);
         return(rs_lpInfo.SelectedIndex.ToString("x2") + "0F" + ByteStrUtil.ByteToHexStr(gas_1_crit) + ByteStrUtil.ByteToHexStr(gas_2_crit) + ByteStrUtil.ByteToHexStr(gas_3_crit) + ByteStrUtil.ByteToHexStr(gas_4_crit));
     }
     catch
     {
         MessageBox.Show("请检查输入参数!");
         return("");
     }
 }
コード例 #12
0
 private void SetLightPath(object sender, Command command)
 {
     byte[] data = ByteStrUtil.HexToByte(command.Data);
     if ("0F".Equals(data[1].ToString("x2").ToUpper()))
     {
         Dispatcher.Invoke(new Action(() =>
         {
             //光路信息,组分信息
             alpp_lPInfo.SelectedIndex = data[0];
             compntInfo.SelectedIndex  = data[2];
             //量程信息
             string[] rangeInfo_1             = ByteToBinary(data[3]);
             gas_liquid_1_range.SelectedIndex = int.Parse(rangeInfo_1[7]);
             gas_liquid_2_range.SelectedIndex = int.Parse(rangeInfo_1[4]);
             string[] rangeInfo_2             = ByteToBinary(data[4]);
             gas_liquid_3_range.SelectedIndex = int.Parse(rangeInfo_2[7]);
             gas_liquid_4_range.SelectedIndex = int.Parse(rangeInfo_1[4]);
             //光谱平均次数,浓度滑动平均次数,零点平均次数,标定平均次数,打灯次数
             specATs.Text     = data[5].ToString();
             concSlidATs.Text = data[6].ToString();
             zeroATs.Text     = data[7].ToString();
             caliATs.Text     = data[8].ToString();
             lightTimes.Text  = data[9].ToString();
             //积分时间,采样时间间隔,光路切换时间间隔
             byte[] integrTime = new byte[2];
             Array.Copy(data, 10, integrTime, 0, 2);
             Array.Reverse(integrTime, 0, integrTime.Length);
             integTime.Text    = BitConverter.ToUInt16(integrTime, 0).ToString();
             byte[] samplInter = new byte[2];
             Array.Copy(data, 12, samplInter, 0, 2);
             Array.Reverse(samplInter, 0, samplInter.Length);
             samplInterval.Text   = BitConverter.ToUInt16(samplInter, 0).ToString();
             byte[] lPSwitchInter = new byte[2];
             Array.Copy(data, 14, lPSwitchInter, 0, 2);
             Array.Reverse(lPSwitchInter, 0, lPSwitchInter.Length);
             lPSwitchInterval.Text = BitConverter.ToUInt16(lPSwitchInter, 0).ToString();
         }));
         ExceptionUtil.Instance.LogMethod("读取光谱仪所有光路参数成功");
     }
 }
コード例 #13
0
 private string GetLPParamData()
 {
     try
     {
         //光路信息 1字节
         string lPInfo = "0" + alpp_lPInfo.SelectedIndex.ToString();
         //组分信息 1字节
         string compntInfoB = Convert.ToString(compntInfo.SelectedIndex, 2);
         string comptInfo   = Convert.ToByte(compntInfoB, 2).ToString("x2").ToUpper();
         //量程信息字一 1字节
         string range_1    = Convert.ToString(gas_liquid_1_range.SelectedIndex, 2);
         string range_2    = Convert.ToString(gas_liquid_2_range.SelectedIndex, 2);
         string rangeInfo1 = Convert.ToByte("00" + range_2 + "00" + range_1, 2).ToString("x2").ToUpper();
         //量程信息字二 1字节
         string range_3    = Convert.ToString(gas_liquid_3_range.SelectedIndex, 2);
         string range_4    = Convert.ToString(gas_liquid_4_range.SelectedIndex, 2);
         string rangeInfo2 = Convert.ToByte("00" + range_4 + "00" + range_3, 2).ToString("x2").ToUpper();
         //光谱平均次数,浓度滑动平均次数,零点平均次数,标定平均次数,打灯次数 各1字节
         string sATs  = Convert.ToByte(specATs.Text).ToString("x2");
         string coATs = Convert.ToByte(concSlidATs.Text).ToString("x2");
         string zATs  = Convert.ToByte(zeroATs.Text).ToString("x2");
         string caATs = Convert.ToByte(caliATs.Text).ToString("x2");
         string lTs   = Convert.ToByte(lightTimes.Text).ToString("x2");
         //积分时间,采样时间间隔,光路切换时间间隔 各2字节
         byte[] integrTimes = BitConverter.GetBytes(Convert.ToUInt16(integTime.Text));
         Array.Reverse(integrTimes);
         byte[] samplInter = BitConverter.GetBytes(Convert.ToUInt16(samplInterval.Text));
         Array.Reverse(samplInter);
         byte[] lPSwitchInter = BitConverter.GetBytes(Convert.ToUInt16(lPSwitchInterval.Text));
         Array.Reverse(lPSwitchInter);
         return(lPInfo + "0F" + comptInfo + rangeInfo1 + rangeInfo2 + sATs + coATs + zATs + caATs + lTs + ByteStrUtil.ByteToHexStr(integrTimes) + ByteStrUtil.ByteToHexStr(samplInter) + ByteStrUtil.ByteToHexStr(lPSwitchInter));
     }
     catch
     {
         MessageBox.Show("请检查输入参数!");
         return("");
     }
 }
コード例 #14
0
        /// <summary>
        /// 设置上传向量表信息
        /// </summary>
        /// <param name="fileName">向量文件路径</param>
        public void SetVectorInfo(string lpInfo, string gas, string range, string fileName)
        {
            try
            {
                ushort      startAddr  = 0;
                ushort      offset     = 0;
                int         coeffiNum  = 0;
                int         pixel      = 512;
                List <byte> data       = new List <byte>();
                FileInfo    file       = new FileInfo(fileName);
                TextReader  textReader = file.OpenText();
                string[]    text       = textReader.ReadToEnd().Split('\n');
                for (int i = 0; i < text.Length; i++)
                {
                    text[i] = text[i].Replace("\n", "").Replace("\t", "").Replace("\r", "").Replace(" ", "");
                }
                //设备号
                data = AddByte(data, Encoding.Default.GetBytes(text[0]));
                //14项基本数据
                for (int i = 0; i < 13; i++)
                {
                    if (i == 3 || i == 4)
                    {
                        //温度|| 压力 4字节
                        byte[] bytes = BitConverter.GetBytes(Convert.ToSingle(text[i + 1]));
                        Array.Reverse(bytes);
                        data = AddByte(data, bytes);
                    }
                    else if (i == 6 || i == 11)
                    {
                        //光程||压缩后的向量数据个数 2字节
                        byte[] bytes = BitConverter.GetBytes(Convert.ToUInt16(text[i + 1]));
                        Array.Reverse(bytes);
                        data = AddByte(data, bytes);
                        //另取得偏移量
                        if (i == 11)
                        {
                            offset = (ushort)(Convert.ToInt32(text[i + 1]) - 1);
                        }
                    }
                    else
                    {
                        //1字节
                        data.Add(byte.Parse(text[i + 1]));
                        //另取得像素个数
                        if (i == 2)
                        {
                            switch (Convert.ToInt32(text[i + 1]))
                            {
                            case 0:
                                pixel = 256;
                                break;

                            case 2:
                                pixel = 1024;
                                break;

                            case 3:
                                pixel = 2048;
                                break;
                            }
                        }
                        //另取得系数个数
                        else if (i == 12)
                        {
                            coeffiNum = Convert.ToInt32(text[i + 1]);
                        }
                    }
                }
                //起始地址
                string[] vectorData = new string[pixel];
                Array.Copy(text, 14, vectorData, 0, vectorData.Length);
                foreach (string s in vectorData)
                {
                    try
                    {
                        Convert.ToInt32(s);
                    }
                    catch
                    {
                        break;
                    }
                    startAddr++;
                }
                byte[] reStartAddr = BitConverter.GetBytes(startAddr);
                Array.Reverse(reStartAddr);
                data = AddByte(data, reStartAddr);
                //偏移量
                byte[] reOffset = BitConverter.GetBytes(offset);
                Array.Reverse(reOffset);
                data = AddByte(data, reOffset);
                //压缩后的数据
                for (int i = 0; i < offset; i++)
                {
                    byte[] reVD = BitConverter.GetBytes(Convert.ToSingle(vectorData[startAddr + i]));
                    Array.Reverse(reVD);
                    data = AddByte(data, reVD);
                }
                //系数
                string[] coefficient = new string[coeffiNum];
                Array.Copy(text, 526, coefficient, 0, coeffiNum);
                foreach (string coe in coefficient)
                {
                    byte[] reCoe = BitConverter.GetBytes(Convert.ToSingle(coe));
                    Array.Reverse(reCoe);
                    data = AddByte(data, reCoe);
                }
                string datas = ByteStrUtil.ByteToHex(data.ToArray());
                int    pkgNum = (int)Math.Ceiling((double)datas.Length / 512);
                int    startIndex = 0, length = 512;
                for (int currPkgNum = 1; currPkgNum <= pkgNum; currPkgNum++)
                {
                    if (currPkgNum < pkgNum)
                    {
                        SuperSerialPort.Instance.Send(new Command
                        {
                            Cmn       = "2C",
                            ExpandCmn = "66",
                            Data      = lpInfo + gas + range + currPkgNum.ToString("x2") + pkgNum.ToString("x2") + datas.Substring(startIndex, length)
                        }, true);
                        startIndex = length * currPkgNum;
                        Thread.Sleep(DefaultArgument.INTERVAL_TIME);
                    }
                    else
                    {
                        SuperSerialPort.Instance.Send(new Command
                        {
                            Cmn       = "2C",
                            ExpandCmn = "66",
                            Data      = lpInfo + gas + range + currPkgNum.ToString("x2") + pkgNum.ToString("x2") + datas.Substring(startIndex)
                        }, true);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionUtil.Instance.ExceptionMethod(ex.Message, true);
            }
        }
コード例 #15
0
        /// <summary>
        /// 转发分配实现
        /// </summary>
        /// <param name="command"></param>
        public void DataForwardMethod(Command command)
        {
            //读回应
            if (command.ExpandCmn == "AA")
            {
                switch (command.Cmn)
                {
                case "20":
                    ReadCommParam(this, command);
                    break;

                case "21":
                    ReadLPParam(this, command);
                    break;

                case "24":
                    ReadSpecData(this, command);
                    break;

                case "25":
                    ReadDeviceNo(this, command);
                    break;

                case "26":
                    ReadRangeSwitch(this, command);
                    break;

                case "27":
                    ReadZeroParam(this, command);
                    break;

                case "28":
                    ReadCaliParam(this, command);
                    break;

                case "29":
                    ReadConcMeasure(this, command);
                    break;

                case "2C":
                    ReadVectorInfo(this, command);
                    break;

                default:
                    break;
                }
            }
            //写回应
            if (command.ExpandCmn == "99")
            {
                switch (command.Data)
                {
                case "88":
                    ExceptionUtil.Instance.LogMethod("设置成功");
                    //Console.WriteLine("设置成功");
                    break;

                case "99":
                    ExceptionUtil.Instance.ExceptionMethod("设置失败", true);
                    //Console.WriteLine("设置失败");
                    break;

                default:
                    byte[] data = ByteStrUtil.HexToByte(command.Data);
                    if (data.Length == 6 && data[3] == data[4])
                    {
                        switch (data[5])
                        {
                        case 0x88:
                            ExceptionUtil.Instance.LogMethod("设置成功");
                            //Console.WriteLine("设置成功");
                            break;

                        case 0x99:
                            ExceptionUtil.Instance.ExceptionMethod("设置失败", true);
                            //Console.WriteLine("设置失败");
                            break;

                        case 0xAA:
                            ExceptionUtil.Instance.ExceptionMethod("向量更新失败,全部重传", true);
                            //Console.WriteLine("向量更新失败,全部重传");
                            break;
                        }
                    }
                    break;
                }
            }
        }
コード例 #16
0
 /// <summary>
 /// 设置光谱仪设备号
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="command"></param>
 private void SetDeviceNo(object sender, Command command)
 {
     byte[] deviceNo = ByteStrUtil.HexToByte(command.Data);
     this.deviceNo = Encoding.Default.GetString(deviceNo).ToUpper();
     MessageBox.Show("Copyright © 天津七一二通信广播股份有限公司\n光谱仪软件版本:" + this.deviceNo, "关于系统", MessageBoxButton.OK, MessageBoxImage.Information);
 }
        private void GetConcMeasureData(object sender, Command command)
        {
            try
            {
                byte[] data       = ByteStrUtil.HexToByte(command.Data);
                byte   statusCode = data[1];
                string msg        = string.Empty;
                bool   error      = true;
                switch (statusCode)
                {
                case 01:
                    msg = "设备正在调零,请等待";
                    break;

                case 02:
                    msg = "设备正在标定,请等待";
                    break;

                case 03:
                    msg = "光谱数据读取中,请等待";
                    break;

                case 04:
                    msg = "设备维护中...";
                    break;

                case 05:
                    msg = "设备故障";
                    break;

                case 0xAA:
                    msg = "设备待机中";
                    break;

                default:
                    error = false;
                    break;
                }
                if (error)
                {
                    ExceptionUtil.Instance.ExceptionMethod(msg, true);
                    return;
                }
                List <float> concList  = new List <float>();
                byte[]       pressData = new byte[4];
                byte[]       tempData  = new byte[4];
                Array.Copy(data, 7, tempData, 0, 4);
                Array.Copy(data, 11, pressData, 0, 4);
                byte[] concData = new byte[data.Length - 15];
                Array.Copy(data, 15, concData, 0, data.Length - 15);
                for (int i = 0; i < concData.Length / 10; i++)
                {
                    byte[] conc = new byte[4];
                    Array.Copy(concData, 10 * i + 6, conc, 0, 4);
                    Array.Reverse(conc);
                    concList.Add(BitConverter.ToSingle(conc, 0));
                }
                Array.Reverse(pressData);
                Array.Reverse(tempData);
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    UpadateUI(concList, BitConverter.ToSingle(pressData, 0), BitConverter.ToSingle(tempData, 0));
                }));
                concentrationPage.UpdateChart(concList);
            }
            catch (Exception e)
            {
                ExceptionUtil.Instance.ExceptionMethod(e.Message, true);
            }
        }