123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635 |
- using System;
- using System.Windows.Forms;
- using Uni_Trend.MSO7000X.Common.Helper;
- using System.Linq;
- using System.Collections;
- using System.Collections.Generic;
- using Uni_Trend.MSO7000X.UserControls;
- using Uestc.Auto6.Dso.Core;
- using Uestc.Auto6.Dso.ComModel;
- using Uestc.Auto6.Dso.Core.Decode;
- using Uni_Trend.MSO7000X.Language;
- using System.Reflection;
- namespace Uestc.Auto6.Dso.Protocol.RS232
- {
- public partial class RS232SetControl : UserControl, IProtocolView
- {
- public RS232SetControl()
- {
- InitializeComponent();
- InitView();
- }
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- Init();
- }
- private void InitView()
- {
- Int32 rowcount = 1;
- Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.StyleManager.Instance.RegisterControl(x));
- this.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance).Where(x => x.GetCustomAttribute<RowColAttribute>() != null && x.GetValue(this) is Control).Select(x =>
- {
- RowColAttribute attribute = x.GetCustomAttribute<RowColAttribute>();
- Control control = x.GetValue(this) as Control;
- return (attribute, control);
- }).GroupBy(x => x.attribute, (x => x.control)).ToList().ForEach(x =>
- {
- Control lable = x.First(x => x is UestcLabel);
- Control control = x.First(x => !(x is UestcLabel));
- lable.Left = Width / _ColnumCount * x.Key.Colnum;
- lable.Width = control.Width;
- lable.Height = lable.Font.Height;
- lable.Top = 10 + _RowHeight * x.Key.Row;
- control.Left = lable.Left;
- control.Top = lable.Bottom + 2;
- lable.Width = 120;
- if (control is UIRadioButtonGroup)
- control.Width = 140;
- else
- control.Width = 120;
- rowcount = Math.Max(rowcount, x.Key.Row + 1);
- });
- Height = rowcount * _RowHeight;
- }
- private void Init()
- {
- GetDestinPrsnt();
- InitSignalType();
- InitSource();
- InitSourceL();
- InitBiteRate();
- InitRealBiteRate();
- InitDataBits();
- InitByteOrder();
- InitStopBits();
- InitParity();
- InitThreshold();
- InitPolarity();
- }
- /// <summary>
- /// 获取需要同步的Prsnt
- /// 当<see cref="DestinDecodePrsnt"/>为<see cref="null"/>时表示不需要与其他Prsnt进行同步
- /// </summary>
- private void GetDestinPrsnt()
- {
- if (_RS232DecodePrsnt == null)
- return;
- if (_RS232DecodePrsnt.IsTrigger)
- DestinDecodePrsnt = Presenter.GetChannlesDecodePrsnt().Where(x => x is RS232DecodePrsnt).Cast<RS232DecodePrsnt>().Where(x => x.ChannelId == _RS232DecodePrsnt.ChannelId).OrderBy(x => x.ChannelL).FirstOrDefault();
- else
- {
- if (Presenter.GetTriggerDecodePrsnt() is RS232DecodePrsnt rs232decodePrsnt && rs232decodePrsnt.ChannelId == _RS232DecodePrsnt.ChannelId)
- DestinDecodePrsnt = rs232decodePrsnt;
- else
- DestinDecodePrsnt = null;
- }
- }
- #region 属性定义
- protected new Boolean DesignMode
- {
- get
- {
- Boolean rtnflag = false;
- #if DEBUG
- rtnflag = DesignTimeHelper.InDesignMode(this);
- #endif
- return rtnflag;
- }
- }
- private RS232DecodePrsnt DestinDecodePrsnt
- {
- get => _DestinDecodePrsnt;
- set
- {
- if (_DestinDecodePrsnt != value)
- {
- _DestinDecodePrsnt = value;
- ///当有新的同步目标时,应先将目标中参数同步到本地<see cref="_RS232DecodePrsnt"/>属性中
- if (_RS232DecodePrsnt != null && value != null)
- {
- typeof(RS232DecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x=>x.CanWrite).ToList().ForEach(x =>
- {
- x.SetValue(_RS232DecodePrsnt, x.GetValue(value));
- });
- }
- }
- }
- }
- private RS232DecodePrsnt _DestinDecodePrsnt;
- private RS232DecodePrsnt _RS232DecodePrsnt => Presenter as RS232DecodePrsnt;
- public IProtocolPrsnt Presenter { get; set; }
- private FloatForm _FloatForm;
- private Int32 _RowHeight = 56;
- private Int32 _ColnumCount = 3;
- #endregion 属性定义
- #region 控件初始化
- private void InitSourceL()
- {
- this.CbxSourceL.DataSource = ChannelIdExt.GetAnalogs().Select(x => new ComboBoxData<ChannelId>(x.GetEnumValueResourceProperty(), x, x != _RS232DecodePrsnt.ChannelId)).ToList();
- this.CbxSourceL.DisplayMember = "Key";
- this.CbxSourceL.ValueMember = "Value";
- this.CbxSourceL.SelectedValueChanged += (_, _) =>
- {
- _RS232DecodePrsnt.ChannelL = (ChannelId)this.CbxSourceL.SelectedValue;
- };
- this.CbxSourceL.SelectedValue = _RS232DecodePrsnt.ChannelL;
- }
- private void InitPolarity()
- {
- this.RbgPolarity.ButtonItems = Enum.GetValues<ProtocolRS232.Polarity>().Select(x => new RadioButtonItem()
- {
- Tag = x,
- Text = x.GetDescription(),
- }).ToArray();
- this.RbgPolarity.IndexChanged += (sender, args) =>
- {
- _RS232DecodePrsnt.Polarity = (ProtocolRS232.Polarity)RbgPolarity.ButtonItems[RbgPolarity.ChoosedButtonIndex].Tag;
- };
- this.RbgPolarity.ChoosedButtonIndex = Enum.GetValues<ProtocolRS232.Polarity>().ToList().FindIndex(x => x == _RS232DecodePrsnt.Polarity);
- }
- private void InitThreshold()
- {
- this.BtnThreshold.Text = SIHelper.ValueChangeToSI(_RS232DecodePrsnt.Threshold, 2, "V");
- this.BtnThreshold.Click += (sender, args) => SetThreshold();
- }
- private void InitParity()
- {
- this.CbxParity.DataSource = Enum.GetValues<ProtocolRS232.OddEvenCheck>().Select(x => new KeyValuePair<string, ProtocolRS232.OddEvenCheck>(x.GetDescription(), x)).ToList();
- this.CbxParity.ValueMember = "Value";
- this.CbxParity.DisplayMember = "Key";
- this.CbxParity.SelectedValueChanged += (sender, args) =>
- {
- _RS232DecodePrsnt.Parity = (ProtocolRS232.OddEvenCheck)CbxParity.SelectedValue;
- };
- this.CbxParity.SelectedValue = _RS232DecodePrsnt.Parity;
- }
- private void InitStopBits()
- {
- this.CbxStopBits.ButtonItems = Enum.GetValues<ProtocolRS232.StopBit>().Select(x => new RadioButtonItem()
- {
- Text = x switch
- {
- ProtocolRS232.StopBit.StopBit_1bit => "1.0",
- ProtocolRS232.StopBit.StopBit_2bit => "2.0",
- _ => "",
- },
- Tag = x
- }).ToArray();
- this.CbxStopBits.IndexChanged += (sender, args) =>
- {
- _RS232DecodePrsnt.StopBits = (ProtocolRS232.StopBit)CbxStopBits.ButtonItems[CbxStopBits.ChoosedButtonIndex].Tag;
- };
- this.CbxStopBits.ChoosedButtonIndex = Enum.GetValues<ProtocolRS232.StopBit>().ToList().FindIndex(x => x == _RS232DecodePrsnt.StopBits);
- }
- private void InitByteOrder()
- {
- this.CbxByteOrder.ButtonItems = Enum.GetValues<ProtocolRS232.MSB_LSB>().Select(x => new RadioButtonItem()
- {
- Text = x.GetDescription(),
- Tag = x,
- }).ToArray();
- this.CbxByteOrder.IndexChanged += (sender, args) =>
- {
- _RS232DecodePrsnt.ByteOrder = (ProtocolRS232.MSB_LSB)CbxByteOrder.ButtonItems[CbxByteOrder.ChoosedButtonIndex].Tag;
- };
- this.CbxByteOrder.ChoosedButtonIndex = (Int32)_RS232DecodePrsnt.ByteOrder;
- }
- private void InitDataBits()
- {
- this.CbxDataBits.ButtonItems = Enum.GetValues<ProtocolRS232.DataBitWidth>().Select(x =>
- {
- String des = x switch
- {
- ProtocolRS232.DataBitWidth.DataBitWidth_5Bit => "5",
- ProtocolRS232.DataBitWidth.DataBitWidth_6Bit => "6",
- ProtocolRS232.DataBitWidth.DataBitWidth_7Bit => "7",
- ProtocolRS232.DataBitWidth.DataBitWidth_8Bit => "8",
- _ => "",
- };
- return new RadioButtonItem() { Text = des, Tag = x };
- }).ToArray();
- this.CbxDataBits.IndexChanged += (sender, args) =>
- {
- _RS232DecodePrsnt.DataBits = (ProtocolRS232.DataBitWidth)CbxDataBits.ButtonItems[CbxDataBits.ChoosedButtonIndex].Tag;
- };
- this.CbxDataBits.ChoosedButtonIndex = Enum.GetValues<ProtocolRS232.DataBitWidth>().ToList().FindIndex(x => x == _RS232DecodePrsnt.DataBits);
- }
- private void InitRealBiteRate()
- {
- this.BtnRealBitRate.Click += (sender, args) => SetBitRate();
- }
- private void InitBiteRate()
- {
- this.CbxBitRate.DataSource = Enum.GetValues<ProtocolRS232.BPSList>().Select(x => new KeyValuePair<string, ProtocolRS232.BPSList>(x switch
- {
- ProtocolRS232.BPSList.BPSList_Custom => "Custom",
- ProtocolRS232.BPSList.BPSList_115200 =>"115200bps",
- ProtocolRS232.BPSList.BPSList_19200=>"19200bps",
- ProtocolRS232.BPSList.BPSList_2400=>"2400bps",
- ProtocolRS232.BPSList.BPSList_38400=>"38400bps",
- ProtocolRS232.BPSList.BPSList_4800=>"4800bps",
- ProtocolRS232.BPSList.BPSList_57600=>"57600bps",
- ProtocolRS232.BPSList.BPSList_9600=>"9600bps",
- _ => ((UInt32)x).ToString() + "bps",
- }, x)).ToArray();
- this.CbxBitRate.ValueMember = "Value";
- this.CbxBitRate.DisplayMember = "Key";
- this.CbxBitRate.SelectedValueChanged += (sender, args) =>
- {
- ProtocolRS232.BPSList bitrate = (ProtocolRS232.BPSList)this.CbxBitRate.SelectedValue;
- SetRealBitRateVisibility(bitrate == ProtocolRS232.BPSList.BPSList_Custom);
- if (bitrate != ProtocolRS232.BPSList.BPSList_Custom)
- {
- this.BtnRealBitRate.Text = _RS232DecodePrsnt.BitRate.ToString();
- _RS232DecodePrsnt.BitRate = bitrate switch
- {
- ProtocolRS232.BPSList.BPSList_115200 =>115200,
- ProtocolRS232.BPSList.BPSList_19200 => 19200,
- ProtocolRS232.BPSList.BPSList_2400 => 2400,
- ProtocolRS232.BPSList.BPSList_38400 => 38400,
- ProtocolRS232.BPSList.BPSList_4800 => 4800,
- ProtocolRS232.BPSList.BPSList_57600 => 57600,
- ProtocolRS232.BPSList.BPSList_9600 => 9600,
- _=>9600,
- };
- }
- System.Diagnostics.Debug.WriteLine(bitrate);
- };
- UpdateBitRate();
- }
- private void InitSignalType()
- {
- this.CbxSignalType.DataSource = ProtocolRS232.SignalType.Difference.GetEnumList();
- this.CbxSignalType.DisplayMember = "Key";
- this.CbxSignalType.ValueMember = "Value";
- this.CbxSignalType.SelectedValueChanged += (_, _) =>
- {
- _RS232DecodePrsnt.ChType = (ProtocolRS232.SignalType)this.CbxSignalType.SelectedValue;
- ChangeSourceL();
- CbxSourceL.Visible = _RS232DecodePrsnt.ChType == ProtocolRS232.SignalType.Difference;
- LblSourceL.Visible = CbxSourceL.Visible;
- };
- this.CbxSignalType.SelectedValue = _RS232DecodePrsnt.ChType;
- }
- private void InitSource()
- {
- this.CbxSource.DataSource = ChannelIdExt.GetAnalogs().GetEnumList();
- this.CbxSource.DisplayMember = "Key";
- this.CbxSource.ValueMember = "Value";
- this.CbxSource.SelectedValueChanged += (_, _) =>
- {
- _RS232DecodePrsnt.ChannelId = (ChannelId)this.CbxSource.SelectedValue;
- SourceChanged();
- };
- this.CbxSource.SelectedValue = _RS232DecodePrsnt.ChannelId;
- }
- #endregion 控件初始化
- private void SourceChanged()
- {
- //通道发生改变后重新获取需要同步的Prsnt
- GetDestinPrsnt();
- ChangeSourceL();
- }
- /// <summary>
- /// 当<see cref="IRS232DecodePrsnt.ChType"/>属性为<see cref="RS232ChType.Differential"/>时,
- /// <see cref="IRS232DecodePrsnt.ChannelL"/>与<see cref="IRS232DecodePrsnt.ChannelId"/>中值不能相同
- /// </summary>
- private void ChangeSourceL()
- {
- if (_RS232DecodePrsnt.ChType == ProtocolRS232.SignalType.Difference)
- {
- if (_RS232DecodePrsnt.ChannelL == _RS232DecodePrsnt.ChannelId)
- {
- if (_RS232DecodePrsnt.ChannelL == ChannelIdExt.GetAnalogs().Last()) _RS232DecodePrsnt.ChannelL = ChannelIdExt.GetAnalogs().Last() - 1;
- else if (_RS232DecodePrsnt.ChannelL == ChannelIdExt.GetAnalogs().First()) _RS232DecodePrsnt.ChannelL = ChannelIdExt.GetAnalogs().First() + 1;
- else
- {
- _RS232DecodePrsnt.ChannelL++;
- }
- }
- if (this.CbxSourceL.DataSource is IList list)
- {
- foreach (var val in list)
- {
- (val as dynamic).Visible = (val as dynamic).Value != _RS232DecodePrsnt.ChannelId;
- }
- }
- }
- }
- /// <summary>
- /// 同步两个Prsnt
- /// </summary>
- /// <param name="propertyName">属性名称</param>
- private void DecodeSynchronization(String propertyName)
- {
- if (DestinDecodePrsnt == null)
- return;
- ///由于使用了<see cref="IRS232DecodePrsnt.ChannelId"/>进行判断具体同步的目标
- ///因此<see cref="IRS232DecodePrsnt.ChannelId"/>参数不进行同步
- if (propertyName == nameof(_RS232DecodePrsnt.ChannelId))
- return;
- if (String.IsNullOrEmpty(propertyName))
- {
- typeof(RS232DecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x=>x.CanWrite).ToList().ForEach(x =>
- {
- x.SetValue(DestinDecodePrsnt, x.GetValue(_RS232DecodePrsnt));
- });
- }
- else
- {
- PropertyInfo propertyInfo = typeof(RS232DecodePrsnt).GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
- if (propertyInfo != null)
- propertyInfo.SetValue(DestinDecodePrsnt, propertyInfo.GetValue(_RS232DecodePrsnt));
- }
- }
- private void SetBitRate()
- {
- Boolean lastflag = true;
- if (this.FindForm() is FloatForm form)
- {
- lastflag = form.CanClose;
- form.CanClose = false;
- }
- if (_FloatForm != null && !_FloatForm.IsDisposed)
- _FloatForm?.Close();
- _FloatForm = new FloatForm();
- _FloatForm.BackColor = BackColor;
- _FloatForm.ForeColor = ForeColor;
- _FloatForm.Title = "设置波特率";
- _FloatForm.Width = 380;
- _FloatForm.Height = 500 + _FloatForm.HeadHeight;
- HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
- numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.StyleManager.Instance.RegisterControl(x));
- numberKeyboard.Top = _FloatForm.HeadHeight;
- numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight;
- numberKeyboard.Width = _FloatForm.Width;
- numberKeyboard.ForeColor = ForeColor;
- numberKeyboard.BackColor = BackColor;
- numberKeyboard.MaxValue = (Int64)1E9;
- numberKeyboard.MinValue = 0;
- numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Dec;
- numberKeyboard.Value = _RS232DecodePrsnt.BitRate;
- numberKeyboard.OkClick += (sender, args) =>
- {
- _RS232DecodePrsnt.BitRate = (UInt32)args.Data;
- this.BtnRealBitRate.Text = _RS232DecodePrsnt.BitRate.ToString();
- _FloatForm.Close();
- };
- numberKeyboard.CancelClick += (_, _) => _FloatForm.Close();
- _FloatForm.Controls.Add(numberKeyboard);
- _FloatForm.FormClosing += (_, _) =>
- {
- if (this.FindForm() is FloatForm form)
- form.CanClose = lastflag;
- };
- EventBus.EventBroker.Instance.GetEvent<Uni_Trend.MSO7000X.Common.Structs.FormEventArgs>().Publish(this, new Uni_Trend.MSO7000X.Common.Structs.FormEventArgs()
- {
- Current = _FloatForm,
- Type = Uni_Trend.MSO7000X.Common.Structs.FormType.InfoForm,
- });
- }
- private void SetThreshold()
- {
- Boolean lastflag = true;
- if (this.FindForm() is FloatForm form)
- {
- lastflag = form.CanClose;
- form.CanClose = false;
- }
- if (_FloatForm != null && !_FloatForm.IsDisposed)
- _FloatForm?.Close();
- _FloatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
- _FloatForm.BackColor = BackColor;
- _FloatForm.ForeColor = ForeColor;
- _FloatForm.Width = 380;
- _FloatForm.Height = 460 + _FloatForm.HeadHeight;
- _FloatForm.Title = "设置门限";
- Uni_Trend.MSO7000X.UserControls.NumberKeyboard numberKeyboard = new Uni_Trend.MSO7000X.UserControls.NumberKeyboard();
- numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.StyleManager.Instance.RegisterControl(x));
- numberKeyboard.Top = _FloatForm.HeadHeight;
- numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight;
- numberKeyboard.Width = _FloatForm.Width;
- numberKeyboard.ForeColor = ForeColor;
- numberKeyboard.BackColor = BackColor;
- numberKeyboard.DefaultValue = _RS232DecodePrsnt.Threshold;
- numberKeyboard.Unit = "V";
- numberKeyboard.MinValue = -10;
- numberKeyboard.MaxValue = 10;
- numberKeyboard.DecimalNumber = 2;
- numberKeyboard.OkClickEvent += (sender, args) =>
- {
- this._RS232DecodePrsnt.Threshold = args.Data;
- this.BtnThreshold.Text = SIHelper.ValueChangeToSI(_RS232DecodePrsnt.Threshold, 2, "V");
- _FloatForm?.Close();
- };
- numberKeyboard.CancelEvent += (sender, args) => _FloatForm?.Close();
- _FloatForm.Controls.Add(numberKeyboard);
- _FloatForm.FormClosing += (_, _) =>
- {
- if (this.FindForm() is FloatForm form)
- form.CanClose = lastflag;
- };
- EventBus.EventBroker.Instance.GetEvent<Uni_Trend.MSO7000X.Common.Structs.FormEventArgs>().Publish(this, new Uni_Trend.MSO7000X.Common.Structs.FormEventArgs()
- {
- Current = _FloatForm,
- Type = Uni_Trend.MSO7000X.Common.Structs.FormType.InfoForm,
- });
- }
- private void SetRealBitRateVisibility(Boolean visibility = false)
- {
- this.BtnRealBitRate.Visible = visibility;
- this.LblRealBitRate.Visible = visibility;
- }
- public void UpdateView(String propertyName)
- {
- DecodeSynchronization(propertyName);
- if (String.IsNullOrEmpty(propertyName))
- {
- UpdateView();
- return;
- }
- this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Where(x =>
- {
- UpdatePropertyAttribute attribute = x.GetCustomAttribute<UpdatePropertyAttribute>();
- return attribute != null && attribute.PropertyName == propertyName;
- }).FirstOrDefault()?.Invoke(this, null);
- }
- private void UpdateView()
- {
- this.GetType().GetMethods().Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x => x?.Invoke(this, null));
- this.Refresh();
- }
- //private class ComboBoxData<T>
- //{
- // public String Key { get; set; }
- // public T Value { get; set; }
- // public Boolean Visible { get; set; }
- // public ComboBoxData(String key, T value, Boolean visible = true)
- // {
- // Key = key;
- // Value = value;
- // Visible = visible;
- // }
- //}
- //[AttributeUsage(AttributeTargets.Method)]
- //private class UpdatePropertyAttribute : Attribute
- //{
- // public UpdatePropertyAttribute(String propertyName) => this.PropertyName = propertyName;
- // public String PropertyName { get; set; }
- //}
- #region UpdateFunction
- [UpdateProperty(nameof(RS232DecodePrsnt.ChannelId))]
- private void UpdataChannelId()
- {
- this.CbxSource.SelectedValue = _RS232DecodePrsnt.ChannelId;
- }
- [UpdateProperty(nameof(RS232DecodePrsnt.ChannelL))]
- private void UpdateChannelL()
- {
- this.CbxSourceL.SelectedValue = _RS232DecodePrsnt.ChannelL;
- }
- [UpdateProperty(nameof(RS232DecodePrsnt.BitRate))]
- private void UpdateBitRate()
- {
- Int32 index = Enum.GetValues<ProtocolRS232.BPSList>().Select(x => x switch
- {
- ProtocolRS232.BPSList.BPSList_115200=>115200,
- ProtocolRS232.BPSList.BPSList_19200=>19200,
- ProtocolRS232.BPSList.BPSList_2400=>2400,
- ProtocolRS232.BPSList.BPSList_38400=>38400,
- ProtocolRS232.BPSList.BPSList_4800=>4800,
- ProtocolRS232.BPSList.BPSList_57600=>57600,
- ProtocolRS232.BPSList.BPSList_9600=>9600,
- _ => 0,
- }).ToList().FindIndex(x => x == _RS232DecodePrsnt.BitRate);
- if (index >= 0)
- {
- CbxBitRate.SelectedValue = Enum.GetValues<ProtocolRS232.BPSList>()[index];
- SetRealBitRateVisibility(false);
- }
- else
- {
- CbxBitRate.SelectedValue = ProtocolRS232.BPSList.BPSList_Custom;
- SetRealBitRateVisibility(true);
- }
- BtnRealBitRate.Text = _RS232DecodePrsnt.BitRate.ToString();
- }
- [UpdateProperty(nameof(RS232DecodePrsnt.ByteOrder))]
- private void UpdateByteOrder()
- {
- this.CbxByteOrder.ChoosedButtonIndex = Enum.GetValues<ProtocolRS232.MSB_LSB>().ToList().FindIndex(x => x == _RS232DecodePrsnt.ByteOrder);
- }
- [UpdateProperty(nameof(RS232DecodePrsnt.DataBits))]
- private void UpdateDataBits()
- {
- this.CbxDataBits.ChoosedButtonIndex = Enum.GetValues<ProtocolRS232.DataBitWidth>().ToList().FindIndex(x => x == _RS232DecodePrsnt.DataBits);
- }
- [UpdateProperty(nameof(RS232DecodePrsnt.Parity))]
- private void UpdateParity()
- {
- this.CbxParity.SelectedValue = _RS232DecodePrsnt.Parity;
- }
- [UpdateProperty(nameof(RS232DecodePrsnt.StopBits))]
- private void UpdateStopBits()
- {
- this.CbxStopBits.ChoosedButtonIndex = Enum.GetValues<ProtocolRS232.StopBit>().ToList().FindIndex(x => x == _RS232DecodePrsnt.StopBits);
- }
- [UpdateProperty(nameof(RS232DecodePrsnt.ChType))]
- private void UpdateChType()
- {
- this.CbxSignalType.SelectedValue = _RS232DecodePrsnt.ChType;
- }
- [UpdateProperty(nameof(RS232DecodePrsnt.Threshold))]
- private void UpdateThreshold()
- {
- this.BtnThreshold.Text = SIHelper.ValueChangeToSI(_RS232DecodePrsnt.Threshold, 2, "V");
- }
- [UpdateProperty(nameof(RS232DecodePrsnt.Polarity))]
- private void UpdatePolarity()
- {
- this.RbgPolarity.ChoosedButtonIndex = Enum.GetValues<ProtocolRS232.Polarity>().ToList().FindIndex(x => x == _RS232DecodePrsnt.Polarity);
- }
- #endregion UpdateFunction
- }
- [AttributeUsage(AttributeTargets.Field)]
- partial class RowColAttribute : Attribute
- {
- public RowColAttribute(Int32 row = 0, Int32 col = 0)
- {
- Row = row;
- Colnum = col;
- }
- public Int32 Row { get; set; }
- public Int32 Colnum { get; set; }
- public override Boolean Equals(Object obj)
- {
- if (obj == null)
- return false;
- if (!(obj is RowColAttribute attribute))
- return false;
- return attribute.Colnum == Colnum && attribute.Row == Row;
- }
- public override Int32 GetHashCode()
- {
- Int32 hashCode = Row.GetHashCode();
- if (Row.GetHashCode() != Colnum.GetHashCode())
- hashCode ^= Colnum.GetHashCode();
- return hashCode;
- }
- }
- }
|