Ejemplo n.º 1
0
 public void GetVariables(out MaestroVariables variables)
 {
     if (Type == MaestroType.Servo6)
     {
         GetVariablesServo6(out variables, out short[] stack, out ushort[] callStack, out ServoStatus[] status);
     }
     else
     {
         GetVariablesOther(out variables);
     }
 }
Ejemplo n.º 2
0
        private unsafe void GetVariablesOther(out MaestroVariables variables)
        {
            // Get miscellaneous variables.
            MiniMaestroVariables tmp;
            var bytesRead = (uint)_device.ControlTransfer(RequestType._0xC0, Request.REQUEST_GET_VARIABLES, 0, 0, &tmp, (ushort)sizeof(MiniMaestroVariables));

            if (bytesRead != sizeof(MiniMaestroVariables))
            {
                throw new DataMisalignedException("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       = (byte)tmp.ScriptDone;
            variables.PerformanceFlags = tmp.PerformanceFlags;
        }
Ejemplo n.º 3
0
        private unsafe void GetVariablesServo6(out MaestroVariables variables, out short[] stack, out ushort[] callStack, out ServoStatus[] servos)
        {
            byte[] array = new byte[sizeof(MicroMaestroVariables) + MaxServoCount * sizeof(ServoStatus)];

            _device.ControlTransfer(RequestType._0xC0, Request.REQUEST_GET_VARIABLES, 0, 0, array);

            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[MaxServoCount];
                for (byte i = 0; i < MaxServoCount; 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);
                }
            }
        }
Ejemplo n.º 4
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);
     }
 }
Ejemplo n.º 5
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);
     }
 }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
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); }
            }
        }