Esempio n. 1
0
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || value == "")
            {
                return(null);
            }
            String input           = (String)value;
            Match  ControllerMatch = Regex.Match(input, @"\[(.*?)\]");

            if (!ControllerMatch.Success)
            {
                throw new Exception("Invalid tag string");
            }

            String ControllerName      = ControllerMatch.Value.Substring(1, ControllerMatch.Value.Length - 2);
            var    MatchingControllers = ActiveModel.Controllers.Where(p => p.Name == ControllerName);

            if (MatchingControllers.Count() == 0)
            {
                throw new Exception("Invalid controller name");
            }
            Model.ControllersRow Controller = MatchingControllers.First();

            String TagName      = input.Substring(input.LastIndexOf(']') + 1);
            var    MatchingTags = ActiveModel.Tags.Where(p => p.Controller == Controller.PK && (p.Address == TagName || p.Name == TagName));

            return(MatchingTags.First().PK);
        }
Esempio n. 2
0
 public ModbusTcp(Model.ControllersRow ControllerInfo)
 {
     if (ControllerInfo.Address == "localhost")
     {
         Comm.IPAddress = "127.0.0.1";
     }
     else
     {
         Comm.IPAddress = ControllerInfo.Address;
     }
     Comm.TcpipPort = (ushort)ControllerInfo.modbus_port;
 }
Esempio n. 3
0
 private void OnCopyController()
 {
     Model.ControllersRow NewRow = ActiveModel.Controllers.NewControllersRow();
     foreach (DataColumn col in ActiveModel.Controllers.Columns)
     {
         if (col.ColumnName != "PK")
         {
             NewRow[col.ColumnName] = SelectedController[col.ColumnName];
         }
     }
     ActiveModel.Controllers.AddControllersRow(NewRow);
 }
Esempio n. 4
0
 public OPC(Model.ControllersRow controllerInfo)
 {
     try
     {
         ControllerInfo = controllerInfo;
         String OpcName = "plcdb-" + ControllerInfo.PK;
         Server   = new DAServer(ControllerInfo.opc_server, ControllerInfo.Address);
         TagGroup = Server.AddGroup(Interlocked.Increment(ref GroupClientId), OpcName, true, 100, (float)0.0);
     }
     catch (Exception ex)
     {
         Log.Error("Error creating OPC connection: " + ex.Message);
     }
 }
Esempio n. 5
0
        private void btnAddNewController_Click(object sender, RoutedEventArgs e)
        {
            ControllerConfigPopup popup = new ControllerConfigPopup();
            var vm = this.DataContext as MainWindowViewModel;

            Model.ControllersRow NewRow = vm.ActiveModel.Controllers.NewControllersRow();
            NewRow.Name    = "New Controller";
            NewRow.Address = "";
            NewRow.Type    = null;
            vm.ActiveModel.Controllers.AddControllersRow(NewRow);
            popup.DataContext = new ControllerPopupViewModel()
            {
                CurrentController = NewRow,
            };
            popup.ShowDialog();
        }
Esempio n. 6
0
        public override ValidationResult Validate(object value, CultureInfo ultureInfo)
        {
            if (value == null || value == "")
            {
                return(new ValidationResult(false, "Invalid controller name"));
            }
            String input           = (String)value;
            Match  ControllerMatch = Regex.Match(input, @"\[(.*?)\]");

            if (!ControllerMatch.Success)
            {
                return(new ValidationResult(false, "Invalid controller name"));
            }

            String ControllerName      = ControllerMatch.Value.Substring(1, ControllerMatch.Value.Length - 2);
            var    MatchingControllers = ActiveModel.Controllers.Where(p => p.Name == ControllerName);

            if (MatchingControllers.Count() == 0)
            {
                return(new ValidationResult(false, "Invalid controller name"));
            }
            Model.ControllersRow Controller = MatchingControllers.First();

            String TagName      = input.Substring(input.LastIndexOf(']') + 1);
            var    MatchingTags = ActiveModel.Tags.Where(p => p.Controller == Controller.PK && (p.Address == TagName || p.Name == TagName));

            bool ValidNewTag = Controller.Controller.ValidateTag(TagName);

            if (MatchingTags.Count() == 0 && !ValidNewTag)
            {
                return(new ValidationResult(false, "Invalid tag address"));
            }
            else if (MatchingTags.Count() == 0 && ValidNewTag)
            {
                Model.TagsRow NewRow = ActiveModel.Tags.NewTagsRow();
                NewRow.Address    = TagName;
                NewRow.Name       = TagName;
                NewRow.Controller = Controller.PK;
                ActiveModel.Tags.AddTagsRow(NewRow);
                return(new ValidationResult(true, null));;
            }

            return(new ValidationResult(true, null));
        }
Esempio n. 7
0
 public Simulator(Model.ControllersRow row)
 {
     ControllerInfo = row;
 }
Esempio n. 8
0
 public ControllerBase(Model.ControllersRow args)
 {
 }
Esempio n. 9
0
 public SiemensS7(Model.ControllersRow ControllerInfo)
 {
     this.ControllerInfo = ControllerInfo;
 }