Exemplo n.º 1
0
 public ElementList()
 {
     InitializeComponent();
     PLCDeviceManager.GetPLCDeviceManager().PropertyChanged += PLCDeviceType_PropertyChanged;
     DataContext = this;
     Loaded     += ElementList_Loaded;
 }
Exemplo n.º 2
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            ElementAddressType Type   = (ElementAddressType)Enum.ToObject(typeof(ElementAddressType), EleTypeCombox.SelectedIndex);
            Device             device = PLCDeviceManager.GetPLCDeviceManager().SelectDevice;

            if (EleTypeCombox.SelectedIndex == 0 || EleTypeCombox.SelectedIndex == 1 || EleTypeCombox.SelectedIndex == 13 || EleTypeCombox.SelectedIndex == 14)
            {
                LocalizedMessageBox.Show(Properties.Resources.Message_Can_Not_Be_Written, LocalizedMessageIcon.Error);
            }
            else if (!ElementAddressHelper.AssertAddrRange(Type, uint.Parse(textBox.Text) + uint.Parse(LengthTextbox.Text), device))
            {
                LocalizedMessageBox.Show(Properties.Resources.Message_Over_Max_Len, LocalizedMessageIcon.Error);
            }
            else
            {
                if (ElementAddressHelper.IsBitAddr(Type))
                {
                    for (uint i = 0; i < uint.Parse(LengthTextbox.Text); i++)
                    {
                        AddElement(GenerateElementModel(true, Type.ToString(), uint.Parse(textBox.Text) + i, 0));
                    }
                }
                else
                {
                    for (uint i = 0; i < uint.Parse(LengthTextbox.Text); i++)
                    {
                        AddElement(GenerateElementModel(false, Type.ToString(), uint.Parse(textBox.Text) + i, DataTypeCombox.SelectedIndex + 1));
                    }
                }
            }
        }
Exemplo n.º 3
0
 private void _SimulateThread()
 {
     PLCDevice.Device device = PLCDeviceManager.GetPLCDeviceManager().SelectDevice;
     SetBaseBit(device.BitNumber);
     SetBPEnable(1);
     SetClockRate(1);
     // 初始化
     try
     {
         InitRunLadder();
     }
     // 触发异常时暂停并发送事件等待处理
     catch (Exception exce)
     {
         Pause();
         SimulateException(exce, new RoutedEventArgs());
         //SimulateAbort(this, new RoutedEventArgs());
     }
     // 存活状态下运行循环
     while (simulateActive)
     {
         // 暂停状态下运行这个循环
         while (!simulateRunning)
         {
             // 未存活时跳出这个循环
             if (!simulateActive)
             {
                 break;
             }
             // 等待
             Thread.Sleep(10);
         }
         // 未存活时跳出这个循环
         if (!simulateActive)
         {
             break;
         }
         // 运行一次仿真PLC
         BeforeRunLadder();
         try
         {
             RunLadder();
         }
         // 触发异常时暂停并发送事件等待处理
         catch (Exception exce)
         {
             Pause();
             SimulateException(exce, new RoutedEventArgs());
             //SimulateAbort(this, new RoutedEventArgs());
         }
         AfterRunLadder();
     }
     // 发送线程终止的事件
     SimulateAbort(this, new RoutedEventArgs());
 }
Exemplo n.º 4
0
        private void EnsureButton_Click(object sender, RoutedEventArgs e)
        {
            ElementAddressType Type   = (ElementAddressType)Enum.ToObject(typeof(ElementAddressType), comboBox.SelectedIndex);
            Device             device = PLCDeviceManager.GetPLCDeviceManager().SelectDevice;

            if (Type == ElementAddressType.H || Type == ElementAddressType.K)
            {
                LocalizedMessageBox.Show(Properties.Resources.Constant_Monitor, LocalizedMessageIcon.Warning);
            }
            else if (ElementAddressHelper.AssertAddrRange(Type, uint.Parse(textBox.Text), device))
            {
                if ((bool)checkbox1.IsChecked && !ElementAddressHelper.AssertAddrRange(ElementAddressHelper.GetIntrasegmentAddrType(comboBox1.SelectedIndex), uint.Parse(textBox1.Text), device))
                {
                    LocalizedMessageBox.Show(Properties.Resources.Intra_Cross, LocalizedMessageIcon.Warning);
                }
                else if ((bool)checkbox.IsChecked && !ElementAddressHelper.AssertAddrRange(Type, uint.Parse(textBox.Text) + uint.Parse(rangeTextBox.GetTextBox().Text) - 1, device))
                {
                    LocalizedMessageBox.Show(Properties.Resources.Exceed_Adddress, LocalizedMessageIcon.Warning);
                }
                else
                {
                    if (EnsureButtonClick != null)
                    {
                        AddrType  = Type.ToString();
                        StartAddr = uint.Parse(textBox.Text);
                        if ((bool)checkbox1.IsChecked)
                        {
                            IntrasegmentType = ElementAddressHelper.GetIntrasegmentAddrType(comboBox1.SelectedIndex).ToString();
                            IntrasegmentAddr = uint.Parse(textBox1.Text);
                        }
                        if (ElementAddressHelper.IsBitAddr(Type))
                        {
                            DataType = 0;
                        }
                        else
                        {
                            DataType = DataTypeCombox.SelectedIndex + 1;
                        }
                        if ((bool)checkbox.IsChecked)
                        {
                            AddNums = int.Parse(rangeTextBox.GetTextBox().Text);
                        }
                        else
                        {
                            AddNums = 1;
                        }
                        EnsureButtonClick.Invoke(this, new RoutedEventArgs());
                    }
                }
            }
            else
            {
                LocalizedMessageBox.Show(Properties.Resources.Address_Cross, LocalizedMessageIcon.Warning);
            }
        }
Exemplo n.º 5
0
 static public ArgumentValue Parse(string text)
 {
     string[] texts = text.Split(' ');
     if (texts.Length != 3)
     {
         return(ArgumentValue.Null);
     }
     else
     {
         return(Create(texts[0], texts[1], texts[2], PLCDeviceManager.GetPLCDeviceManager().SelectDevice));
     }
 }
Exemplo n.º 6
0
        public static bool checkAddrRange(byte addrType, byte length, ushort startAddr)
        {
            switch (addrType)
            {
            case CommunicationDataDefine.ADDRESS_TYPE_X:
                return(PLCDeviceManager.GetPLCDeviceManager().SelectDevice.XRange.AssertValue(startAddr) && PLCDeviceManager.GetPLCDeviceManager().SelectDevice.XRange.AssertValue((uint)(startAddr + length - 1)));

            case CommunicationDataDefine.ADDRESS_TYPE_Y:
                return(PLCDeviceManager.GetPLCDeviceManager().SelectDevice.YRange.AssertValue(startAddr) && PLCDeviceManager.GetPLCDeviceManager().SelectDevice.YRange.AssertValue((uint)(startAddr + length - 1)));

            case CommunicationDataDefine.ADDRESS_TYPE_M:
                return(PLCDeviceManager.GetPLCDeviceManager().SelectDevice.MRange.AssertValue(startAddr) && PLCDeviceManager.GetPLCDeviceManager().SelectDevice.MRange.AssertValue((uint)(startAddr + length - 1)));

            case CommunicationDataDefine.ADDRESS_TYPE_S:
                return(PLCDeviceManager.GetPLCDeviceManager().SelectDevice.SRange.AssertValue(startAddr) && PLCDeviceManager.GetPLCDeviceManager().SelectDevice.SRange.AssertValue((uint)(startAddr + length - 1)));

            case CommunicationDataDefine.ADDRESS_TYPE_C:
                return(PLCDeviceManager.GetPLCDeviceManager().SelectDevice.CRange.AssertValue(startAddr) && PLCDeviceManager.GetPLCDeviceManager().SelectDevice.CRange.AssertValue((uint)(startAddr + length - 1)));

            case CommunicationDataDefine.ADDRESS_TYPE_T:
                return(PLCDeviceManager.GetPLCDeviceManager().SelectDevice.TRange.AssertValue(startAddr) && PLCDeviceManager.GetPLCDeviceManager().SelectDevice.TRange.AssertValue((uint)(startAddr + length - 1)));

            case CommunicationDataDefine.ADDRESS_TYPE_AI:
                return(PLCDeviceManager.GetPLCDeviceManager().SelectDevice.AIRange.AssertValue(startAddr) && PLCDeviceManager.GetPLCDeviceManager().SelectDevice.AIRange.AssertValue((uint)(startAddr + length - 1)));

            case CommunicationDataDefine.ADDRESS_TYPE_AO:
                return(PLCDeviceManager.GetPLCDeviceManager().SelectDevice.AORange.AssertValue(startAddr) && PLCDeviceManager.GetPLCDeviceManager().SelectDevice.AORange.AssertValue((uint)(startAddr + length - 1)));

            case CommunicationDataDefine.ADDRESS_TYPE_D:
                return(PLCDeviceManager.GetPLCDeviceManager().SelectDevice.DRange.AssertValue(startAddr) && PLCDeviceManager.GetPLCDeviceManager().SelectDevice.DRange.AssertValue((uint)(startAddr + length - 1)));

            case CommunicationDataDefine.ADDRESS_TYPE_V:
                return(PLCDeviceManager.GetPLCDeviceManager().SelectDevice.VRange.AssertValue(startAddr) && PLCDeviceManager.GetPLCDeviceManager().SelectDevice.VRange.AssertValue((uint)(startAddr + length - 1)));

            case CommunicationDataDefine.ADDRESS_TYPE_Z:
                return(PLCDeviceManager.GetPLCDeviceManager().SelectDevice.ZRange.AssertValue(startAddr) && PLCDeviceManager.GetPLCDeviceManager().SelectDevice.ZRange.AssertValue((uint)(startAddr + length - 1)));

            case CommunicationDataDefine.ADDRESS_TYPE_CV:
                return(PLCDeviceManager.GetPLCDeviceManager().SelectDevice.CV16Range.AssertValue(startAddr) && PLCDeviceManager.GetPLCDeviceManager().SelectDevice.CV16Range.AssertValue((uint)(startAddr + length - 1)));

            case CommunicationDataDefine.ADDRESS_TYPE_TV:
                return(PLCDeviceManager.GetPLCDeviceManager().SelectDevice.TVRange.AssertValue(startAddr) && PLCDeviceManager.GetPLCDeviceManager().SelectDevice.TVRange.AssertValue((uint)(startAddr + length - 1)));

            case CommunicationDataDefine.ADDRESS_TYPE_CV32:
                return(PLCDeviceManager.GetPLCDeviceManager().SelectDevice.CV32Range.AssertValue(startAddr) && PLCDeviceManager.GetPLCDeviceManager().SelectDevice.CV32Range.AssertValue((uint)(startAddr + length - 1)));

            default:
                return(false);
            }
        }
Exemplo n.º 7
0
        public bool Open(XElement rootNode)
        {
            ProjectName = rootNode.Attribute("Name").Value;
            PLCDeviceManager.GetPLCDeviceManager().SetSelectDeviceType((PLCDeviceType)Enum.Parse(typeof(PLCDeviceType), rootNode.Attribute("DeviceType").Value));
            SubRoutines.Clear();
            FuncBlocks.Clear();
            ValueAliasManager.Clear();
            ValueCommentManager.Clear();
            InstructionCommentManager.Clear();
            ProjectHelper.LoadValueCommentsByXElement(rootNode.Element("ValueComments"));
            ProjectHelper.LoadValueAliasByXElement(rootNode.Element("ValueAlias"));
            ProjectPropertyManager.LoadProjectPropertyByXElement(rootNode.Element("ProjectPropertyParams"));
            MMonitorManager.MMWindow.LoadTablesByXElement(rootNode.Element("Tables"));
            EleInitializeData = rootNode.Element("EleInitialize");
            var ldnodes = rootNode.Elements("Ladder");

            foreach (XElement ldnode in ldnodes)
            {
                var ldmodel = ProjectHelper.CreateLadderDiagramByXElement(ldnode, this);
                if (ldmodel.IsMainLadder)
                {
                    MainRoutine = ldmodel;
                }
                else
                {
                    SubRoutines.Add(ldmodel);
                    TreeViewItem item = new TreeViewItem();
                    item.Header = ldmodel;
                }
            }
            // Open FunctionBlock
            var fbnodes = rootNode.Elements("FuncBlock");

            foreach (XElement fbnode in fbnodes)
            {
                var fbmodel = ProjectHelper.CreateFuncBlockByXElement(fbnode, this);
                FuncBlocks.Add(fbmodel);
            }
            var mtnodes = rootNode.Element("Modbus");
            var mtmodel = new ModbusTableViewModel(this);

            mtmodel.Load(mtnodes);
            MTVModel = mtmodel;
            return(true);
        }
Exemplo n.º 8
0
 public void Save()
 {
     PLCDeviceManager.GetPLCDeviceManager().SetSelectDeviceType((PLCDeviceType)Enum.ToObject(typeof(PLCDeviceType), MainList.SelectedIndex));
 }
Exemplo n.º 9
0
 static DeviceSelectionWidget()
 {
     _widget = new List <UserControl>(PLCDeviceManager.GetPLCDeviceManager().GetDeviceMessageDialogs());
 }
Exemplo n.º 10
0
 public DeviceSelectionWidget()
 {
     InitializeComponent();
     DataContext = PLCDeviceManager.GetPLCDeviceManager();
 }
Exemplo n.º 11
0
 private void PLCDeviceType_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     FilterCollectionByDeviceType(_elementCollection, PLCDeviceManager.GetPLCDeviceManager().SelectDevice);
     UpdateElementCollection();
     RangePropertyChanged();
 }
Exemplo n.º 12
0
 private void LoadElements()
 {
     FilterCollectionByDeviceType(_elementCollection, PLCDeviceManager.GetPLCDeviceManager().SelectDevice);
     RangePropertyChanged();
     UpdateElementCollection();
 }
Exemplo n.º 13
0
        /// <summary>
        /// 仿真线程要运行的函数(图表模式)
        /// </summary>
        public void _SimulateThread_Chart()
        {
            PLCDevice.Device device = PLCDeviceManager.GetPLCDeviceManager().SelectDevice;
            SetBaseBit(device.BitNumber);
            SetClockRate(1);
            InitRunLadder();
            InitClock(TimeStart);
            // 当前时间
            int    time     = GetClock();
            int    count    = 0;
            double progress = 0.0;

            while (simulateActive)
            {
                count++;
                // 设置锁定的视点
                foreach (SimulateDataModel sdmodel in locksdmodels)
                {
                    sdmodel.Set(this, time);
                }

                while (!simulateRunning)
                {
                    if (!simulateActive)
                    {
                        break;
                    }
                    Thread.Sleep(10);
                }
                if (!simulateActive)
                {
                    break;
                }
                BeforeRunLadder();
                try
                {
                    RunLadder();
                }
                // 触发异常时发送事件,并暂停运行等待处理
                catch (Exception exce)
                {
                    SimulateException(exce, new RoutedEventArgs());
                    simulateRunning = false;
                }
                AfterRunLadder();
                // 检查是否超过终止时间
                time = GetClock();
                if (time >= TimeEnd)
                {
                    simulateActive = false;
                }
                if (!simulateActive)
                {
                    break;
                }

                double _progress = (double)(time - TimeStart) / (TimeEnd - TimeStart) * 100;
                if (_progress - progress > 1.0)
                {
                    progress = _progress;
                    SimulateProgress(progress, new RoutedEventArgs());
                }
                // 读取监视的视点
                foreach (SimulateDataModel sdmodel in viewsdmodels)
                {
                    sdmodel.Update(this, time);
                }
            }
            // 发送线程终止的事件
            SimulateAbort(this, new RoutedEventArgs());
        }