Im make one InterruptPort and event handler for it but it behavior very strange.
I use Cobra and IO23(I also use some other ports for other things)…
Code which I use:
using System;
using System.Threading;
#if DEBUG
using Microsoft.SPOT;
#endif
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
namespace PEPP
{
class IOBoard
{
#region Variables & Constants
private InterruptPort DoorState;
public delegate void DoorStateChangeEventHandler(InterruptPort sender, bool state);
public event DoorStateChangeEventHandler OnDoorStateChange;
#endregion
#region Constructor
public IOBoard()
{
try
{
//Inputs
DoorState = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.IO23, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
DoorState.OnInterrupt += new NativeEventHandler(DoorState_OnInterrupt);
}
catch (Exception e)
{
Module.WriteErrorLog("IOBoard.IOBoard() - ERROR:" + e.Message.ToString());
}
}
#endregion
#region Events
private void DoorState_OnInterrupt(uint port, uint state, DateTime time)
{
try
{
if (DoorState.Read())
{
//Make some things
}
else
{
//Make some things
}
OnDoorStateChange(DoorState, (DoorState.Read()) ? false : true);
}
catch { }
}
#endregion
#region Public Methods
#endregion
#region Private Methods
#endregion
}
}
Im test app all night and approximately every 50 min I get error:
01/01/1977 03:47:47: 5130 Network online: True
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
The thread '<No Name>' (0x141c) has exited with code 0 (0x0).
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
01/01/1977 03:47:51: 5131 Network online: True
01/01/1977 04:34:39: 6550 Network online: True
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
The thread '<No Name>' (0x19a8) has exited with code 0 (0x0).
01/01/1977 04:34:41: 6551 Network online: True
01/01/1977 05:08:16: 7603 Network online: True
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
01/01/1977 05:08:21: 7606 Network online: True
01/01/1977 05:55:55: 9097 Network online: True
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
The thread '<No Name>' (0x239c) has exited with code 0 (0x0).
01/01/1977 05:55:57: 9098 Network online: True
01/01/1977 06:28:33: 10110 Network online: True
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
01/01/1977 06:28:35: 10111 Network online: True
01/01/1977 07:15:40: 11573 Network online: True
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
01/01/1977 07:15:42: 11574 Network online: True
01/01/1977 07:48:36: 12569 Network online: True
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Message:
#### DDD.IOBoard::DoorState_OnInterrupt [IP: 0040] ####
A first chance exception of type 'System.NullReferenceException' occurred in Application.exe
01/01/1977 07:48:40: 12570 Network online: True
In network testing thread I do not do anything with Inputs or outputs…
Also PIN is directly connected to ground all time and nobody do not touch it.