示例#1
0
        private void PopulateRegisterPage(uint port, Register[] registerInfoArray)
        {
            ManagedBusManager busMgr = new ManagedBusManager();

            m_nodeInformationDataGridView.Rows.Clear();
            uint currAddr = 0;
            uint prevAddr = 0;
            uint regValue = 0;
            bool isFirst  = true;

            foreach (Register iter in registerInfoArray)
            {
                prevAddr = currAddr;
                currAddr = iter.Address;
                if (isFirst || currAddr != prevAddr)
                {
                    try
                    {
                        regValue = busMgr.ReadPhyRegister(m_selectedGuid, 0, port, iter.Address);
                    }
                    catch (FC2Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                        ex.Dispose();
                        return;
                    }

                    isFirst = false;
                }

                // add result to table
                try
                {
                    int rowNum = m_nodeInformationDataGridView.Rows.Add(new DataGridViewRow());
                    m_nodeInformationDataGridView.Rows[rowNum].Cells[0].Value = iter.Name;
                    m_nodeInformationDataGridView.Rows[rowNum].Cells[1].Value = GetField(iter, regValue);
                }
                catch (InvalidOperationException ex)
                {
                    Debug.WriteLine("Error appending new row.");
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Debug.WriteLine("The information data table is full.");
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }
            }
        }
示例#2
0
        private bool GetVendorID(ManagedPGRGuid guid, out Field vendorID)
        {
            vendorID = new Field("Node", 0);

            uint regVal    = 0;
            uint vendorVal = 0;

            // read vendor id registers
            for (uint i = 10; i <= 12; i++)
            {
                try
                {
                    regVal = m_busMgr.ReadPhyRegister(guid, k_vendorPage, 0, i);
                }
                catch (FC2Exception ex)
                {
                    ex.Dispose();
                    return(false);
                }

                vendorVal = (vendorVal << 8) | regVal;
            }

            vendorID.ID = vendorVal;

            uint count;

            for (count = 0; count < k_vendorList.Length; count++)
            {
                if (vendorVal == k_vendorList[count].ID)
                {
                    vendorID.Name = k_vendorList[count].Name;
                    break;
                }
            }

            return(true);
        }