public AddressDlg(GXProperty property)
		{
			InitializeComponent();			
            m_Property = property;
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;
            //Update resources..            
            nameLbl.Text = "OBIS " + Gurux.IEC62056_21.AddIn.Properties.Resources.AddressTxt;            
		}
 object GetWriteData(GXProperty prop, byte functionCode)
 {
     if (functionCode == 5)
     {
         return Convert.ToBoolean(prop.GetValue(true)) ? 0xFF00 : 0x0;
     }
     if (functionCode == 6)
     {
         return prop.GetValue(false);
     }
     throw new Exception("Write failed. Invalid Function code. " + functionCode.ToString());
 }        
		public object UIValueToDeviceValue(GXProperty sender, object value)
		{
			//TODO: implement
			return value;
		}
		public object DeviceValueToUIValue(GXProperty sender, object value)
		{
            GXMBusProperty prop = sender as GXMBusProperty;
            byte[] data = (byte[]) value;

			if (value is byte[])
			{
				//TODO: implement BCD and DateTime handling
				//BCD methods are in #region BCD converters
				byte[] val = value as byte[];
				switch (val.Length)
				{
					case 1:
						return val[0];
					case 2:
						return BitConverter.ToUInt16(val, 0);
					case 4:
						return BitConverter.ToUInt32(val, 0);
					case 8:
						return BitConverter.ToUInt64(val, 0);
				}
			}
			return value;
		}
		public object DeviceValueToUIValue(GXProperty sender, object value)
		{
            DataType dt = (sender as GXIEC62056Property).DataType;
            if (!(value is DateTime))
            {                
                if (dt == DataType.DateTime)
                {
                    return Parser.IEC62056Parser.StringToDateTime(value.ToString());
                }
                else if (dt == DataType.Date)
                {
                    return Parser.IEC62056Parser.StringToDateTime(value.ToString()).ToShortDateString();
                }
                else if (dt == DataType.Time)
                {
                    return Parser.IEC62056Parser.StringToTime(value.ToString());
                }
            }
            if (dt == DataType.OctetString)
            {
                value = ASCIIEncoding.ASCII.GetString(GXCommon.HexToBytes(value.ToString(), false));
            }
            return value;
		}
		public object UIValueToDeviceValue(GXProperty sender, object value)
		{
            if (sender.ValueType == typeof(DateTime))
			{
                return Parser.IEC62056Parser.DateTimeToString((DateTime)value, true);
			}
			return value;
		}
Ejemplo n.º 7
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public GXPropertyEventArgs(GXProperty prop, PropertyStates status)
     : base(prop)
 {
     Status = status;
 }
Ejemplo n.º 8
0
		/// <summary>
		/// Creates a new instance of all protocol addin GXProperty Types.
		/// </summary>
        public GXProperty[] GetProperties(object parent)
        {
			Type[] types = this.GetPropertyTypes(parent);
            GXProperty[] properties = new GXProperty[types.Length];
            for (int pos = 0; pos != types.Length; ++pos)
            {
                properties[pos] = Activator.CreateInstance(types[pos]) as GXProperty;
            }
            return properties;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// New device has selected. Select device but don't notify it.
        /// </summary>
        public virtual void OnSelectedItemChanged(object sender, GXSelectedItemEventArgs e)
        {
            try
            {
                DeviceListTree.AfterSelect -= new TreeViewEventHandler(OnAfterSelect);
                if (DeviceListTree.SelectedNode != e.NewItem)
                {
                    if (e.NewItem != null)
                    {
                        TreeNode node = (TreeNode)DeviceToTreeNode[e.NewItem];
                        DeviceListTree.SelectedNode = node;
                        if (node != null)
                        {
                            node.EnsureVisible();
                        }
                    }
                    else
                    {
                        DeviceListTree.SelectedNode = null;
                    }
                    bool showDeviceList = e.NewItem is GXDeviceList || e.NewItem is GXDeviceGroup;
                    bool showPropertyList = e.NewItem is GXCategory;
                    bool showPropertyInfo = e.NewItem is GXProperty;
                    GXDevice device = e.NewItem as GXDevice;
                    GXTable table = e.NewItem as GXTable;
                    if (showDeviceList)
                    {
                        DevicesList.Items.Clear();
                        if (e.NewItem is GXDeviceGroup)
                        {
                            GXDeviceGroup group = e.NewItem as GXDeviceGroup;
                            foreach(GXDevice it in group.Devices)
                            {
                                AddDeviceToDeviceList(it);
                            }
                        }
                        else 
                        {
                            GXDeviceList list = e.NewItem as GXDeviceList;
                            foreach (GXDevice it in list.DeviceGroups.GetDevicesRecursive())
                            {
                                AddDeviceToDeviceList(it);
                            }
                        }
                    }
                    else if (showPropertyList)
                    {
                        PropertyList.Items.Clear();
                        GXCategory cat = e.NewItem as GXCategory;
                        List<ListViewItem> items = new List<ListViewItem>();
                        foreach (GXProperty it in cat.Properties)
                        {
                            ListViewItem item = new ListViewItem(it.Name);
                            item.Tag = it;
                            string unit = it.Unit == null ? "" : it.Unit;
                            string type = it.ValueType == null ? "" : it.ValueType.Name;
                            string tm = it.ReadTime == DateTime.MinValue ? "" : it.ReadTime.ToString();
                            object value = it.GetValue(true);
                            if (value is Array || value is IList)
                            {
                                StringBuilder sb = new StringBuilder();
                                if (value is Array)
                                {
                                    Array arr = value as Array;
                                    foreach (object it2 in arr)
                                    {                                        
                                        sb.Append(it2);
                                        sb.Append(", ");
                                    }
                                }
                                else
                                {
                                    IList list = value as IList;
                                    foreach (object it2 in list)
                                    {
                                        sb.Append(it2);
                                        sb.Append(", ");
                                    }
                                }
                                //Remove extra data.
                                if (sb.Length > 2)
                                {
                                    sb.Remove(sb.Length - 2, 2);
                                }
                                value = sb.ToString();
                            }

                            item.SubItems.AddRange(new string[]{Convert.ToString(value), 
                                            type, unit, tm, 
                                            string.Format("{0:#,0}/{1:#,0}", it.Statistics.ReadCount, it.Statistics.ReadFailCount),
                                            string.Format("{0:#,0}/{1:#,0}", it.Statistics.WriteCount, it.Statistics.WriteFailCount),
                                            string.Format("{0:#,0}/{1:#,0}", it.Statistics.ExecutionTime, it.Statistics.ExecutionAverage)});
                            items.Add(item);
                            PropertyToListItem[it] = item;
                        }
                        PropertyList.Items.AddRange(items.ToArray());
                    }
                    else if (showPropertyInfo)
                    {
                        m_Property = e.NewItem as GXProperty;
                        bool write = (m_Property.AccessMode & AccessMode.Write) != 0 && (m_Property.DisabledActions & DisabledActions.Write) == 0;
                        bool read = (m_Property.AccessMode & AccessMode.Read) != 0 && (m_Property.DisabledActions & DisabledActions.Read) == 0;
                        ResetBtn.Enabled = WriteBtn.Enabled = write;
                        ReadBtn.Enabled = read;
                        ValueTB.ReadOnly = !write;
                        NameTB.Text = m_Property.DisplayName;
                        UnitTB.Text = m_Property.Unit;
                        if (m_Property.ValueType != null)
                        {
                            TypeTB.Text = m_Property.ValueType.Name;
                        }
                        else
                        {
                            TypeTB.Text = "Unknown";
                        }
                        // Check type of the property to determine the type of the control used for value input.
                        UseBitMask = m_Property.BitMask;
                        UseCombobox = !UseBitMask && m_Property.Values.Count != 0;
                        ValueCB.Items.Clear();
                        ValueLB.Items.Clear();
                        Type type = m_Property.ValueType;
                        if (type == null)
                        {
                            type = typeof(string);
                        }
                        object value = m_Property.GetValue(true);
                        string str = Convert.ToString(value);                                               
                        if (type == typeof(bool))
                        {
                            ValueCB.Items.Add(bool.FalseString);
                            ValueCB.Items.Add(bool.TrueString);
                            UseCombobox = true;
                        }
                        else if (UseCombobox)
                        {
                            foreach (GXValueItem it in m_Property.Values)
                            {
                                ValueCB.Items.Add(it.UIValue);                            
                            }
                        }
                        if (UseCombobox)
                        {
                            ValueCB.Visible = true;
                            ValueLB.Visible = ValueTB.Visible = false;
                            this.ValueCB.SelectedIndexChanged -= new System.EventHandler(this.ValueCB_SelectedIndexChanged);
                            ValueCB.SelectedIndex = ValueCB.FindStringExact(str);
                            this.ValueCB.SelectedIndexChanged += new System.EventHandler(this.ValueCB_SelectedIndexChanged);
                            if (m_Property.ForcePresetValues || type == typeof(bool))
                            {
                                ValueCB.DropDownStyle = ComboBoxStyle.DropDownList;
                            }
                            else
                            {
                                ValueCB.DropDownStyle = ComboBoxStyle.DropDown;
                                ValueCB.Text = str;
                            }
                        }
                        else
                        {
                            if (value is Array || value is IList)
                            {
                                ValueLB.CheckBoxes = false;
                                ValueLB.Visible = true;
                                ValueCB.Visible = ValueTB.Visible = false;
                                if (value is Array)
                                {
                                    Array arr = value as Array;
                                    foreach (object it in arr)
                                    {
                                        ValueLB.Items.Add(it.ToString());
                                    }
                                }
                                else
                                {
                                    IList list = value as IList;
                                    foreach (object it in list)
                                    {
                                        ValueLB.Items.Add(it.ToString());
                                    }
                                }
                            }
                            else
                            {
                                ValueLB.Visible = ValueCB.Visible = false;
                                if (UseBitMask)
                                {
                                    ValueLB.CheckBoxes = true;
                                    ValueLB.Visible = true;
                                    ulong val = Convert.ToUInt64(m_Property.GetValue(true));
                                    this.ValueLB.ItemCheck -= new System.Windows.Forms.ItemCheckEventHandler(this.ValueLB_ItemCheck);
                                    this.ValueLB.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.ValueLB_ItemCheck);
                                }
                                ValueTB.Visible = true;
                                ValueTB.Text = str;
                            }
                        }
                    }
                    else if (device != null)
                    {
                        SelectedDeviceLbl.Text = device.Name;
                        if (string.IsNullOrEmpty(device.Manufacturer))
                        {
                            DeviceTypeTB.Text = device.ProtocolName + " " + device.DeviceProfile;
                        }
                        else
                        {
                            DeviceTypeTB.Text = device.PresetName + " [" + device.Manufacturer + " " + device.Model + " " + device.Version + "]";
                        }
                        DeviceProperties.SelectedObject = device;
                        DeviceMediaFrame.Controls.Clear();
                        Form propertiesForm = device.GXClient.Media.PropertiesForm;
                        ((IGXPropertyPage)propertiesForm).Initialize();
                        while (propertiesForm.Controls.Count != 0)
                        {
                            Control ctr = propertiesForm.Controls[0];
                            if (ctr is Panel)
                            {
                                if (!ctr.Enabled)
                                {
                                    propertiesForm.Controls.RemoveAt(0);
                                    continue;
                                }
                            }
                            DeviceMediaFrame.Controls.Add(ctr);
                        }
                    }
                    else if (table != null)
                    {                        
                        TableData.AllowUserToAddRows = TableData.AllowUserToDeleteRows = TableData.ShowEditingIcon = (table.AccessMode & AccessMode.Write) != 0;
                        UpdatedTableData(this, new GXTableEventArgs(table, TableStates.RowsClear, 0, null));
                        TableData.Columns.Clear();
                        foreach (GXProperty it in table.Columns)
                        {
                            TableData.Columns.Add(it.Name, it.DisplayName);
                        }                        
                        List<object[]> rows = table.GetRows(0, -1, true);
                        OnUpdated(this, new GXTableEventArgs(table, TableStates.RowsAdded, 0, rows));
                        IGXPartialRead partialRead = table as IGXPartialRead;
                        if (table.Columns.Count != 0)
                        {
                            GXProperty prop = table.Columns[0];
                            if (prop.ValueType != typeof(DateTime))
                            {
                                ReadNewValuesCB.Enabled = ReadFromRB.Enabled = ReadLastRB.Enabled = false;
                                partialRead.Type = PartialReadType.All;
                            }
                            else
                            {
                                ReadNewValuesCB.Enabled = ReadFromRB.Enabled = ReadLastRB.Enabled = true;
                            }
                        }
                        ReadingGB.Visible = partialRead != null;
                        if (partialRead != null)
                        {
                            switch (partialRead.Type)
                            {
                                case PartialReadType.New://Read New values.
                                    ReadNewValuesCB.Checked = true;
                                    try
                                    {
                                        if (partialRead.Type != PartialReadType.New || partialRead.Start == null)
                                        {
                                            LastReadValueTP.Text = "";
                                        }
                                        else
                                        {
                                            LastReadValueTP.Text = Convert.ToDateTime(partialRead.Start).ToString();
                                        }
                                    }
                                    catch
                                    {
                                        LastReadValueTP.Text = "";
                                    }
                                    break;
                                case PartialReadType.All://Read all values.
                                    ReadAllRB.Checked = true;
                                    break;
                                case PartialReadType.Last: //Read last n. Days.
                                    ReadLastRB.Checked = true;
                                    ReadLastTB.Text = partialRead.Start.ToString();
                                    break;
                                case PartialReadType.Range://Read between days
                                    ReadFromRB.Checked = true;
                                    if (partialRead.Start != null)
                                    {
                                        StartPick.Value = Convert.ToDateTime(partialRead.Start);
                                        StartPick.Checked = true;
                                    }
                                    else
                                    {
                                        StartPick.Checked = false;
                                    }
                                    if (partialRead.End != null)
                                    {
                                        ToPick.Value = Convert.ToDateTime(partialRead.End);
                                        ToPick.Checked = true;
                                    }
                                    else
                                    {
                                        ToPick.Checked = false;
                                    }
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                    TablePanel.Visible = table != null;
                    DevicePanel.Visible = device != null;
                    DevicesList.Visible = showDeviceList;
                    PropertyList.Visible = showPropertyList;
                    PropertyPanel.Visible = showPropertyInfo;
                    //Show diagnostics trace.
                    if (TraceLevel != System.Diagnostics.TraceLevel.Off)
                    {
                        if (!TabControl1.TabPages.Contains(TracePage))
                        {
                            TabControl1.TabPages.Add(TracePage);
                        }
                        //If user changes device or device group.
                        device = GXTransactionManager.GetDevice(e.NewItem);
                        if (device == null || device != TracedDevice)
                        {
                            lock (TraceEvents)
                            {
                                TraceEvents.Clear();
                                TraceView.VirtualListSize = 0;
                            }
                            if (TracedDevice != null)
                            {
                                TracedDevice.OnTrace -= new TraceEventHandler(OnTrace);
                            }
                            TracedDevice = null;
                        }
                        //If new device is selected.
                        if (device != null && device != TracedDevice)
                        {
                            TracedDevice = device;
                            TracedDevice.OnTrace += new TraceEventHandler(OnTrace);
                        }
                    }
                    else if (TabControl1.TabPages.Contains(TracePage))
                    {
                        TabControl1.TabPages.Remove(TracePage);
                    }
                }
            }
            catch (Exception Ex)
            {
                GXCommon.ShowError(this.ParentComponent, Gurux.DeviceSuite.Properties.Resources.GuruxDeviceSuiteTxt, Ex);
            }
            finally
            {
                DeviceListTree.AfterSelect += new TreeViewEventHandler(OnAfterSelect);
            }
        }
Ejemplo n.º 10
0
        private void ShowAvailableProperty(GXProperty prop, TreeNode root)
        {
#if DEBUG
            m_ObjectIDs.Add(prop.ID, prop);
#endif //DEBUG
            //If property already exists
            System.Diagnostics.Debug.Assert(DeviceToTreeNode[prop] == null);
            //If device ID is nill.
            ulong id = prop.ID;
            System.Diagnostics.Debug.Assert((id >> 16) != 0);
            //If property ID is nill.
            System.Diagnostics.Debug.Assert((id & 0xFFFF) != 0);
            TreeNode it;
            if (prop.Table == null)
            {
                it = root.Nodes.Add(prop.DisplayName + " " + prop.GetValue(true));
            }
            else
            {
                it = root.Nodes.Add(prop.DisplayName);
            }
            it.Tag = prop;
            DeviceToTreeNode[prop] = it;
            PropertyChanged(this, new GXPropertyEventArgs(prop, prop.Status));
        }
Ejemplo n.º 11
0
		///<summary>
		/// Convert device value to UI value.
		///</summary>
		internal object DeviceValueToUIValue(GXProperty sender, object value)
		{
			value = this.PacketHandler.DeviceValueToUIValue(sender, value);
			if (value is byte[])
			{
				value = Gurux.Common.GXCommon.ToHex((byte[])value, true);
			}
			return value;
		}
Ejemplo n.º 12
0
		///<summary>
		/// Convert UI value to device value.
		///</summary>
		internal object UIValueToDeviceValue(GXProperty sender, object value)
		{
			return this.PacketHandler.UIValueToDeviceValue(sender, value);
		}