using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
namespace PACNET
{
/// Interrupt API
public class Interrupt
{
/// Rising edge trigger(default)
public const int INTR_RISING_TRIG = 0;
/// Level trigger
public const int INTR_LEVEL_TRIG = 1;
/// Falling edge trigger
public const int INTR_Falling_TRIG = 2;
//3.1. PAC_API void pac_EnableSlotInterrupt(BYTE slot, bool bEnable)
///
/// This function performs hardware operations necessary to enable the specified hardware interrupt.
///
/// [in] Specify the index of slot to enable interrupt or disable.
/// [in] Specify the Slot interrupt turning on or not.
[DllImport("PACSDK.dll", EntryPoint = "pac_EnableSlotInterrupt")]
public static extern void EnableSlotInterrupt(byte slot, bool bEnable);
//3.2. PAC_API HANDLE pac_GetSlotInterruptEvent(BYTE slot)
///
/// This function retrieves the slot event handle which registered by pac_InterruptInitialize.
///
/// [in] Specify the index of slot to retrieve the event handle.
/// Return a handle to the event object if success, otherwise, false.
[DllImport("PACSDK.dll", EntryPoint = "pac_GetSlotInterruptEvent")]
public extern static IntPtr GetSlotInterruptEvent(byte slot);
//3.3. PAC_API DWORD pac_GetSlotInterruptID(BYTE slot)
///
/// This function retrieves the slot interrupt ID.
///
/// [in] Specify the slot.
/// Return the slot interrupt ID.
[DllImport("PACSDK.dll", EntryPoint = "pac_GetSlotInterruptID")]
public extern static uint GetSlotInterruptID(byte slot);
//3.4. PAC_API void pac_InterruptDone(BYTE slot)
///
/// This function signals to the kernel that interrupt processing has been completed.
///
/// [in] Specify the slot.
[DllImport("PACSDK.dll", EntryPoint = "pac_InterruptDone")]
public extern static void InterruptDone(byte slot);
//3.5. PAC_API bool pac_InterruptInitialize(BYTE slot)
///
/// This function initializes a slot interrupt with the kernel. This initialization allows the slot to
/// register an event and enable the interrupt.
///
/// [in] Specify the index of slot to initialize.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_InterruptInitialize")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool InterruptInitialize(byte slot);
//3.6. PAC_API bool pac_RegisterSlotInterrupt(BYTE slot, PAC_CALLBACK_FUNC f)
///
/// This function registers slot interrupt service route and turns on slot interrupt.
///
/// [in] Specify the index of slot.
/// A callback function.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_RegisterSlotInterrupt")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool RegisterSlotInterrupt(byte slot, PAC_CALLBACK_FUNC f);
//3.7. PAC_API void pac_SetSlotInterruptEvent(BYTE slot, HANDLE hEvent)
///
/// This function allows a device driver to assign the slot event handle.
///
/// [in] Specify the index of slot to retrieve the event handle.
/// [in] Event to be signaled.
[DllImport("PACSDK.dll", EntryPoint = "pac_SetSlotInterruptEvent")]
public extern static void SetSlotInterruptEvent(byte slot, IntPtr hEvent);
//3.8. PAC_API bool pac_SetSlotInterruptPriority(BYTE slot, int nPriority)
///
/// This function sets the priority for a real-time thread on a thread by thread basis.
///
/// [in] Specify the index of slot to set priority.
/// [in] Priority to set for the thread.
///This value can range from 0 through 255, with 0 as the highest priority.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_SetSlotInterruptPriority")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool SetSlotInterruptPriority(byte slot, int nPriority);
//3.9. PAC_API void pac_SetTriggerType(BYTE slot, int iType)
///
/// This function can assign the pulse trigger type.
///
/// [in] Specify the index of slot.
/// [in] Specify the pulse trigger type.
/// 0: Rising edge trigger(default)
/// 1: Level trigger
/// 2: Falling edge trigger
[DllImport("PACSDK.dll", EntryPoint = "pac_SetTriggerType")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool SetTriggerType(byte slot, int iType);
//3.10. PAC_API bool pac_UnregisterSlotInterrupt(BYTE slot)
///
/// This function unregisters slot interrupt service route and diables a hardware interrupt as
/// specified by its interrupt identifier.
///
/// [in] Specify the index of slot.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_UnregisterSlotInterrupt")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool UnregisterSlotInterrupt(byte slot);
}
}