/// <summary>///读取ADC通道/// </summary> public void ReadCanChannelLen() { var sedip = ConstUdpArg.GetDacChannelReadCommand(DisPlayWindow.Info.DacChannel - 1); Send(sedip, ConstUdpArg.Dst_ComMsgIp); ReceiveCanChannelLen(20); }
/// <summary>///读取延时信息/// </summary> public void ReadDelyTime() { var sedip = ConstUdpArg.GetDelayTimeReadCommand(DisPlayWindow.Info.DelayChannel); Send(sedip, ConstUdpArg.Dst_ComMsgIp); ReceiveChannelDeleyTime(20); }
/// <summary>存:ADC偏移</summary> /// <param name="data">数据8bit,[(配置值+1.2)/1.2]*128</param> public void SaveAdcOffset(byte data) { var addr = ConstUdpArg.GetAdcOffsetSave(DisPlayWindow.Info.AdcNum); var sendData = new byte[addr.Length + 1]; Array.Copy(addr, sendData, addr.Length); //最后一位是需要发送的数据 sendData.SetValue(data, sendData.Length - 1); Send(sendData, ConstUdpArg.Dst_ComMsgIp); }
/// 将接收到的数据显示到对应的界面上 /// 由于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); } }
/// <summary>存:DAC幅值</summary> /// <param name="data">数据8bit,[(配置值+1.2)/1.2]*128</param> public void SaveDacLen(byte[] data) { var cmd = ConstUdpArg.GetDacLenSaveCommand(int.Parse(DisPlayWindow.HMainWindow.tb_dacChannel.Text)); SaveData(cmd, data); }
/// <summary>存:延时通道</summary> /// <param name="data">数据8bit,[(配置值+1.2)/1.2]*128</param> public void SaveDelayTime(byte[] data) { var cmd = ConstUdpArg.GetDelayTimeSaveCommand(int.Parse(DisPlayWindow.HMainWindow.tb_deleyChannel.Text)); SaveData(cmd, data); }
/// <summary>写:脉冲宽度</summary> /// <param name="data">数据,16bit,配置值/5</param> public void WriteDelayTime(byte[] data) { var tmp = ConstUdpArg.GetDelayTimeWriteCommand(int.Parse(DisPlayWindow.HMainWindow.tb_deleyChannel.Text) - 1); WriteData(tmp, data); }
/// <summary>读取:ADC偏移</summary> public void ReadAdcOffset() { Send(ConstUdpArg.GetAdcOffsetRead(DisPlayWindow.Info.AdcNum), ConstUdpArg.Dst_ComMsgIp); ReceiveAdcOffset(19); }