Example #1
0
        public void ScanState()
        {
            Collection devCollection = (Collection)Application.Current.Properties["MonitorCollection"];
            while (true)
            {
                using (Bus.DataBusServiceClient client = new Bus.DataBusServiceClient())
                {
                    DeviceSign[] devArr = devCollection.GetDeviceIDList();

                    DeviceDynamic device;

                    foreach (var item in devArr)
                    {
                        device = devCollection.GetDevice(item.dev_id,item.mon_id);

                        string []  statelist=device.GetStateName();

                        DynamicState state;
                        Bus.AttributeValue attVal;

                        foreach(var stateitem in statelist)
                        {

                        Bus.DeviceState busquerystate = new Bus.DeviceState();
                        busquerystate.AgentID = device.Monitor_ID;
                        busquerystate.DevType = device.Dev_Type;
                        busquerystate.DevID = device.Device_ID;
                        busquerystate.Name = stateitem;
                        attVal = client.QueryStateTest(busquerystate);

                        if (attVal != null)
                        {
                            AttributeValue stateVal = new AttributeValue(attVal.Type, attVal.Value);

                            state = new DynamicState(stateitem, device.Device_ID,device.Monitor_ID, device.Dev_Type);
                            state.StateValue = stateVal;
                            device.ChangeStateValue(state);
                        }

                        }/////单个设备所以状态扫描

                    }///所有设备集合扫描
                } ///服务端口开

                Thread.Sleep(scantime);
            }////线程循环
        }
        private void Button_ClickSet(object sender, RoutedEventArgs e)
        {
            Button source = e.Source as Button;
            DockPanel txtblock = source.Parent as DockPanel;
            Label leb = (Label)txtblock.FindName("state_name");
            TextBox txtbox = (TextBox)txtblock.FindName("state_value");
            string state_name =(string)leb.Content;
            string state_value = (string)txtbox.Text;

            /*********************************************
              仅供下变频器设置频率,需要设计逻辑层
             *********************************************/
            double val = Double.Parse(state_value);
            Bus.AttributeValue staval=new Bus.AttributeValue();

            staval.Type="double";
            staval.Value=val;

            Collection devCollection=(Collection)Application.Current.Properties["MonitorCollection"];
            DeviceDynamic device=devCollection.GetDevice(dev_id,mon_id);

               // MessageBox.Show(string.Format("{0} 数据不合法!",state_value));

            Bus.DeviceState deviceState = new Bus.DeviceState();

            deviceState.AgentID = device.Monitor_ID;
            deviceState.DevID = device.Device_ID;
            deviceState.DevType = device.Dev_Type;
            deviceState.Name = state_name;
            deviceState.Value = staval;

            using (Bus.DataBusServiceClient client = new WpfDataBingding.TaskServiceReference.DataBusServiceClient())
            {
              bool issucess=client.SetStates(new Bus.DeviceState[]{deviceState});
              if (issucess == true)
              {
                  MessageBox.Show("属性设置成功!");
              }
              else
              {
                  MessageBox.Show("属性修改失败!");
              }
            }
        }
Example #3
0
        public static ChangeStateBackInfo ChangeDeviceDynamicState(DynamicState dyState, string strValue)
        {
            ChangeStateBackInfo backinfo;
            #region////暂用版本
            try
            {
            double val = Double.Parse(strValue);
            Bus.AttributeValue staval = new Bus.AttributeValue();

            staval.Type = "double";
            staval.Value = val;

            Bus.DeviceState deviceState = new Bus.DeviceState();

            deviceState.AgentID = dyState.AgentName;
            deviceState.DevID = dyState.DevID;
            deviceState.DevType = "XBPQ";
            deviceState.Name = dyState.StateName;
            deviceState.Value = staval;

                using (Bus.DataBusServiceClient client = new WpfDataBingding.TaskServiceReference.DataBusServiceClient())
                {
                    bool issucess = client.SetStates(new Bus.DeviceState[] { deviceState });
                    if (issucess == true)
                    {
                        backinfo = new ChangeStateBackInfo { isSucess=true, info=string.Empty};
                    }
                    else
                    {
                        backinfo = new ChangeStateBackInfo {  isSucess=false, info = string.Empty };
                    }
                    client.Close();
                }
            }
            catch(Exception e)
            {
                backinfo = new ChangeStateBackInfo { isSucess=false, info=e.Message.ToString() };
                return backinfo;
            }

            return backinfo;
            #endregion
        }
Example #4
0
        /*********************************************
        初始化监控状态
        *********************************************/
        public void GenerateSate(Bus.UserMonTask usertask, Bus.DataBusServiceClient client)
        {
            var state_list = usertask.MonTaskList.GroupBy(c => new { c.DevID, c.AgentName });
               {
               Collection monCollection = (Collection)Application.Current.Properties["MonitorCollection"];
               DeviceDynamic device;

               foreach (var item in state_list)
               {

                   device = monCollection.GetDevice(item.Key.DevID,item.Key.AgentName);
                   DynamicState state;
                   Bus.AttributeValue attVal;

                   foreach(var deviceitem in item)
                   {

                       {
                           Bus.DeviceState busquerystate = new Bus.DeviceState();

                           busquerystate.AgentID = deviceitem.AgentName;
                           busquerystate.DevType = deviceitem.DevType;
                           busquerystate.DevID = deviceitem.DevID;
                           busquerystate.Name = deviceitem.StateName;

                           attVal=client.QueryStateTest(busquerystate);
                       }
                       if (attVal != null)
                       {
                           AttributeValue stateVal = new AttributeValue(attVal.Type, attVal.Value);

                           state = new DynamicState(deviceitem.StateName, deviceitem.DevID, deviceitem.AgentName, deviceitem.DevType, deviceitem.ViewType, deviceitem.DomainName, deviceitem.ChangeThreshold, deviceitem.TimeInterval);

                           int timeinterval = deviceitem.TimeInterval;

                           if (timeinterval < device.Scan_Time)
                           {
                               device.Scan_Time = timeinterval;
                           }
                           state.StateValue = stateVal;
                           device.AddMonitorState(state);
                       }
                   }/////查询单个状态值

               }////根据设备归类状态查询
               }
        }