Exemplo n.º 1
0
        /// <summary>
        /// Applys register to data to associated RegisterTreeNode.
        /// </summary>
        /// <param name="registerAddress">
        /// Register address of tree node. See x_IMU_API.RegisterAddresses.
        /// </param>
        /// <param name="isConfirmed">
        /// A value indicating if the register data being applied should be displayed as confirmed.
        /// </param>
        public void ApplyRegisterData(x_IMU_API.RegisterData registerData, bool isConfirmed)
        {
            RegisterTreeNode registerTreeNode = FindRegisterTreeNode(registerData.Address);

            if (registerTreeNode == null)
            {
                throw new Exception("Register address does have an associated RegisterTreeNode.");
            }
            registerTreeNode.SetFromRegisterData(registerData, isConfirmed);
            RefreshPending = true;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Finds RegisterTreeNode with register address.
 /// </summary>
 /// <param name="registerAddress">
 /// Register address of tree node.
 /// </param>
 /// <returns>
 /// RegisterTreeNode.
 /// </returns>
 private RegisterTreeNode FindRegisterTreeNode(x_IMU_API.RegisterAddresses registerAddress)
 {
     foreach (TreeNode childNode in Nodes)
     {
         RegisterTreeNode registerTreeNode = FindRegisterTreeNode(childNode, registerAddress);
         if (registerTreeNode != null)
         {
             return(registerTreeNode);
         }
     }
     return(null);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Recursively searches for RegisterTreeNode with register address starting from a root TreeNode.
 /// </summary>
 /// <param name="rootNode">
 /// Root TreeNode that recursive search starts from.
 /// </param>
 /// <param name="registerAddress">
 /// Register address of tree node. See x_IMU_API.RegisterAddresses.
 /// </param>
 /// <returns>
 /// RegisterTreeNode.
 /// </returns>
 private RegisterTreeNode FindRegisterTreeNode(TreeNode rootNode, x_IMU_API.RegisterAddresses registerAddress)
 {
     foreach (TreeNode childNode in rootNode.Nodes)
     {
         if (childNode is RegisterTreeNode)
         {
             if ((childNode as RegisterTreeNode).RegisterAddress == registerAddress)
             {
                 return(childNode as RegisterTreeNode);
             }
         }
         else if (childNode.Nodes.Count > 0)
         {
             RegisterTreeNode registerTreeNode = FindRegisterTreeNode(childNode, registerAddress);   // for all child nodes recursively
             if (registerTreeNode != null)
             {
                 return(registerTreeNode);
             }
         }
     }
     return(null);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Sends a read register packet for a RegisterTreeNode.
 /// </summary>
 /// <param name="registerTreeNode">
 /// RegisterTreeNode to be read.
 /// </param>
 private void ReadRegisterTreeNode(RegisterTreeNode registerTreeNode)
 {
     try
     {
         Thread.Sleep(5);    // delay to avoid overrunning the device receive buffer
         xIMUserial.SendReadRegisterPacket(new x_IMU_API.RegisterData(registerTreeNode.RegisterAddress));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Sends a write register packet for a RegisterTreeNode.
 /// </summary>
 /// <param name="registerTreeNode">
 /// RegisterTreeNode to be written.
 /// </param>
 private void WriteRegisterTreeNode(RegisterTreeNode registerTreeNode)
 {
     if ((registerTreeNode.RegisterAddress == x_IMU_API.RegisterAddresses.FirmwareVersionMajorNum) ||
         (registerTreeNode.RegisterAddress == x_IMU_API.RegisterAddresses.FirmwareVersionMinorNum) ||
         (registerTreeNode.RegisterAddress == x_IMU_API.RegisterAddresses.DeviceID))
     {
         return;             // do not attmept to write read-only registers
     }
     try
     {
         Thread.Sleep(5);    // delay to avoid overrunning the device receive buffer
         xIMUserial.SendWriteRegisterPacket(registerTreeNode.ConvertToRegisterData());
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }