Exemple #1
0
        public void Write(ElementModel emodel)
        {
            SimulateVariableUnit svunit = smodel.GetVariableUnit(emodel.ShowName, _Type(emodel.DataType));

            switch (svunit.Type)
            {
            case "BIT":
                switch (emodel.SetValue.ToUpper())
                {
                case "0":
                case "OFF":
                case "FALSE":
                    svunit.Value = 0; break;

                case "1":
                case "ON":
                case "TRUE":
                    svunit.Value = 1; break;
                }
                break;

            case "WORD":
                svunit.Value = Int32.Parse(emodel.SetValue); break;

            case "DWORD":
                svunit.Value = Int64.Parse(emodel.SetValue); break;

            case "FLOAT":
                svunit.Value = double.Parse(emodel.SetValue); break;
            }
            svunit.Set(smodel.SManager.DllModel);
            //emodel.CurrentValue = svunit.Value.ToString();
        }
Exemple #2
0
        private IntraSegment GenerateIntraSegmentByElement(ElementModel element)
        {
            AddrSegment bseg = new AddrSegment(element);
            AddrSegment iseg = new AddrSegment(element, true);

            return(new IntraSegment(bseg, iseg));
        }
Exemple #3
0
        public void Add(ICommunicationCommand cmd)
        {
            ElementModel emodel = null;

            if (cmd is GeneralWriteCommand)
            {
                GeneralWriteCommand gwcmd = (GeneralWriteCommand)cmd;
                Write(gwcmd.RefElements_A);
                Write(gwcmd.RefElements_B);
            }
            if (cmd is IntrasegmentWriteCommand)
            {
            }
            if (cmd is ForceCancelCommand)
            {
                ForceCancelCommand fccmd = (ForceCancelCommand)cmd;
                emodel = fccmd.RefElement;
                if (fccmd.IsAll)
                {
                    foreach (ElementModel _emodel in dict.Values)
                    {
                        Unlock(_emodel);
                    }
                    smodel.SManager.UnlockAll();
                }
                else
                {
                    Unlock(emodel);
                }
            }
        }
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox cbox = (ComboBox)sender;

            if (cbox.Parent is DataGridCell)
            {
                DataGridCell dgcell = (DataGridCell)(cbox.Parent);
                if (dgcell.DataContext is ElementModel)
                {
                    ElementModel emodel_old = (ElementModel)(dgcell.DataContext);
                    ElementModel emodel_new = new ElementModel(emodel_old);
                    if (e.AddedItems.Count <= 0 ||
                        emodel_new.ShowType.Equals(e.AddedItems[0].ToString()))
                    {
                        return;
                    }
                    emodel_new.ShowType = e.AddedItems[0].ToString();
                    _parent.Manager.Replace(emodel_old, emodel_new);
                    emodel_new = _parent.Manager.Get(emodel_new);
                    int id = Elements.IndexOf(emodel_old);
                    Elements[id]       = emodel_new;
                    dgcell.DataContext = emodel_new;
                }
            }
        }
 private void AddElement()
 {
     using (AddElementDialog dialog = new AddElementDialog())
     {
         dialog.EnsureButtonClick += (sender1, e1) =>
         {
             List <ElementModel> emb = new List <ElementModel>();
             int span = GetSpan(dialog.DataType);
             for (int j = 0, i = 0; j < dialog.AddNums; i += span, j++)
             {
                 ElementModel ele = new ElementModel(dialog.IntrasegmentType != string.Empty, dialog.DataType);
                 ele.AddrType         = dialog.AddrType;
                 ele.DataType         = dialog.DataType;
                 ele.StartAddr        = (uint)(dialog.StartAddr + i);
                 ele.IntrasegmentType = dialog.IntrasegmentType;
                 ele.IntrasegmentAddr = dialog.IntrasegmentAddr;
                 emb.Add(ele);
             }
             Manager.Add(emb);
             foreach (ElementModel ele in emb)
             {
                 CurrentTable.AddElement(
                     Manager.Get(ele));
             }
             dialog.Close();
         };
         dialog.ShowDialog();
     }
 }
        private void Write(ElementModel element)
        {
            string value = element.SetValue;

            byte[] data;
            element.SetValue = value;
            switch (element.ShowType)
            {
            case "WORD":
                data = ValueConverter.GetBytes(
                    (UInt16)(Int16.Parse(value)));
                break;

            case "UWORD":
                data = ValueConverter.GetBytes(
                    UInt16.Parse(value));
                break;

            case "BCD":
                data = ValueConverter.GetBytes(
                    ValueConverter.ToUINT16(
                        UInt16.Parse(value)));
                break;

            case "DWORD":
                data = ValueConverter.GetBytes(
                    (UInt32)(Int32.Parse(value)));
                break;

            case "UDWORD":
                data = ValueConverter.GetBytes(
                    UInt32.Parse(value));
                break;

            case "FLOAT":
                data = ValueConverter.GetBytes(
                    ValueConverter.FloatToUInt(
                        float.Parse(value)));
                break;

            default:
                data = new byte[0];
                break;
            }
            if (element.IsIntrasegment)
            {
                IntrasegmentWriteCommand command = new IntrasegmentWriteCommand(data, element);
                command.RefElement = element;
                _parent.Manager.Add(command);
            }
            else
            {
                GeneralWriteCommand command = new GeneralWriteCommand(data, element);
                command.RefElements_A.Add(element);
                _parent.Manager.Add(command);
            }
        }
Exemple #7
0
 private void _Replace(ElementModel emodel_old, ElementModel emodel_new, bool arrange = true)
 {
     _Remove(emodel_old, false);
     _Add(emodel_new, false);
     if (arrange)
     {
         Arrange();
     }
 }
 public void LoadElementsByXElment(XElement rootNode)
 {
     Elements.Clear();
     foreach (var ele in rootNode.Elements("Element"))
     {
         ElementModel elementModel = new ElementModel();
         elementModel.LoadSelfByXElement(ele);
         AddElement(elementModel);
     }
 }
Exemple #9
0
 public ElementModel(ElementModel emodel)
 {
     AddrType         = emodel.AddrType;
     StartAddr        = emodel.StartAddr;
     IsIntrasegment   = emodel.IsIntrasegment;
     IntrasegmentType = emodel.IntrasegmentType;
     IntrasegmentAddr = emodel.IntrasegmentAddr;
     DataType         = emodel.DataType;
     RefCount         = 1;
     SetShowTypes();
 }
 public void AddElement(ElementModel ele)
 {
     if (ele == null)
     {
         return;
     }
     if (!Elements.ToList().Exists(x => { return(x.ShowName == ele.ShowName); }))
     {
         Elements.Add(ele);
     }
 }
Exemple #11
0
 private uint GetAddrSpan(ElementModel element, uint startAddr)
 {
     if (element.ByteCount == 4 && !(element.AddrType == "CV" && element.StartAddr >= 200))
     {
         return(element.StartAddr - startAddr + 1);
     }
     else
     {
         return(element.StartAddr - startAddr);
     }
 }
Exemple #12
0
        public void Unlock(ElementModel emodel)
        {
            SimulateVariableUnit svunit = smodel.GetVariableUnit(emodel.ShowName, _Type(emodel.DataType));

            if (!svunit.Islocked)
            {
                return;
            }
            smodel.SManager.Unlock(svunit);
            emodel.SetValue = String.Empty;
        }
Exemple #13
0
 private void Write(ElementModel element, byte value)
 {
     if (element.IsIntrasegment)
     {
         Add(new IntrasegmentWriteCommand(new byte[] { value }, element));
     }
     else
     {
         Add(new GeneralWriteCommand(new byte[] { value }, element));
     }
 }
Exemple #14
0
        public void Lock(ElementModel emodel)
        {
            Write(emodel);
            SimulateVariableUnit svunit = smodel.GetVariableUnit(emodel.ShowName, _Type(emodel.DataType));

            if (svunit.Islocked)
            {
                return;
            }
            smodel.SManager.Lock(svunit);
        }
Exemple #15
0
        public void Handle(IMoniValueModel mvmodel, ElementValueModifyEventArgs e)
        {
            ElementModel element = (ElementModel)mvmodel;

            element.ShowType = e.VarType;
            byte bvalue = 0;
            ICommunicationCommand command = null;

            switch (e.Type)
            {
            case ElementValueModifyEventType.ForceON:
                bvalue           = 0x01;
                element.SetValue = "ON";
                Force(element, bvalue);
                break;

            case ElementValueModifyEventType.ForceOFF:
                bvalue           = 0x00;
                element.SetValue = "OFF";
                Force(element, bvalue);
                break;

            case ElementValueModifyEventType.ForceCancel:
                element.SetValue = String.Empty;
                command          = new ForceCancelCommand(false, element);
                Add(command);
                break;

            case ElementValueModifyEventType.AllCancel:
                element.SetValue = String.Empty;
                command          = new ForceCancelCommand(true, element);
                Add(command);
                break;

            case ElementValueModifyEventType.WriteOFF:
                bvalue           = 0x00;
                element.SetValue = "OFF";
                Write(element, bvalue);
                break;

            case ElementValueModifyEventType.WriteON:
                bvalue           = 0x01;
                element.SetValue = "ON";
                Write(element, bvalue);
                break;

            case ElementValueModifyEventType.Write:
                element.SetValue = e.Value;
                Write(element, element.SetValue);
                break;
            }
        }
Exemple #16
0
        public ElementModel Get(ElementModel emodel)
        {
            SimulateVariableUnit svunit = smodel.GetVariableUnit(emodel.ShowName, _Type(emodel.DataType));

            if (dict.ContainsKey(svunit))
            {
                return(dict[svunit]);
            }
            else
            {
                return(null);
            }
        }
 private void Force(ElementModel element, byte value)
 {
     if (_parent.Manager.CanLock)
     {
         _parent.Manager.Lock(element);
     }
     else
     {
         GeneralWriteCommand command = new GeneralWriteCommand(new byte[] { value }, element);
         command.RefElements_A.Add(element);
         _parent.Manager.Add(command);
     }
 }
Exemple #18
0
        private void _Write(ElementModel emodel)
        {
            string flagname = emodel.FlagName;

            if (!WriteModels.ContainsKey(flagname))
            {
                WriteModels.Add(flagname, emodel);
            }
            else
            {
                throw new ArgumentException(
                          String.Format("It already had a same ElementModel named as {0}", flagname));
            }
        }
 public MonitorVariableTable(string tableName, MainMonitor parent)
 {
     InitializeComponent();
     DataContext = this;
     TableName   = tableName;
     if (tableName == "table_0")
     {
         ElementModel model = new ElementModel(false, BitType.BOOL);
         model.AddrType  = "X";
         model.StartAddr = 0;
         Elements.Add(model);
     }
     _parent = parent;
 }
Exemple #20
0
 /// <summary>
 /// 对命令进行分组
 /// </summary>
 /// <param name="command">当前命令</param>
 /// <param name="index">当前命令片段的索引</param>
 /// <param name="element">需添加的元素</param>
 private void ArrangeCmd(ref GeneralReadCommand command, ref int index, ElementModel element)
 {
     if (index < CommunicationDataDefine.MAX_ADDRESS_TYPE - 1)
     {
         index++;
     }
     else
     {
         index = 0;
         ReadCommands.Add(command);
         command = new GeneralReadCommand();
     }
     command.SegmentsGroup[index] = new List <AddrSegment>();
     command.SegmentsGroup[index].Add(GenerateAddrSegmentByElement(element));
 }
 private void Write(ElementModel element, byte value)
 {
     if (element.IsIntrasegment)
     {
         IntrasegmentWriteCommand command = new IntrasegmentWriteCommand(new byte[] { value }, element);
         command.RefElement = element;
         _parent.Manager.Add(command);
     }
     else
     {
         GeneralWriteCommand command = new GeneralWriteCommand(new byte[] { value }, element);
         command.RefElements_A.Add(element);
         _parent.Manager.Add(command);
     }
 }
 private void ChangeDialogStyle(AddElementDialog dialog, ElementModel element)
 {
     dialog.Title = string.Format(Properties.Resources.Variable_Modification);
     dialog.Themetextblock.Text          = string.Format(Properties.Resources.Variable_Modification);
     dialog.stackpanel.Visibility        = Visibility.Hidden;
     dialog.comboBox.SelectedIndex       = (int)Enum.Parse(typeof(ElementAddressType), element.AddrType);
     dialog.textBox.Text                 = element.StartAddr.ToString();
     dialog.DataTypeCombox.SelectedIndex = element.DataType == 0 ? 0 : element.DataType - 1;
     if (element.IsIntrasegment)
     {
         dialog.checkbox1.IsChecked     = true;
         dialog.comboBox1.SelectedIndex = element.IntrasegmentType == string.Format("V") ? 0 : 1;
         dialog.textBox1.Text           = element.IntrasegmentAddr.ToString();
     }
 }
Exemple #23
0
 public int GetMaxRange(ElementModel ele)
 {
     if (ele == null)
     {
         return(32);
     }
     if (ele.AddrType == "CV" && ele.StartAddr >= 200)
     {
         return(16);
     }
     else
     {
         return(32);
     }
 }
Exemple #24
0
 public void Write(ElementModel emodel)
 {
     if (_Thread_IsActive)
     {
         if (H_Model == MonitorManager_ElementModelHandle.NULL)
         {
             O_Model        = emodel;
             H_Model        = MonitorManager_ElementModelHandle.WRITE;
             _Thread_Active = false;
         }
     }
     else
     {
         _Write(emodel);
     }
 }
Exemple #25
0
 public void Remove(ElementModel emodel)
 {
     if (_Thread_IsActive)
     {
         if (H_Model == MonitorManager_ElementModelHandle.NULL)
         {
             O_Model        = emodel;
             H_Model        = MonitorManager_ElementModelHandle.REMOVE;
             _Thread_Active = false;
         }
     }
     else
     {
         _Remove(emodel);
     }
 }
        private void OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            ElementModel element = (ElementModel)ElementDataGrid.SelectedItem;

            if (element != null && ElementDataGrid.CurrentCell.Column != null)
            {
                if (!_parent.IsBeingMonitored)
                {
                    ShowAddDialog(element);
                }
                else
                {
                    ShowModifyDialog(element);
                }
            }
        }
Exemple #27
0
 public void Add(ElementModel emodel)
 {
     if (_Thread_IsActive)
     {
         if (H_Model == MonitorManager_ElementModelHandle.NULL)
         {
             O_Model        = emodel;
             H_Model        = MonitorManager_ElementModelHandle.ADD;
             _Thread_Active = false;
         }
     }
     else
     {
         _Add(emodel);
     }
 }
Exemple #28
0
 private void OnValueChanged(object sender, RoutedEventArgs e)
 {
     if (sender is SimulateVariableUnit)
     {
         if (!IsRunning)
         {
             return;
         }
         SimulateVariableUnit svunit = (SimulateVariableUnit)sender;
         if (!dict.ContainsKey(svunit))
         {
             return;
         }
         ElementModel emodel = dict[svunit];
         UpdateValue(emodel, svunit);
     }
 }
Exemple #29
0
        public void Add(ElementModel emodel)
        {
            SimulateVariableUnit svunit = smodel.GetVariableUnit(emodel.ShowName, _Type(emodel.DataType));

            if (!dict.ContainsKey(svunit))
            {
                dict.Add(svunit, emodel);
                emodel.RefCount      = 1;
                svunit.ValueChanged += OnValueChanged;
            }
            else
            {
                emodel = dict[svunit];
                emodel.RefCount++;
            }
            UpdateValue(emodel, svunit);
        }
Exemple #30
0
        private void _Add(ElementModel emodel, bool arrange = true)
        {
            string flagname = emodel.FlagName;

            if (!ReadModels.ContainsKey(flagname))
            {
                ReadModels.Add(flagname, emodel);
            }
            else
            {
                ReadModels[flagname].RefCount++;
            }
            if (arrange)
            {
                Arrange();
            }
        }