コード例 #1
0
        public static string AddDigitalInputTag(string tagId, string description, string driver, string ioAddress, int scanTime, bool onScan)
        {
            if (!TagConfig.Keys.Contains(tagId))
            {
                DITag di = new DITag()
                {
                    TagId       = tagId,
                    Description = description,
                    Driver      = driver,
                    IOAddress   = ioAddress,
                    ScanTime    = scanTime,
                    OnScan      = onScan
                };

                lock (locker)
                {
                    TagConfig.Add(di.TagId, di);
                    TagCurrentValues.Add(di.TagId, di.GetValue());

                    tagdb.Tags.Add(new TagValueInfo(di.TagId, 555));
                    tagdb.SaveChanges();

                    TagProcessingThreads.Add(di.TagId, new Thread(() => ScanTag(di.TagId)));
                    TagProcessingThreads[tagId].Start();
                }

                UpdateConfig();

                return("Tag added successfully");
            }

            return("Tag already exists");
        }
コード例 #2
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            Tag t = null;

            switch (tagType.SelectedItem)
            {
            case "Digital input":
                if (string.IsNullOrEmpty(tagName.Text) || string.IsNullOrEmpty(description.Text) || scanTime.Value < 1 || alarmCeiling.Value < alarmFloor.Value)
                {
                    return;
                }
                t = new DITag(tagName.Text, description.Text, (int)ioAddress.Value, selDriver, (int)scanTime.Value, new Alarm((int)alarmCeiling.Value, (int)alarmFloor.Value), scan.Checked, auto.Checked);
                break;

            case "Digital output":
                if (string.IsNullOrEmpty(tagName.Text) || string.IsNullOrEmpty(description.Text))
                {
                    return;
                }
                t = new DOTag(tagName.Text, description.Text, (int)ioAddress.Value, selDriver, (int)initialValue.Value);
                break;

            case "Analog input":
                if (string.IsNullOrEmpty(tagName.Text) || string.IsNullOrEmpty(description.Text) || scanTime.Value < 1 || alarmCeiling.Value < alarmFloor.Value || limitLow.Value > limitHigh.Value || string.IsNullOrEmpty(units.Text))
                {
                    return;
                }
                t = new AITag(tagName.Text, description.Text, (int)ioAddress.Value, selDriver, (int)scanTime.Value, new Alarm((int)alarmCeiling.Value, (int)alarmFloor.Value), scan.Checked, auto.Checked, (int)limitLow.Value, (int)limitHigh.Value, units.Text);
                break;

            case "Analog output":
                if (string.IsNullOrEmpty(tagName.Text) || string.IsNullOrEmpty(description.Text) || limitLow.Value > limitHigh.Value || string.IsNullOrEmpty(units.Text))
                {
                    return;
                }
                t = new AOTag(tagName.Text, description.Text, (int)ioAddress.Value, selDriver, (int)initialValue.Value, (int)limitLow.Value, (int)limitHigh.Value, units.Text);
                break;

            default:
                break;
            }

            if (proxy.addTag(t))
            {
                var item = listViewTag.Items.Add(new ListViewItem(tagName.Text));
                item.SubItems.Add(description.Text);
                item.SubItems.Add(selDriver.ToString());
                item.SubItems.Add(ioAddress.Value.ToString());
                item.SubItems.Add(scanTime.Value.ToString());
                item.SubItems.Add(alarmFloor.Value.ToString());
                item.SubItems.Add(alarmCeiling.Value.ToString());
                item.SubItems.Add(scan.Checked ? "Yes" : "No");
                item.SubItems.Add(auto.Checked ? "Yes" : "No");
                item.SubItems.Add(initialValue.Value.ToString());
                item.SubItems.Add(limitLow.Value.ToString());
                item.SubItems.Add(limitHigh.Value.ToString());
                item.SubItems.Add(units.Text);
            }
        }