Exemplo n.º 1
0
        /// <summary>
        /// Initializes the device tags.
        /// </summary>
        public override void InitDeviceTags()
        {
            TagGroup tagGroup = new TagGroup();

            tagGroup.AddTag(TagCode.Mail, TagName.Mail).Format             = TagFormat.IntNumber;
            tagGroup.AddTag(TagCode.MailAttach, TagName.MailAttach).Format = TagFormat.IntNumber;
            DeviceTags.AddGroup(tagGroup);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the device tags.
        /// </summary>
        public override void InitDeviceTags()
        {
            TagGroup tagGroup = new TagGroup("Inputs");

            tagGroup.AddTag("Sin", "Sine");
            tagGroup.AddTag("Sqr", "Square").Format = TagFormat.OffOn;
            tagGroup.AddTag("Tr", "Triangle");
            DeviceTags.AddGroup(tagGroup);

            tagGroup = new TagGroup("Outputs");
            tagGroup.AddTag("DO", "Relay State").Format = TagFormat.OffOn;
            tagGroup.AddTag("AO", "Analog Output");
            DeviceTags.AddGroup(tagGroup);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes the device tags.
        /// </summary>
        public override void InitDeviceTags()
        {
            if (opcDeviceConfig == null)
            {
                return;
            }

            foreach (SubscriptionConfig subscriptionConfig in opcDeviceConfig.Subscriptions)
            {
                TagGroup tagGroup = new TagGroup(subscriptionConfig.DisplayName);

                foreach (ItemConfig itemConfig in subscriptionConfig.Items)
                {
                    DeviceTag deviceTag = tagGroup.AddTag(itemConfig.TagCode, itemConfig.DisplayName);
                    deviceTag.Aux  = new DeviceTagMeta();
                    itemConfig.Tag = deviceTag;

                    if (itemConfig.IsString)
                    {
                        deviceTag.DataLen  = DriverUtils.GetTagDataLength(itemConfig.DataLength);
                        deviceTag.DataType = TagDataType.Unicode;
                        deviceTag.Format   = TagFormat.String;
                    }
                    else if (itemConfig.IsArray)
                    {
                        deviceTag.DataLen = itemConfig.DataLength;
                    }
                }

                DeviceTags.AddGroup(tagGroup);
            }
        }
Exemplo n.º 4
0
        public void AddTag(Tag tag)
        {
            if (_tags.Contains(tag))
            {
                return;
            }

            var logixTag = new Logix.Tag(_controlLogix)
            {
                Name     = tag.FullName(),
                DataType = IngearHelper.ParseNetLogixDataType(tag.DataType)
            };

            logixTag.Changed += TagDataChanged;

            tag.ValueChanged += TagValueChanged;

            _tags.Add(tag);
            _tagGroup.AddTag(logixTag);
        }
Exemplo n.º 5
0
        //------------------------------------------------------------------------------//
        //                                Manual Start Stop                             //
        //------------------------------------------------------------------------------//
        public void ManualStart(string ObjectNumber, bool SwitchOn)
        {
            if (MainWindow.stat_iUserLevel >= 2)
            {
                try
                {
                    if (!PLCW.IsConnected)
                        PLCW.Connect();

                    if (PLCW.IsConnected)
                    {
                        Tag tObjNo = new Tag("DB3.DBD50", S7Link.Tag.ATOMIC.DWORD, 1);
                        Tag tCmdOn = new Tag("DB3.DBX55.1", S7Link.Tag.ATOMIC.BOOL, 1);
                        Tag tCmdOff = new Tag("DB3.DBX55.0", S7Link.Tag.ATOMIC.BOOL, 1);
                        Tag tCmdManOff = new Tag("DB3.DBX57.5", S7Link.Tag.ATOMIC.BOOL, 1);
                        Tag tCmdManOn = new Tag("DB3.DBX55.5", S7Link.Tag.ATOMIC.BOOL, 1);
                        Tag tReqDefine = new Tag("DB3.DBX43.0", S7Link.Tag.ATOMIC.BOOL, 1);
                        Tag tCmdHN = new Tag("DB3.DBX55.1", S7Link.Tag.ATOMIC.BOOL, 1);

                        if (SwitchOn)
                        {
                            tObjNo.Value = ObjectNumber;
                            tCmdOn.Value = true;
                            tCmdManOn.Value = true;
                            tCmdOff.Value = false;
                            tCmdManOff.Value = false;
                            tReqDefine.Value = true;
                        }
                        else
                        {
                            tObjNo.Value = ObjectNumber;
                            tCmdOn.Value = false;
                            tCmdManOn.Value = false;
                            tCmdOff.Value = true;
                            tCmdManOff.Value = true;
                            tReqDefine.Value = true;
                        }

                        TagGroup tg1 = new TagGroup();
                        tg1.AddTag(tObjNo);
                        tg1.AddTag(tCmdOn);
                        tg1.AddTag(tCmdManOn);
                        tg1.AddTag(tCmdOff);
                        tg1.AddTag(tCmdManOff);
                        tg1.AddTag(tReqDefine);

                        PLCW.GroupWrite(tg1);
                        PLCW.Disconnect();
                        MainWindow.stat_sActiveObjectNo = "";
                    }
                    else
                    {
                        MessageBox.Show("Not Connected");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Manual Start --> " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("You do not have sufficient privileges to perform this action! ", " access denied", MessageBoxButton.OK, MessageBoxImage.Stop);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes the device tags.
        /// </summary>
        public override void InitDeviceTags()
        {
            DeviceTemplate deviceTemplate = GetDeviceTemplate();

            if (deviceTemplate == null)
            {
                return;
            }

            // create device model
            deviceModel      = CreateDeviceModel();
            deviceModel.Addr = (byte)NumAddress;

            // add model elements and device tags
            foreach (ElemGroupConfig elemGroupConfig in deviceTemplate.ElemGroups)
            {
                bool      groupActive   = elemGroupConfig.Active;
                bool      groupCommands = groupActive && elemGroupConfig.ReadOnlyEnabled;
                ElemGroup elemGroup     = null;
                TagGroup  tagGroup      = new TagGroup(elemGroupConfig.Name)
                {
                    Hidden = !groupActive
                };
                int elemIndex = 0;

                if (groupActive)
                {
                    elemGroup             = deviceModel.CreateElemGroup(elemGroupConfig.DataBlock);
                    elemGroup.Name        = elemGroupConfig.Name;
                    elemGroup.Address     = (ushort)elemGroupConfig.Address;
                    elemGroup.StartTagIdx = DeviceTags.Count;
                }

                foreach (ElemConfig elemConfig in elemGroupConfig.Elems)
                {
                    // add model element
                    if (groupActive)
                    {
                        Elem elem = elemGroup.CreateElem();
                        elem.Name      = elemConfig.Name;
                        elem.ElemType  = elemConfig.ElemType;
                        elem.ByteOrder = ModbusUtils.ParseByteOrder(elemConfig.ByteOrder) ??
                                         deviceTemplate.Options.GetDefaultByteOrder(ModbusUtils.GetDataLength(elemConfig.ElemType));
                        elemGroup.Elems.Add(elem);
                    }

                    // add model command
                    if (groupCommands && !elemConfig.ReadOnly && !string.IsNullOrEmpty(elemConfig.TagCode))
                    {
                        deviceModel.Cmds.Add(
                            CreateModbusCmd(deviceTemplate.Options, elemGroupConfig, elemConfig, elemIndex));
                    }

                    // add device tag
                    tagGroup.AddTag(elemConfig.TagCode, elemConfig.Name).SetFormat(GetTagFormat(elemConfig));
                    elemIndex++;
                }

                if (groupActive)
                {
                    elemGroup.InitReqPDU();
                    elemGroup.InitReqADU(deviceModel.Addr, transMode);
                    deviceModel.ElemGroups.Add(elemGroup);
                }

                DeviceTags.AddGroup(tagGroup);
            }

            // add model commands
            foreach (CmdConfig cmdConfig in deviceTemplate.Cmds)
            {
                deviceModel.Cmds.Add(CreateModbusCmd(deviceTemplate.Options, cmdConfig));
            }

            deviceModel.InitCmdMap();
            CanSendCommands = deviceModel.Cmds.Count > 0;
            InitModbusPoll();
        }
        private void ReadParameterValuesFromPLC()
        {
            try
            {
                //Calculate what DB Offsets to Read From
                int iStart = SwitchOverWeightDBOffset.LastIndexOf('D');
                int iLength = SwitchOverWeightDBOffset.Length;
                string s = (SwitchOverWeightDBOffset.Substring(iStart + 1, iLength - iStart - 1));
                int i1 = Convert.ToInt32(s);
                int i2 = i1 + 4;
                int i3 = i2 + 4;
                int i4 = i3 + 4;
                int i5 = i4 + 4;
                int i6 = i5 + 4;
                int i7 = i6 + 2;
                int i8 = i7 + 2;
                int i9 = i8 + 2;
                int i10 = i9 + 2;
                int i11 = i10 + 2;
                int i12 = i11 + 2;
                int i13 = i12 + 4;
                int i14 = i13 + 2;
                int i15 = i14 + 2;
                int i16 = i15 + 2;

                TagGroup tg = new TagGroup();
                Tag t1 = new Tag(ScaleDBNumber + ".DBD" + i1, S7Link.Tag.ATOMIC.DWORD, 1);
                Tag t2 = new Tag(ScaleDBNumber + ".DBD" + i2, S7Link.Tag.ATOMIC.DWORD, 1);
                Tag t3 = new Tag(ScaleDBNumber + ".DBD" + i3, S7Link.Tag.ATOMIC.DWORD, 1);
                Tag t4 = new Tag(ScaleDBNumber + ".DBD" + i4, S7Link.Tag.ATOMIC.DWORD, 1);
                Tag t5 = new Tag(ScaleDBNumber + ".DBD" + i5, S7Link.Tag.ATOMIC.DWORD, 1);
                Tag t6 = new Tag(ScaleDBNumber + ".DBW" + i6, S7Link.Tag.ATOMIC.WORD, 1);
                Tag t7 = new Tag(ScaleDBNumber + ".DBW" + i7, S7Link.Tag.ATOMIC.WORD, 1);
                Tag t8 = new Tag(ScaleDBNumber + ".DBW" + i8, S7Link.Tag.ATOMIC.WORD, 1);
                Tag t9 = new Tag(ScaleDBNumber + ".DBW" + i9, S7Link.Tag.ATOMIC.WORD, 1);
                Tag t10 = new Tag(ScaleDBNumber + ".DBW" + i10, S7Link.Tag.ATOMIC.WORD, 1);
                Tag t11 = new Tag(ScaleDBNumber + ".DBW" + i11, S7Link.Tag.ATOMIC.WORD, 1);
                Tag t12 = new Tag(ScaleDBNumber + ".DBD" + i12, S7Link.Tag.ATOMIC.DWORD, 1);
                Tag t13 = new Tag(ScaleDBNumber + ".DBW" + i13, S7Link.Tag.ATOMIC.WORD, 1);
                Tag t14 = new Tag(ScaleDBNumber + ".DBW" + i14, S7Link.Tag.ATOMIC.WORD, 1);
                Tag t15 = new Tag(ScaleDBNumber + ".DBW" + i15, S7Link.Tag.ATOMIC.WORD, 1);
                Tag t16 = new Tag(ScaleDBNumber + ".DBD" + i16, S7Link.Tag.ATOMIC.DWORD, 1);

                tg.AddTag(t1);
                tg.AddTag(t2);
                tg.AddTag(t3);
                tg.AddTag(t4);
                tg.AddTag(t5);
                tg.AddTag(t6);
                tg.AddTag(t7);
                tg.AddTag(t8);
                tg.AddTag(t9);
                tg.AddTag(t10);
                tg.AddTag(t11);
                tg.AddTag(t12);
                tg.AddTag(t13);
                tg.AddTag(t14);
                tg.AddTag(t15);
                tg.AddTag(t16);

                if (!PLCR.IsConnected)
                    PLCR.Connect();

                PLCR.GroupRead(tg);

                SwitchOverWeight_Online = Convert.ToDouble(t1.Value) / 1000;
                CutOffWeight_Online = Convert.ToDouble(t2.Value) / 1000;
                TolerancePositiveWeight_Online = Convert.ToDouble(t3.Value) / 1000;
                ToleranceNegativeWeight_Online = Convert.ToDouble(t4.Value) / 1000;
                CutOffWeightCorrectionMax_Online = Convert.ToDouble(t5.Value) / 1000;
                DosingTimeSlow_Online = Convert.ToDouble(t6.Value) / 10;
                SwitchOverTimeFastToSlow_Online = Convert.ToDouble(t7.Value) / 10;
                TipPulseLength_Online = Convert.ToDouble(t8.Value) / 10;
                DosingTimeMax_Online = Convert.ToDouble(t9.Value) / 10;
                TolerancePositiveProportion_Online = Convert.ToDouble(t10.Value);
                ToleranceNegativeProportion_Online = Convert.ToDouble(t11.Value);
                AutoFaultResetWeight_Online = Convert.ToDouble(t12.Value) / 1000;
                AutoFaultResetPercent_Online = Convert.ToDouble(t13.Value);
                DosingSpeedFast_Online = Convert.ToDouble(t14.Value);
                DosingSpeedSlow_Online = Convert.ToDouble(t15.Value);
                FineDosingWeight_Online = Convert.ToDouble(t16.Value) / 1000;
            }
            catch (Exception ex)
            {
                var msgBox = base.GetService<IMessageBoxService>();
                if (msgBox != null)
                    msgBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public void cmdDownloadParametersImplementation()
        {
            try
            {
                var msgBox = base.GetService<IMessageBoxService>();
                if (msgBox != null)
                {
                    var result = msgBox.Show("Are you sure you want to download the OFFLINE values to the PLC? This will OVERWRITE ONLINE values.", "Confrim Download. OFFLINE --> ONLINE", MessageBoxButton.YesNo, MessageBoxImage.Question);

                    if (result == MessageBoxResult.Yes)
                    {
                        //Calculate what DB Offsets to Read From
                        int iStart = SwitchOverWeightDBOffset.LastIndexOf('D');
                        int iLength = SwitchOverWeightDBOffset.Length;
                        string s = (SwitchOverWeightDBOffset.Substring(iStart + 1, iLength - iStart - 1));
                        int i1 = Convert.ToInt32(s);
                        int i2 = i1 + 4;
                        int i3 = i2 + 4;
                        int i4 = i3 + 4;
                        int i5 = i4 + 4;
                        int i6 = i5 + 4;
                        int i7 = i6 + 2;
                        int i8 = i7 + 2;
                        int i9 = i8 + 2;
                        int i10 = i9 + 2;
                        int i11 = i10 + 2;
                        int i12 = i11 + 2;
                        int i13 = i12 + 4;
                        int i14 = i13 + 2;
                        int i15 = i14 + 2;
                        int i16 = i15 + 2;

                        TagGroup tg = new TagGroup();
                        Tag t1 = new Tag(ScaleDBNumber + ".DBD" + i1, S7Link.Tag.ATOMIC.DWORD, 1);
                        Tag t2 = new Tag(ScaleDBNumber + ".DBD" + i2, S7Link.Tag.ATOMIC.DWORD, 1);
                        Tag t3 = new Tag(ScaleDBNumber + ".DBD" + i3, S7Link.Tag.ATOMIC.DWORD, 1);
                        Tag t4 = new Tag(ScaleDBNumber + ".DBD" + i4, S7Link.Tag.ATOMIC.DWORD, 1);
                        Tag t5 = new Tag(ScaleDBNumber + ".DBD" + i5, S7Link.Tag.ATOMIC.DWORD, 1);
                        Tag t6 = new Tag(ScaleDBNumber + ".DBW" + i6, S7Link.Tag.ATOMIC.WORD, 1);
                        Tag t7 = new Tag(ScaleDBNumber + ".DBW" + i7, S7Link.Tag.ATOMIC.WORD, 1);
                        Tag t8 = new Tag(ScaleDBNumber + ".DBW" + i8, S7Link.Tag.ATOMIC.WORD, 1);
                        Tag t9 = new Tag(ScaleDBNumber + ".DBW" + i9, S7Link.Tag.ATOMIC.WORD, 1);
                        Tag t10 = new Tag(ScaleDBNumber + ".DBW" + i10, S7Link.Tag.ATOMIC.WORD, 1);
                        Tag t11 = new Tag(ScaleDBNumber + ".DBW" + i11, S7Link.Tag.ATOMIC.WORD, 1);
                        Tag t12 = new Tag(ScaleDBNumber + ".DBD" + i12, S7Link.Tag.ATOMIC.DWORD, 1);
                        Tag t13 = new Tag(ScaleDBNumber + ".DBW" + i13, S7Link.Tag.ATOMIC.WORD, 1);
                        Tag t14 = new Tag(ScaleDBNumber + ".DBW" + i14, S7Link.Tag.ATOMIC.WORD, 1);
                        Tag t15 = new Tag(ScaleDBNumber + ".DBW" + i15, S7Link.Tag.ATOMIC.WORD, 1);
                        Tag t16 = new Tag(ScaleDBNumber + ".DBD" + i16, S7Link.Tag.ATOMIC.DWORD, 1);

                        t1.Value = SwitchOverWeight * 1000;
                        t2.Value = CutOffWeight * 1000;
                        t3.Value = TolerancePositiveWeight * 1000;
                        t4.Value = ToleranceNegativeWeight * 1000;
                        t5.Value = CutOffWeightCorrectionMax * 1000;
                        t6.Value = DosingTimeSlow * 10;
                        t7.Value = SwitchOverTimeFastToSlow * 10;
                        t8.Value = TipPulseLength * 10;
                        t9.Value = DosingTimeMax * 10;
                        t10.Value = TolerancePositiveProportion;
                        t11.Value = ToleranceNegativeProportion;
                        t12.Value = AutoFaultResetWeight * 1000;
                        t13.Value = AutoFaultResetPercent;
                        t14.Value = DosingSpeedFast;
                        t15.Value = DosingSpeedSlow;
                        t16.Value = FineDosingWeight * 1000;

                        tg.AddTag(t1);
                        tg.AddTag(t2);
                        tg.AddTag(t3);
                        tg.AddTag(t4);
                        tg.AddTag(t5);
                        tg.AddTag(t6);
                        tg.AddTag(t7);
                        tg.AddTag(t8);
                        tg.AddTag(t9);
                        tg.AddTag(t10);
                        tg.AddTag(t11);
                        tg.AddTag(t12);
                        tg.AddTag(t13);
                        tg.AddTag(t14);
                        tg.AddTag(t15);
                        tg.AddTag(t16);

                        if (!PLCW.IsConnected)
                            PLCW.Connect();

                        PLCR.GroupWrite(tg);

                        ReadParameterValuesFromPLC();
                    }
                }

            }
            catch (Exception ex)
            {
                var msgBox = base.GetService<IMessageBoxService>();
                if (msgBox != null)
                    msgBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }