Exemplo n.º 1
0
 /// <summary>
 /// Gets a MaestroVariables struct representing the current status
 /// of the device.
 /// </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 MaestroVariables variables)
 {
     if (microMaestro)
     {
         ServoStatus[] servos;
         short[] stack;
         ushort[] callStack;
         getVariablesMicroMaestro(out variables, out stack, out callStack, out servos);
     }
     else
     {
         getVariablesMiniMaestro(out variables);
     }
 }
Exemplo n.º 2
0
        private unsafe void getVariablesMiniMaestro(out MaestroVariables variables)
        {
            try
            {
                // Get miscellaneous variables.
                MiniMaestroVariables tmp;
                UInt32 bytesRead = controlTransfer(0xC0, (byte)uscRequest.REQUEST_GET_VARIABLES, 0, 0, &tmp, (ushort)sizeof(MiniMaestroVariables));
                if (bytesRead != sizeof(MiniMaestroVariables))
                {
                    throw new Exception("Short read: " + bytesRead + " < " + sizeof(MiniMaestroVariables) + ".");
                }

                // Copy the variable data
                variables.stackPointer = tmp.stackPointer;
                variables.callStackPointer = tmp.callStackPointer;
                variables.errors = tmp.errors;
                variables.programCounter = tmp.programCounter;
                variables.scriptDone = tmp.scriptDone;
                variables.performanceFlags = tmp.performanceFlags;
            }
            catch (Exception e)
            {
                throw new Exception("Error getting variables from device.", e);
            }
        }
Exemplo n.º 3
0
 /// <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);
     }
 }
Exemplo n.º 4
0
        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); }
            }
        }