Beispiel #1
0
        /// <summary>
        /// Returns the number of bytes that the variable takes.
        /// </summary>
        private byte getVariableBytes(VariableId variableId)
        {
            switch (variableId)
            {
            case VariableId.TARGET_VCC_ALLOWED_MINIMUM:
            case VariableId.TARGET_VCC_ALLOWED_MAXIMUM_RANGE:
            case VariableId.TARGET_VCC_MEASURED_MINIMUM:
            case VariableId.TARGET_VCC_MEASURED_MAXIMUM:
            case VariableId.PROGRAMMING_ERROR:
            case VariableId.LINE_A_IDENTITY:
            case VariableId.LINE_B_IDENTITY:
            case VariableId.SLOSCOPE_STATE:
            case VariableId.SW_MINOR:
            case VariableId.SW_MAJOR:
            case VariableId.HW_VER:
            case VariableId.SCK_DURATION:
                return(1);

            case VariableId.FVR_ADC:
            case VariableId.SLOSCOPE_OUTPUT_STATE:
                return(2);

            default: throw new Exception("Unrecognized variabledId " + variableId.ToString());
            }
        }
Beispiel #2
0
        private unsafe ushort getVariable(VariableId variableId)
        {
            byte bytes = getVariableBytes(variableId);

            ushort value = 0;

            byte[] array = new byte[bytes];
            try
            {
                controlTransfer(0xC0, 0x81, 0, (ushort)variableId, array);
            }
            catch (Exception e)
            {
                throw new Exception("There was an error getting variable " + variableId.ToString() + " from the device.", e);
            }
            if (bytes == 1)
            {
                // read a single byte
                fixed(byte *pointer = array)
                {
                    value = *(byte *)pointer;
                }
            }
            else
            {
                // read two bytes
                fixed(byte *pointer = array)
                {
                    value = *(ushort *)pointer;
                }
            }
            return(value);
        }
Beispiel #3
0
 private void setVariable(VariableId variableId, ushort value)
 {
     try
     {
         controlTransfer(0x40, 0x82, value, (ushort)variableId);
     }
     catch (Exception e)
     {
         throw new Exception("There was an error setting variable " + variableId.ToString() + " on the device.", e);
     }
 }
Beispiel #4
0
 private void setVariable(VariableId variableId, ushort value)
 {
     try
     {
         controlTransfer(0x40, 0x82, value, (ushort)variableId);
     }
     catch (Exception e)
     {
         throw new Exception("There was an error setting variable " + variableId.ToString() + " on the device.", e);
     }
 }
Beispiel #5
0
        /// <summary>
        /// Returns the number of bytes that the variable takes.
        /// </summary>
        private byte getVariableBytes(VariableId variableId)
        {
            switch (variableId)
            {
                case VariableId.TARGET_VCC_ALLOWED_MINIMUM:
                case VariableId.TARGET_VCC_ALLOWED_MAXIMUM_RANGE:
                case VariableId.TARGET_VCC_MEASURED_MINIMUM:
                case VariableId.TARGET_VCC_MEASURED_MAXIMUM:
                case VariableId.PROGRAMMING_ERROR:
                case VariableId.LINE_A_IDENTITY:
                case VariableId.LINE_B_IDENTITY:
                case VariableId.SLOSCOPE_STATE:
                case VariableId.SW_MINOR:
                case VariableId.SW_MAJOR:
                case VariableId.HW_VER:
                case VariableId.SCK_DURATION:
                    return 1;

                case VariableId.FVR_ADC:
                case VariableId.SLOSCOPE_OUTPUT_STATE:
                    return 2;

                default: throw new Exception("Unrecognized variabledId " + variableId.ToString());
            }
        }
Beispiel #6
0
        private unsafe ushort getVariable(VariableId variableId)
        {
            byte bytes = getVariableBytes(variableId);

            ushort value = 0;
            byte[] array = new byte[bytes];
            try
            {
                controlTransfer(0xC0, 0x81, 0, (ushort)variableId, array);
            }
            catch (Exception e)
            {
                throw new Exception("There was an error getting variable " + variableId.ToString() + " from the device.", e);
            }
            if (bytes == 1)
            {
                // read a single byte
                fixed (byte* pointer = array)
                {
                    value = *(byte*)pointer;
                }
            }
            else
            {
                // read two bytes
                fixed (byte* pointer = array)
                {
                    value = *(ushort*)pointer;
                }
            }
            return value;
        }