Beispiel #1
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));
                    }
                }
            }
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
        public static byte?GetAddrType(ElementAddressType type, uint offset)
        {
            switch (type)
            {
            case ElementAddressType.X:
                return(CommunicationDataDefine.ADDRESS_TYPE_X);

            case ElementAddressType.Y:
                return(CommunicationDataDefine.ADDRESS_TYPE_Y);

            case ElementAddressType.M:
                return(CommunicationDataDefine.ADDRESS_TYPE_M);

            case ElementAddressType.S:
                return(CommunicationDataDefine.ADDRESS_TYPE_S);

            case ElementAddressType.C:
                return(CommunicationDataDefine.ADDRESS_TYPE_C);

            case ElementAddressType.T:
                return(CommunicationDataDefine.ADDRESS_TYPE_T);

            case ElementAddressType.D:
                return(CommunicationDataDefine.ADDRESS_TYPE_D);

            case ElementAddressType.V:
                return(CommunicationDataDefine.ADDRESS_TYPE_V);

            case ElementAddressType.Z:
                return(CommunicationDataDefine.ADDRESS_TYPE_Z);

            case ElementAddressType.CV:
                if (offset >= 200)
                {
                    return(CommunicationDataDefine.ADDRESS_TYPE_CV32);
                }
                else
                {
                    return(CommunicationDataDefine.ADDRESS_TYPE_CV);
                }

            case ElementAddressType.TV:
                return(CommunicationDataDefine.ADDRESS_TYPE_TV);

            case ElementAddressType.AI:
                return(CommunicationDataDefine.ADDRESS_TYPE_AI);

            case ElementAddressType.AO:
                return(CommunicationDataDefine.ADDRESS_TYPE_AO);

            default:
                return(null);
            }
        }
Beispiel #4
0
        public static bool IsBitAddr(ElementAddressType Type)
        {
            switch (Type)
            {
            case ElementAddressType.X:
            case ElementAddressType.Y:
            case ElementAddressType.M:
            case ElementAddressType.S:
            case ElementAddressType.C:
            case ElementAddressType.T:
                return(true);

            default:
                return(false);
            }
        }
Beispiel #5
0
        public static bool AssertAddrRange(ElementAddressType type, uint value, Device CurrentDevice)
        {
            switch (type)
            {
            case ElementAddressType.X:
                return(CurrentDevice.XRange.AssertValue(value));

            case ElementAddressType.Y:
                return(CurrentDevice.YRange.AssertValue(value));

            case ElementAddressType.M:
                return(CurrentDevice.MRange.AssertValue(value));

            case ElementAddressType.S:
                return(CurrentDevice.SRange.AssertValue(value));

            case ElementAddressType.C:
                return(CurrentDevice.CRange.AssertValue(value));

            case ElementAddressType.T:
                return(CurrentDevice.TRange.AssertValue(value));

            case ElementAddressType.D:
                return(CurrentDevice.DRange.AssertValue(value));

            case ElementAddressType.V:
                return(CurrentDevice.VRange.AssertValue(value));

            case ElementAddressType.Z:
                return(CurrentDevice.ZRange.AssertValue(value));

            case ElementAddressType.CV:
                return(CurrentDevice.CVRange.AssertValue(value));

            case ElementAddressType.TV:
                return(CurrentDevice.TVRange.AssertValue(value));

            case ElementAddressType.AI:
                return(CurrentDevice.AIRange.AssertValue(value));

            case ElementAddressType.AO:
                return(CurrentDevice.AORange.AssertValue(value));

            default:
                return(false);
            }
        }