Ejemplo n.º 1
0
        public void RefreshTorque()
        {
            try
            {
                lock (_objLock)
                {
                    _server.Connect(IP_ADDRESS);

                    // each input register can hold only 2 bytes, we are only reading 1 register
                    var data = new byte[2];

                    // spelled out for clarity
                    ushort transactionId = 1;
                    ushort startAddress  = 0;
                    ushort numInputs     = 1;

                    _server.ReadInputRegister(transactionId, startAddress, numInputs, ref data);

                    // Data is big endian, windows is little endian, so need to reverse.
                    Array.Reverse(data);

                    // the signed integer value.
                    var value = BitConverter.ToInt16(data, 0);

                    Torque = 0.667f * value;

                    _server.Dispose();
                }
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Gets the current rotational position of the output flange,
        ///     and saves the value to the GearboxAngle property.
        /// </summary>
        public void RefreshPosition()
        {
            try
            {
                lock (_objLock)
                {
                    _server.Connect(IP_ADDRESS);

                    // reading the loop position feedback value at index 588
                    // see Modbus Parameter Table, pg 344 of user guide.

                    var    data      = new byte[16];
                    ushort transId   = 1;
                    ushort startAddr = 588;
                    ushort numInputs = 4;

                    _server.ReadHoldingRegister(transId, startAddr, numInputs, ref data);

                    if (data != null)
                    {
                        Array.Reverse(data);
                        var value = BitConverter.ToInt64(data, 0);

                        if (value == 0)
                        {
                            GearboxAngle = 0f;
                        }
                        else
                        {
                            // represents the PL.FB from the ADK drive.
                            long count = 0;

                            if (Math.Abs(value) < COUNTS_PER_REV)
                            {
                                count = value;
                            }
                            else
                            {
                                count = value % COUNTS_PER_REV;
                            }

                            GearboxAngle = count * (360f / COUNTS_PER_REV);
                        }
                    }

                    _server.Dispose();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(
                    "** EXCEPTION ** \n\tLocation: ServoDrive.RefreshPosition() \n\tLine:100 \n\t{0} \n\tServoDrive values:\n\t\tGearboxAngle: {1:n2}°",
                    ex.Message, GearboxAngle);
            }
        }