コード例 #1
0
        /// <summary>///读取ADC通道/// </summary>
        public void ReadCanChannelLen()
        {
            var sedip = ConstUdpArg.GetDacChannelReadCommand(DisPlayWindow.Info.DacChannel - 1);

            Send(sedip, ConstUdpArg.Dst_ComMsgIp);
            ReceiveCanChannelLen(20);
        }
コード例 #2
0
        /// 将接收到的数据显示到对应的界面上
        /// 由于UDP返回数据包可能不是按发送命令顺序,此处增加识别处理
        /// <param name="cmd"></param>
        /// <param name="data"></param>
        void SetData(string cmd, byte[] data)
        {
            //得到发送指令后与ConstUdpArg中指令集对比,再将对应的数据处理后显示到界面上
            if (Encoding.ASCII.GetString(ConstUdpArg.Pulse_Period_Read, 0, 6).Equals(cmd)) //脉冲周期
            {
                int pulsePeriod = ToInt(data) * 5;
                Console.WriteLine("pulse_period={0}", pulsePeriod);
                DisPlayWindow.Info.PulsePeriod = pulsePeriod;
            }
            else if (Encoding.ASCII.GetString(ConstUdpArg.Pulse_Delay_Read, 0, 6).Equals(cmd)) //脉冲延时
            {
                int pulseDelay = ToInt(data) * 5;
                Console.WriteLine("pulse_delay={0}", pulseDelay);
                DisPlayWindow.Info.PulseDelay = pulseDelay;
            }
            else if (Encoding.ASCII.GetString(ConstUdpArg.Pulse_Width_Read, 0, 6).Equals(cmd)) //脉冲宽度
            {
                int pulseWidth = ToInt(data) * 5;
                Console.WriteLine("pulse_width={0}", pulseWidth);
                DisPlayWindow.Info.PulseWidth = pulseWidth;
            }
            else if (Encoding.ASCII.GetString(ConstUdpArg.GetAdcOffsetRead(DisPlayWindow.Info.AdcNum), 0, 6).Equals(cmd)) //ADC偏移
            {
                double adcOffset = data[0];
                adcOffset = adcOffset * 1.2 / 128 - 1.2;
                //AdcOffset.ToString("G3");
                Console.WriteLine("adc_offset={0}", adcOffset.ToString("G2"));
                DisPlayWindow.Info.AdcOffset = adcOffset.ToString("G2");
            }
            else if (Encoding.ASCII.GetString(ConstUdpArg.GetDelayTimeReadCommand(DisPlayWindow.Info.DelayChannel), 0, 6).Equals(cmd)) //延迟通道
            {
                byte t = data[0];
                data[0] = data[1];
                data[1] = t;
                int delaytime = BitConverter.ToUInt16(data, 0);
                DisPlayWindow.Info.DelayTime = delaytime;
            }
            else if (Encoding.ASCII.GetString(ConstUdpArg.GetDacChannelReadCommand(DisPlayWindow.Info.DacChannel - 1), 0, 6).Equals(cmd))
            //Dac数据
            {
                int result = data[0] * 256;
                result += data[1];
                DisPlayWindow.Info.DacLenth = result;
            }
            else
            {
//其他,未定义
                Console.WriteLine("cmd={0}", cmd);
            }
        }