public AnalogInput(string id, string description, Driver driver, string io_address, int scanTime,
                    scanType scan, readType read, int lowLim, int highLim, string units) : base(id, description,
                                                                                                driver, io_address, scanTime, scan, read)
 {
     this.lowLimits  = lowLim;
     this.highLimits = highLim;
     this.units      = units;
 }
Beispiel #2
0
 public TagInput(string id, string description, Driver driver, string io_address,
                 int scanTime, scanType scan, readType read) : base(id, description, driver, io_address)
 {
     this.scanTime = scanTime;
     this.scan     = scan;
     this.read     = read;
     this.alarms   = new List <Alarm>();
 }
Beispiel #3
0
    public void SetReadType(int read)
    {
        switch (read)
        {
        case 0:
            read_Type = readType.QR;
            break;

        case 1:
            read_Type = readType.BarCode;
            break;

        default:
            break;
        }
    }
Beispiel #4
0
        /// <summary>
        /// 读文本文件
        /// <param name="rt">文件打开方式</param>
        /// </summary>
        /// <returns>返回文本文件内容,异常返回空</returns>
        public string openFile(readType rt)
        {
            try
            {
                //判断文件是否存在,不存在返回空字符串
                if (System.IO.File.Exists(strPath) == false)
                {
                    return("");
                }
                else
                {
                    //创建StreamReader对象sr
                    StreamReader sr  = new StreamReader(strPath, System.Text.Encoding.UTF8, true);
                    string       str = "";
                    switch (rt)
                    {
                    case readType.ReadAll:
                        str = sr.ReadToEnd();
                        break;

                    case readType.ReadLine:
                        str = sr.ReadLine();
                        break;
                    }
                    sr.Close();
                    return(str);
                }
            }
            catch (FileNotFoundException)
            { //找不到文件异常
                return("");
            }

            catch (FileLoadException)
            { return(""); }
            catch (DirectoryNotFoundException)
            { return(""); }
            catch (UnauthorizedAccessException)
            { return(""); }
            catch (IOException)
            { return(""); }
        }
Beispiel #5
0
 public DigitalInput(string id, string description, Driver driver, string io_address,
                     int scanTime, scanType scan, readType read) : base(id, description, driver, io_address, scanTime, scan, read)
 {
 }
Beispiel #6
0
        public bool addTag(bool editing, List <Alarm> alarms)
        {
            var tokens = tagTypeComboBox.SelectedItem.ToString().Split(':');

            string id      = tagNameTextBox.Text;
            string descr   = tagDescrTextBox.Text;
            string driver  = tagDriverComboBox.SelectedItem.ToString();
            string address = tagAddressComboBox.SelectedItem.ToString();

            scanType scan = scanType.ON;
            readType read = readType.AUTO;

            if (tagScanComboBox.SelectedItem != null)
            {
                if (tagScanComboBox.Text.ToLower().Equals("on"))
                {
                    scan = scanType.ON;
                }
                else
                {
                    scan = scanType.OFF;
                }
            }

            if (tagReadDataTypeComboBox.SelectedItem != null)
            {
                if (tagReadDataTypeComboBox.Text.ToLower().Equals("auto"))
                {
                    read = readType.AUTO;
                }
                else
                {
                    read = readType.MANUAL;
                }
            }

            var driverTokens = tagDriverComboBox.SelectedItem.ToString().Split(':');

            bool response = true;

            switch (tokens[1].Trim())
            {
            case "Digital input":

                DigitalInput di;
                try
                {
                    di = new DigitalInput(id, descr, null, address,
                                          Int32.Parse(tagScanTimeTextBox.Text), scan, read);
                } catch (FormatException)
                {
                    MessageBox.Show("Please enter a number on tag scan time");
                    return(false);
                }

                if (di.ScanTime < 1)
                {
                    MessageBox.Show("Scan time must be > 1");
                    return(false);
                }

                if (editing)
                {
                    di.Alarms = alarms;
                }

                response = service.addTag(di, driverTokens[1].Trim());

                break;

            case "Digital output":

                DigitalOutput dig_out;

                try
                {
                    dig_out = new DigitalOutput(id, descr, null, address,
                                                Int32.Parse(tagInitValueTextBox.Text));
                } catch (FormatException)
                {
                    MessageBox.Show("Please enter a number in init value");
                    return(false);
                }

                response = service.addTag(dig_out, driverTokens[1].Trim());

                break;

            case "Analog input":

                AnalogInput analog_input;

                try
                {
                    analog_input = new AnalogInput(id, descr, null, address, Int32.Parse(tagScanTimeTextBox.Text),
                                                   scan, read, Int32.Parse(tagLowLimitTextBox.Text), Int32.Parse(tagHighLimitTextBox.Text), tagDescrTextBox.Text);
                } catch (FormatException)
                {
                    MessageBox.Show("Please enter a number on scan time, low and high limits");
                    return(false);
                }

                if (analog_input.ScanTime < 1)
                {
                    MessageBox.Show("Scan time must be > 1");
                    return(false);
                }

                if (editing)
                {
                    analog_input.Alarms = alarms;
                }

                response = service.addTag(analog_input, driverTokens[1].Trim());
                break;

            case "Analog output":

                AnalogOutput analog_output;

                try
                {
                    analog_output = new AnalogOutput(id, descr, null, address, Int32.Parse(tagInitValueTextBox.Text),
                                                     Int32.Parse(tagLowLimitTextBox.Text), Int32.Parse(tagHighLimitTextBox.Text), tagDescrTextBox.Text);
                } catch (FormatException)
                {
                    MessageBox.Show("Please enter a number on scan time, low and high limits");
                    return(false);
                }

                response = service.addTag(analog_output, driverTokens[1].Trim());
                break;
            }

            if (!response)
            {
                MessageBox.Show($"Tag name {tagNameTextBox.Text} already exists");
                return(false);
            }

            displayAllTags();
            return(true);
        }