Guys,
I have a small FSM that drives a servo using PWM and a digital output on an extender board. The FSM cycles around 136 times and then an InvaldOperationException is raised. It seems impossible to debug with the knowledge I have and the result is very unexecpted. I could add a bunch of try-catch-finally blocks but thought I’d see if anyone had any experience of this kind of error and could point me in the right direction.
Found debugger!
Create TS.
Loading start at a0e00000, end a0e1383c
Assembly: mscorlib (4.2.0.0) Assembly: Microsoft.SPOT.Native (4.2.0.0) Assembly: Microsoft.SPOT.Security.PKCS11 (4.2
.0.0) Assembly: System.Security (4.2.0.0) Loading Deployment Assemblies.
Attaching deployed file.
Assembly: Microsoft.SPOT.IO (4.2.0.0) Attaching deployed file.
Assembly: Gadgeteer (2.42.0.0) Attaching deployed file.
Assembly: Microsoft.SPOT.Graphics (4.2.0.0) Attaching deployed file.
Assembly: Blade lifecycle testing (1.0.0.0) Attaching deployed file.
Assembly: System.Http (4.2.0.0) Attaching deployed file.
Assembly: Microsoft.SPOT.Hardware (4.2.0.0) Attaching deployed file.
Assembly: System (4.2.0.0) Attaching deployed file.
Assembly: Microsoft.SPOT.Net.Security (4.2.0.0) Attaching deployed file.
Assembly: GTM.GHIElectronics.Extender (1.1.2.0) Attaching deployed file.
Assembly: GHI.Premium.Hardware (4.2.7.0) Attaching deployed file.
Assembly: Microsoft.SPOT.Touch (4.2.0.0) Attaching deployed file.
Assembly: GTM.GHIElectronics.UsbClientDP (1.1.1.0) Attaching deployed file.
Assembly: GTM.GHIElectronics.Button (1.1.1.0) Attaching deployed file.
Assembly: Microsoft.SPOT.TinyCore (4.2.0.0) Attaching deployed file.
Assembly: GHI.Premium.System (4.2.7.0) Attaching deployed file.
Assembly: Microsoft.SPOT.Net (4.2.0.0) Attaching deployed file.
Assembly: System.IO (4.2.0.0) Attaching deployed file.
Assembly: GHI.Premium.IO (4.2.7.0) Attaching deployed file.
Assembly: Microsoft.SPOT.Hardware.PWM (4.2.0.1) Attaching deployed file.
Assembly: System.Net.Security (4.2.0.0) Attaching deployed file.
Assembly: Microsoft.SPOT.Hardware.SerialPort (4.2.0.0) Attaching deployed file.
Assembly: GHIElectronics.Gadgeteer.FEZSpider (1.1.1.0) Resolving.
GC: 1msec 36048 bytes used, 7303620 bytes available
Type 0F (STRING ): 24 bytes
Type 15 (FREEBLOCK ): 7303620 bytes
Type 17 (ASSEMBLY ): 31908 bytes
Type 1E (BINARY_BLOB_HEAD ): 4044 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
GC: performing heap compaction...
The debugging target runtime is loading the application assemblies and starting execution.
Ready.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\mscorlib.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Native.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Security.PKCS11.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Security.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.IO.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Net.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Graphics.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.TinyCore.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.IO.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.PWM.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Gadgeteer\Core\Assemblies\.NET Micro Framework 4.2\le\Gadgeteer.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\GHI Electronics\GHI .NET Gadgeteer SDK\Modules\Button\NETMF 4.2\le\GTM.GHIElectronics.Button.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\GHI Electronics\GHI .NET Gadgeteer SDK\Modules\Extender\NETMF 4.2\le\GTM.GHIElectronics.Extender.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\GHI Electronics\GHI .NET Gadgeteer SDK\Modules\UsbClientDP\NETMF 4.2\le\GTM.GHIElectronics.UsbClientDP.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\GHI Electronics\GHI Premium NETMF v4.2 SDK\Assemblies\le\GHI.Premium.System.dll'
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\GHI Electronics\GHI Premium NETMF v4.2 SDK\Assemblies\le\GHI.Premium.IO.dll'
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\GHI Electronics\GHI Premium NETMF v4.2 SDK\Assemblies\le\GHI.Premium.Hardware.dll'
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\GHI Electronics\GHI .NET Gadgeteer SDK\Mainboards\FEZSpider\NETMF 4.2\le\GHIElectronics.Gadgeteer.FEZSpider.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Users\JJames\Documents\Visual Studio 2010\Projects\Automation\Handtool\Blade lifecycle testing\Blade lifecycle testing\bin\Release\le\Blade lifecycle testing.exe', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Net.Security.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Net.Security.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Http.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Touch.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.SerialPort.dll', Symbols loaded.
The thread '<No Name>' (0x2) has exited with code 0 (0x0).
Using mainboard GHI Electronics FEZSpider version 1.0
Program Started
Servo Stopped
Blade Up
Awaiting button press
OP # - 1
OP # - 2
OP # - 3
OP # - 4
The thread '<No Name>' (0x3) has exited with code 0 (0x0).
OP # - 5
OP # - 6
...
OP # - 135
OP # - 136
GC: 135msec 89484 bytes used, 7250184 bytes available
Type 0F (STRING ): 1380 bytes
Type 11 (CLASS ): 23892 bytes
Type 12 (VALUETYPE ): 1512 bytes
Type 13 (SZARRAY ): 4500 bytes
Type 03 (U1 ): 156 bytes
Type 04 (CHAR ): 852 bytes
Type 07 (I4 ): 1044 bytes
Type 0F (STRING ): 72 bytes
Type 11 (CLASS ): 2292 bytes
Type 12 (VALUETYPE ): 84 bytes
Type 15 (FREEBLOCK ): 7250184 bytes
Type 16 (CACHEDBLOCK ): 120 bytes
Type 17 (ASSEMBLY ): 31908 bytes
Type 18 (WEAKCLASS ): 96 bytes
Type 19 (REFLECTION ): 168 bytes
Type 1B (DELEGATE_HEAD ): 756 bytes
Type 1D (OBJECT_TO_EVENT ): 288 bytes
Type 1E (BINARY_BLOB_HEAD ): 14268 bytes
Type 1F (THREAD ): 1536 bytes
Type 20 (SUBTHREAD ): 144 bytes
Type 21 (STACK_FRAME ): 1632 bytes
Type 22 (TIMER_HEAD ): 144 bytes
Type 26 (WAIT_FOR_OBJECT_HEAD): 48 bytes
Type 27 (FINALIZER_HEAD ): 3432 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 3372 bytes
#### Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (6) ####
#### Message:
#### Microsoft.SPOT.Hardware.Port::ReservePin [IP: 0000] ####
#### Microsoft.SPOT.Hardware.PWM::Dispose [IP: 0017] ####
A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.SPOT.Hardware.dll
An unhandled exception of type 'System.InvalidOperationException' occurred in Microsoft.SPOT.Hardware.dll
The code looks like this:
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using Gadgeteer.Interfaces;
namespace Blade_lifecycle_testing
{
public enum FSM
{
BladeUp,
Wait_BladeUp,
WireMoveStart,
Wait_WireMoveStart,
WireMoveStop,
Wait_WireMoveStop,
BladeDown,
Wait_BladeDown
}
public partial class Program
{
FSM MachineState;
GT.Timer MachineTimer;
uint period = 20 * 1000 * 1000;
uint high1 = 1400 * 1000;
PWMOutput servo;
DigitalOutput blade;
uint ServoRunTime = 50;
uint ServoWaitTime = 150;
uint BladeDownTime = 100;
uint BladeUpTime = 100;
uint ticks = 0;
bool TimerEnabled = false;
uint operations = 0;
bool DebugPrint = false;
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
Debug.Print("Program Started");
MachineState = FSM.WireMoveStart;
MachineTimer = new GT.Timer(1);
MachineTimer.Tick += new GT.Timer.TickEventHandler(MachineTimer_Tick);
button.ButtonReleased += new Button.ButtonEventHandler(button_ButtonReleased);
servo = extender.SetupPWMOutput(GT.Socket.Pin.Eight);
servo.SetPulse(period, high1);
servo.Active = false;
Debug.Print("Servo Stopped");
blade = extender.SetupDigitalOutput(GT.Socket.Pin.Three, false);
blade.Write(false);
Debug.Print("Blade Up");
Debug.Print("Awaiting button press");
}
void button_ButtonReleased(Button sender, Button.ButtonState state)
{
if (TimerEnabled)
{
TimerEnabled = false;
servo.Active = false;
MachineTimer.Stop();
}
else
{
TimerEnabled = true;
MachineTimer.Start();
}
}
void MachineTimer_Tick(GT.Timer timer)
{
ProcessMachineState();
}
private void ProcessMachineState()
{
switch (MachineState)
{
case FSM.WireMoveStart:
{
if(DebugPrint)
Debug.Print("WireMoveStart");
StartWireMove();
ticks = 0;
MachineState = FSM.Wait_WireMoveStart;
operations++;
Debug.Print("OP # - " + operations.ToString());
break;
}
case FSM.Wait_WireMoveStart:
{
if (DebugPrint)
Debug.Print("Wait_WireMoveStart\t\t" + ticks.ToString());
ticks++;
if (ticks == ServoRunTime)
{
MachineState = FSM.WireMoveStop;
}
break;
}
case FSM.WireMoveStop:
{
if (DebugPrint)
Debug.Print("WireMoveStop");
StopWireMove();
ticks = 0;
MachineState = FSM.Wait_WireMoveStop;
break;
}
case FSM.Wait_WireMoveStop:
{
if (DebugPrint)
Debug.Print("Wait_WireMoveStop\t\t" + ticks.ToString());
ticks++;
if(ticks == ServoWaitTime)
{
MachineState = FSM.BladeDown;
}
break;
}
case FSM.BladeDown:
{
if (DebugPrint)
Debug.Print("BladeDown");
BladeDown();
ticks = 0;
MachineState = FSM.Wait_BladeDown;
break;
}
case FSM.Wait_BladeDown:
{
if (DebugPrint)
Debug.Print("Wait_BladeDown\t\t" + ticks.ToString());
ticks++;
if (ticks == BladeDownTime)
{
MachineState = FSM.BladeUp;
}
break;
}
case FSM.BladeUp:
{
if (DebugPrint)
Debug.Print("BladeDown");
BladeUp();
ticks = 0;
MachineState = FSM.Wait_BladeUp;
break;
}
case FSM.Wait_BladeUp:
{
if (DebugPrint)
Debug.Print("Wait_BladeUp\t\t" + ticks.ToString());
ticks++;
if (ticks == BladeUpTime)
{
MachineState = FSM.WireMoveStart;
}
break;
}
}
}
private void StartWireMove()
{
servo.Active = true;
}
private void StopWireMove()
{
servo.Active = false;
}
private void BladeDown()
{
blade.Write(true);
}
private void BladeUp()
{
blade.Write(false);
}
}
}
Many thanks,
Jason.