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 }
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("属性修改失败!"); } } }