コード例 #1
0
ファイル: GaugeInfo.cs プロジェクト: kjlopin/bqev23k
        /// <summary>
        /// Write specific device register using methode defined in configuration.
        /// </summary>
        /// <param name="caption">Register name to write.</param>
        /// <returns>EV2300 error code.</returns>
        /// <remarks>For now only works to set the ManufacturerAccess command.</remarks>
        private EV23KError WriteDevice(string caption)
        {
            EV23KError err        = EV23KError.Unknown;
            object     dataBlock  = null;
            short      dataLength = 0;

            SbsCommandItem c = sbsItems.SbsCommands.Find(x => x.Caption == caption);

            if (c != null)
            {
                if (c.WriteStyle == 1)
                {
                    err = EV23KBoard.WriteSMBusWord(0, c.Command, sbsItems.TargetAdress);
                }
                else if (c.WriteStyle == 2)
                {
                    err = EV23KBoard.ReadManufacturerAccessBlock(sbsItems.TargetMacAdress, c.Command, out dataBlock, out dataLength, sbsItems.TargetAdress);
                    if (c.HasResult && err == EV23KError.NoError)
                    {
                        c.GetRawValueFromDataBlock(dataBlock, dataLength, c.OffsetWithinBlock, c.LengthWithinBlock);
                        c.CalculateDisplayValue();
                    }
                }
            }
            return(err);
        }
コード例 #2
0
ファイル: GaugeInfo.cs プロジェクト: kjlopin/bqev23k
        /// <summary>
        /// Get scaled register value.
        /// </summary>
        /// <param name="caption">Register name to read from.</param>
        /// <returns>Scaled value.</returns>
        public double GetReadValue(string caption)
        {
            SbsRegisterItem i = sbsItems.SbsRegister.Find(x => x.Caption == caption);

            if (i == null)
            {
                SbsCommandItem c = sbsItems.SbsCommands.Find(x => x.Caption == caption);
                if (c == null)
                {
                    return(0);
                }
                else
                {
                    return(c.ReadValue);
                }
            }
            else
            {
                return(i.ReadValue);
            }
        }
コード例 #3
0
ファイル: GaugeInfo.cs プロジェクト: kjlopin/bqev23k
        /// <summary>
        /// Get formatted string of register value, scaled and including the unit.
        /// </summary>
        /// <param name="caption">Register name to read from.</param>
        /// <returns>Formatted value string.</returns>
        public string GetDisplayValue(string caption)
        {
            SbsRegisterItem i = sbsItems.SbsRegister.Find(x => x.Caption == caption);

            if (i == null)
            {
                SbsCommandItem c = sbsItems.SbsCommands.Find(x => x.Caption == caption);
                if (c == null)
                {
                    return("");
                }
                else
                {
                    return(c.DisplayValue);
                }
            }
            else
            {
                return(i.DisplayValue);
            }
        }
コード例 #4
0
        /// <summary>
        /// Constructor, reading the device configuration file.
        /// </summary>
        /// <param name="bqzPath">Full path to configuration file.</param>
        public SbsItems(string bqzPath)
        {
            string  s = string.Empty;
            bool    b = false;
            int     n = 0;
            XmlNode singleNode;

            try
            {
                using (ZipArchive archive = ZipFile.OpenRead(bqzPath))
                {
                    #region default.sbsx
                    ZipArchiveEntry e = archive.GetEntry(@"sbs/default.sbsx");
                    using (Stream sbsx = e.Open())
                    {
                        XmlDocument sbs = new XmlDocument();
                        sbs.Load(sbsx);

                        #region sbsInfo
                        XmlNodeList info = sbs.DocumentElement.SelectNodes("/sbs/sbsInfo");
                        foreach (XmlNode node in info)
                        {
                            singleNode = node.SelectSingleNode("targetAddress");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        targetAdress = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out targetAdress);
                                    }
                                }
                            }

                            singleNode = node.SelectSingleNode("targetEndianess");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        targetEndianess = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out targetEndianess);
                                    }
                                }
                            }

                            singleNode = node.SelectSingleNode("mac");
                            if (singleNode != null)
                            {
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        mac = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out mac);
                                    }
                                }
                            }

                            singleNode = node.SelectSingleNode("SMB_NewMacCMD");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        targetMacAddress = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out targetMacAddress);
                                    }
                                }
                            }
                        }
                        #endregion

                        #region sbsItem
                        XmlNodeList items = sbs.DocumentElement.SelectNodes("/sbs/sbsItem");
                        sbsRegister = new List <SbsRegisterItem>(items.Count);
                        s           = null;

                        foreach (XmlNode node in items)
                        {
                            SbsRegisterItem i = new SbsRegisterItem();
                            singleNode = node.SelectSingleNode("caption");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.Caption = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("logcaption");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.LogCaption = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("isstatic");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.IsStatic = b;
                                }
                            }

                            singleNode = node.SelectSingleNode("isvisible");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.IsVisible = b;
                                }
                            }

                            singleNode = node.SelectSingleNode("ismac");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.IsMac = b;
                                }
                            }

                            singleNode = node.SelectSingleNode("readstyle");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.ReadStyle = n;
                                }
                            }

                            singleNode = node.SelectSingleNode("offsetwithinblock");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.OffsetWithinBlock = n;
                                }
                            }

                            singleNode = node.SelectSingleNode("lengthwithinblock");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.LengthWithinBlock = n;
                                }
                            }

                            singleNode = node.SelectSingleNode("length");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.Length = n;
                                }
                            }

                            singleNode = node.SelectSingleNode("command");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.Command = (short)n;
                                }
                            }

                            singleNode = node.SelectSingleNode("readformula");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.ReadFormula = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("writeformula");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.WriteFormula = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("writable");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.Writable = b;
                                }
                            }

                            singleNode = node.SelectSingleNode("unit");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.Unit = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("displayformat");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.DisplayFormat = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("mreadformula");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.MReadFormula = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("mwriteformula");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.MWriteFormula = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("munit");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.MUnit = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("isbitfield");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.IsBitfield = b;
                                }
                            }

                            if (i.IsBitfield)
                            {
                                XmlNodeList bits = node.SelectSingleNode("fields").ChildNodes;
                                i.SbsBitItems = new List <SbsBitItem>(bits.Count);
                                foreach (XmlNode bit in bits)
                                {
                                    SbsBitItem bi = new SbsBitItem();
                                    n             = 0;
                                    bi.SbsCaption = bi.SbsBitDescription = bit.InnerText;
                                    s             = bit.Name.Substring(3);
                                    if (s != null)
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    bi.SbsBitPosition = n;
                                    bi.SbsBitValue    = 0;
                                    i.SbsBitItems.Add(bi);
                                }
                            }

                            sbsRegister.Add(i);
                        }
                        #endregion
                    }
                    #endregion

                    #region commands.xml
                    e = archive.GetEntry(@"toolcustomization/commands.xml");
                    using (Stream strm = e.Open())
                    {
                        XmlDocument xml = new XmlDocument();
                        xml.Load(strm);

                        #region Commands
                        XmlNodeList items = xml.DocumentElement.SelectNodes("/commands/commandItem");
                        sbsCommands = new List <SbsCommandItem>(items.Count);
                        s           = null;

                        foreach (XmlNode node in items)
                        {
                            SbsCommandItem i = new SbsCommandItem();
                            singleNode = node.SelectSingleNode("caption");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.Caption = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("description");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    i.Description = s.Trim();
                                }
                            }

                            singleNode = node.SelectSingleNode("result");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.HasResult = b;
                                }
                            }

                            singleNode = node.SelectSingleNode("sealedaccess");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.SealedAccess = b;
                                }
                            }

                            singleNode = node.SelectSingleNode("private");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.IsPrivate = b;
                                }
                            }

                            singleNode = node.SelectSingleNode("databigendian");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                if (s != null)
                                {
                                    bool.TryParse(s, out b);
                                    i.IsBigEndian = b;
                                }
                            }

                            singleNode = node.SelectSingleNode("writestyle");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.WriteStyle = n;
                                }
                            }

                            singleNode = node.SelectSingleNode("offsetwithinblock");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.OffsetWithinBlock = n;
                                }
                            }

                            singleNode = node.SelectSingleNode("lengthwithinblock");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.LengthWithinBlock = n;
                                }
                            }

                            singleNode = node.SelectSingleNode("length");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.Length = n;
                                }
                            }

                            singleNode = node.SelectSingleNode("writevalue");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.Command = (short)n;
                                }
                            }

                            singleNode = node.SelectSingleNode("delayms");
                            if (singleNode != null)
                            {
                                s = singleNode.InnerText;
                                n = 0;
                                if (s != null)
                                {
                                    if (s.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        n = Convert.ToInt32(s, 16);
                                    }
                                    else
                                    {
                                        int.TryParse(s, out n);
                                    }
                                    i.Delayms = n;
                                }
                            }

                            sbsCommands.Add(i);
                        }
                        #endregion
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }