コード例 #1
0
ファイル: Usc.cs プロジェクト: siegelpeter/UAV-NET
 /// <summary>
 /// Gets an array of ServoStatus structs representing
 /// the current status of all the channels.
 /// </summary>
 /// <remarks>If you are using the Micro Maestro and calling
 /// getVariables more than once in quick succession,
 /// then you can save some CPU time by just using the
 /// overload that has 4 arguments.
 /// </remarks>
 public void getVariables(out ServoStatus[] servos)
 {
     if (microMaestro)
     {
         MaestroVariables variables;
         short[] stack;
         ushort[] callStack;
         getVariablesMicroMaestro(out variables, out stack, out callStack, out servos);
     }
     else
     {
         getVariablesMiniMaestro(out servos);
     }
 }
コード例 #2
0
ファイル: Usc.cs プロジェクト: siegelpeter/UAV-NET
        private unsafe void getVariablesMiniMaestro(out ServoStatus[] servos)
        {
            try
            {
                byte[] servoSettingsArray = new byte[servoCount * sizeof(ServoStatus)];

                // Get the raw data from the device.
                UInt32 bytesRead = controlTransfer(0xC0, (byte)uscRequest.REQUEST_GET_SERVO_SETTINGS, 0, 0, servoSettingsArray);
                if (bytesRead != servoSettingsArray.Length)
                {
                    throw new Exception("Short read: " + bytesRead + " < " + servoSettingsArray.Length + ".");
                }

                // Put the data in to a managed array object.
                servos = new ServoStatus[servoCount];
                fixed (byte* pointer = servoSettingsArray)
                {
                    for (byte i = 0; i < servoCount; i++)
                    {
                        servos[i] = *(ServoStatus*)(pointer + sizeof(ServoStatus) * i);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error getting channel settings from device.", e);
            }
        }
コード例 #3
0
ファイル: Usc.cs プロジェクト: siegelpeter/UAV-NET
 /// <summary>
 /// Gets the complete set of status information for the Maestro.
 /// </summary>
 /// <remarks>If you are using a Mini Maestro and do not need all of
 /// the data provided by this function, you can save some CPU time
 /// by using the overloads with fewer arguments.</remarks>
 public unsafe void getVariables(out MaestroVariables variables, out short[] stack, out ushort[] callStack, out ServoStatus[] servos)
 {
     if (microMaestro)
     {
         // On the Micro Maestro, this function requires just one control transfer:
         getVariablesMicroMaestro(out variables, out stack, out callStack, out servos);
     }
     else
     {
         // On the Mini Maestro, this function requires four control transfers:
         getVariablesMiniMaestro(out variables);
         getVariablesMiniMaestro(out servos);
         getVariablesMiniMaestro(out stack);
         getVariablesMiniMaestro(out callStack);
     }
 }
コード例 #4
0
ファイル: Usc.cs プロジェクト: siegelpeter/UAV-NET
        private unsafe void getVariablesMicroMaestro(out MaestroVariables variables, out short[] stack, out ushort[] callStack, out ServoStatus[] servos)
        {
            byte[] array = new byte[sizeof(MicroMaestroVariables) + servoCount * sizeof(ServoStatus)];

            try
            {
                controlTransfer(0xC0, (byte)uscRequest.REQUEST_GET_VARIABLES, 0, 0, array);
            }
            catch (Exception e)
            {
                throw new Exception("There was an error getting the device variables.", e);
            }

            fixed (byte* pointer = array)
            {
                // copy the variable data
                MicroMaestroVariables tmp = *(MicroMaestroVariables*)pointer;
                variables.stackPointer = tmp.stackPointer;
                variables.callStackPointer = tmp.callStackPointer;
                variables.errors = tmp.errors;
                variables.programCounter = tmp.programCounter;
                variables.scriptDone = tmp.scriptDone;
                variables.performanceFlags = 0;

                servos = new ServoStatus[servoCount];
                for (byte i = 0; i < servoCount; i++)
                {
                    servos[i] = *(ServoStatus*)(pointer + sizeof(MicroMaestroVariables) + sizeof(ServoStatus) * i);
                }

                stack = new short[variables.stackPointer];
                for(byte i = 0; i < stack.Length; i++) { stack[i] = *(tmp.stack+i); }

                callStack = new ushort[variables.callStackPointer];
                for (byte i = 0; i < callStack.Length; i++) { callStack[i] = *(tmp.callStack + i); }
            }
        }