/// <summary>Used to create a data model for the appropriate type</summary> /// <param name="dataType"></param> public DashboardConfigData(BinaryMsgDataType dataType) { this.DataModel = new DashboardControlDataModel() { DataType = dataType, }; }
private DashboardControlEdit(UserControl parent, DashboardControlDataModel dm) { this.callingUserControl = parent; this.DataModel = dm; InitializeComponent(); this.SetFieldValue(this.txtId, this.DataModel.Id, BinaryMsgDataType.typeUInt8); this.txtName.Text = this.DataModel.IOName; this.cbDataType.ItemsSource = this.typeList; this.cbDataType.SelectedItem = this.typeList.Find(x => x.DataType == this.DataModel.DataType); this.currentDataType = this.DataModel.DataType; this.SetFieldValue(this.txtMin, this.DataModel.Minimum, this.DataModel.DataType); this.SetFieldValue(this.txtMax, this.DataModel.Maximum, this.DataModel.DataType); this.SetFieldValue(this.txtStep, this.DataModel.SendAtStep, this.DataModel.DataType); // User display show visual value row and colum this.lblRow.Content = this.DataModel.Row + 1; this.lblColum.Content = this.DataModel.Column - 1; if (this.DataModel.DataType == BinaryMsgDataType.typeBool) { this.rowMin.Height = new GridLength(0); this.rowMax.Height = new GridLength(0); this.rowStep.Height = new GridLength(0); this.cbDataType.SelectedIndex = 0; this.cbDataType.IsEnabled = false; } else { this.cbDataType.SelectionChanged += this.dataTypeChanged; } }
public static int DataSize(this BinaryMsgDataType dataType) { switch (dataType) { case BinaryMsgDataType.typeBool: return(((byte)0).GetSize()); case BinaryMsgDataType.typeInt8: return(((sbyte)0).GetSize()); case BinaryMsgDataType.typeUInt8: return(((byte)0).GetSize()); case BinaryMsgDataType.typeInt16: return(((Int16)0).GetSize()); case BinaryMsgDataType.typeUInt16: return(((UInt16)0).GetSize()); case BinaryMsgDataType.typeInt32: return(((Int32)0).GetSize()); case BinaryMsgDataType.typeUInt32: return(((UInt32)0).GetSize()); case BinaryMsgDataType.typeFloat32: return(((Single)0).GetSize()); case BinaryMsgDataType.tyepUndefined: case BinaryMsgDataType.typeInvalid: default: return(0);; } }
private void dataTypeChanged(object sender, SelectionChangedEventArgs e) { DI.W.GetRange( this.cbDataType.SelectedItem as BinaryMsgDataTypeDisplay, range => { this.currentDataType = (this.cbDataType.SelectedItem as BinaryMsgDataTypeDisplay).DataType; this.SetFieldValue(this.txtMin, range.Min, this.currentDataType); this.SetFieldValue(this.txtMax, range.Max, this.currentDataType); this.SetFieldValue(this.txtStep, "1", this.currentDataType); }, App.ShowErrMsg); }
public void InitNew(int row, int column, BinaryMsgDataType dataType) { this.Id = 0; this.IOName = ""; this.DataType = dataType; this.SendAtStep = 1; this.Minimum = dataType.Min(); this.Maximum = dataType.Max(); this.Row = row; this.Column = column; this.DoInit(); }
public static string ToStr(this BinaryMsgDataType dataType) { return(dataType switch { BinaryMsgDataType.typeBool => "Bool", BinaryMsgDataType.typeInt8 => "Int8", BinaryMsgDataType.typeUInt8 => "UInt8", BinaryMsgDataType.typeInt16 => "Int16", BinaryMsgDataType.typeUInt16 => "UInt16", BinaryMsgDataType.typeInt32 => "Int32", BinaryMsgDataType.typeUInt32 => "UInt32", BinaryMsgDataType.typeFloat32 => "Float32", BinaryMsgDataType.tyepUndefined => "Undefined", BinaryMsgDataType.typeInvalid => "Invalid", _ => "Unhandled", });
public void Validate(BinaryMsgDataType dataType, string value, Action onSuccess, OnErr onError) { dataType.Validate(value, onSuccess, (range) => { if (dataType == BinaryMsgDataType.tyepUndefined || dataType == BinaryMsgDataType.typeInvalid) { onError(string.Format("'{0}' {1}", this.GetText(MsgCode.DataType), this.GetText(MsgCode.undefined))); } else { onError(string.Format("'{0}' {1} {2} - {3}", value, this.GetText(MsgCode.OutOfRange), range.Min, range.Max)); } }); }
/// <summary>This function is passed in to the controls so they can send their values</summary> /// <param name="id">The message ID</param> /// <param name="dataType">The value data type</param> /// <param name="value">The value to send</param> private void sendAction(byte id, BinaryMsgDataType dataType, double value) { // TODO Can do some validation here of range? should already be set in the config // TODO - move to an event that the window picks up switch (dataType) { case BinaryMsgDataType.typeBool: this.MsgToDevice?.Invoke(this, new BinaryMsgBool(id, (value != 0)).ToByteArray()); //DI.W.BTSend(new BinaryMsgBool(id, (value != 0)).ToByteArray()); break; case BinaryMsgDataType.typeInt8: this.MsgToDevice?.Invoke(this, new BinaryMsgInt8(id, (sbyte)value).ToByteArray()); break; case BinaryMsgDataType.typeInt16: this.MsgToDevice?.Invoke(this, new BinaryMsgInt16(id, (Int16)value).ToByteArray()); break; case BinaryMsgDataType.typeInt32: this.MsgToDevice?.Invoke(this, new BinaryMsgInt32(id, (Int32)value).ToByteArray()); break; case BinaryMsgDataType.typeUInt8: this.MsgToDevice?.Invoke(this, new BinaryMsgUInt8(id, (byte)value).ToByteArray()); //DI.W.BTSend(new BinaryMsgUInt8(id, (byte)value).ToByteArray()); break; case BinaryMsgDataType.typeUInt16: this.MsgToDevice?.Invoke(this, new BinaryMsgUInt16(id, (UInt16)value).ToByteArray()); break; case BinaryMsgDataType.typeUInt32: this.MsgToDevice?.Invoke(this, new BinaryMsgUInt32(id, (UInt32)value).ToByteArray()); break; case BinaryMsgDataType.typeFloat32: this.MsgToDevice?.Invoke(this, new BinaryMsgFloat32(id, (Single)value).ToByteArray()); break; case BinaryMsgDataType.tyepUndefined: case BinaryMsgDataType.typeInvalid: // TODO - raise error break; } }
private DashboardControlDataModel dm( byte id, string name, BinaryMsgDataType dataType, double step, double min, double max, int row, int column, int precision = 0) { return(new DashboardControlDataModel() { Id = id, IOName = name, DataType = dataType, SendAtStep = step, Minimum = min, Maximum = max, Precision = precision, Row = row, Column = column, }); }
public BinaryMsgDataTypeDisplay(BinaryMsgDataType dataType) { this.DataType = dataType; this.Display = this.DataType.ToStr(); }
public static byte ToByte(this BinaryMsgDataType dataType) { return((byte)dataType); }
public void Validate(BinaryMsgDataType dataType, string value, OnErr onError) { this.Validate(dataType, value, () => { }, onError); }
public void SetDataType(BinaryMsgDataType dataType) { this.dataType = dataType; }
private void SetFieldValue(UC_NumericEditBox txt, object obj, BinaryMsgDataType dataType) { txt.Text = obj.ToString(); txt.SetDataType(dataType); }