using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
namespace PACNET
{
/// Error Handling APII
public class ErrHandling
{
//11.1. PAC_API void pac_GetErrorMessage(DWORD dwMessageID, LPTSTR lpBuffer)
///
/// This function retrieves a message string.
///
/// [in] Specifies the 32-bit message identifier for the requested message.
/// [out] Pointer to a buffer for the error message.
[DllImport("PACSDK.dll", EntryPoint = "pac_GetErrorMessage")]
public extern static void GetErrorMessage(uint dwMessageID, string lpBuffer);
///
/// Get a message string
///
/// Specifies the 32-bit message identifier for the requested message
/// Error message string
public static string GetErrorMessage(uint dwMessageID)
{
string errMessage = new string(' ', 512);
PACNET.ErrHandling.GetErrorMessage(dwMessageID, errMessage);
return errMessage.Split('\0')[0];
}
//11.2. PAC_API DWORD pac_GetLastError()
///
/// This function returns the last-error code value.
///
/// The Return Value section of each reference page notes the conditions under which the
/// function sets the last-error code.
[DllImport("PACSDK.dll", EntryPoint = "pac_GetLastError")]
public extern static uint GetLastError();
//11.3. PAC_API void pac_SetLastError(DWORD errno)
///
/// This function sets the last-error code.
///
/// [in] Specifies the last-error code.
[DllImport("PACSDK.dll", EntryPoint = "pac_SetLastError")]
public extern static void SetLastError(uint errno);
///////////////////////////////////////////////////////////////////////
//
// from Xpac
//
///////////////////////////////////////////////////////////////////////
//8.4. PAC_API void pac_ClearLastError(DWORD errorno)
///
/// This function clears the last-error code.
///
[DllImport("PACSDK.dll", EntryPoint = "pac_ClearLastError")]
public extern static void ClearLastError();
}
/// Error Codes
public enum ErrCode
{
/// No Error
PAC_ERR_SUCCESS = 0x00000,
/// Unknow Error
PAC_ERR_UNKNOWN = 0x00001,
///////////////////////////////////////////////////////////////////////
// Basic Error Codes
///////////////////////////////////////////////////////////////////////
/// Slot registered error
PAC_ERR_SLOT_REGISTERED = 0x10001,
/// Slot not registered error
PAC_ERR_SLOT_NOT_REGISTERED = 0x10002,
/// Unknown Module
PAC_ERR_UNKNOWN_MODULE = 0x10003,
/// Module doesn't exist
PAC_ERR_INVALID_MAC = 0x10004,
/// Invalid COM port number
PAC_ERR_INVALID_COMPORT_NUMBER = 0x10005,
/// Function not supported
PAC_ERR_FUNCTION_NOT_SUPPORT = 0x10006,
/// Module doesn't exist
PAC_ERR_MODULE_UNEXISTS = 0x10007,
/// Slot not registered error
PAC_ERR_INVALID_SLOT_NUMBER = 0x10008,
///////////////////////////////////////////////////////////////////////
// Memory Error Codes
///////////////////////////////////////////////////////////////////////
/// EEPROM accesses invalid address
PAC_ERR_EEP_INVALID_ADDRESS = 0x11001,
/// SRAM accesses invalid address
PAC_ERR_SRAM_INVALID_ADDRESS = 0x11002,
/// SRAM accesses invalid type
PAC_ERR_MEMORY_INVALID_TYPE = 0x11003,
/// NVRAM accesses invalid address
PAC_ERR_NVRAM_INVALID_ADDRESS = 0x11004,
/// EEPROM write protection
PAC_ERR_EEP_WRITE_PROTECT = 0x11005,
/// EEPROM write fail
PAC_ERR_EEP_WRITE_FAIL = 0x11006,
/// EEPROM read fail
PAC_ERR_EEP_READ_FAIL = 0x11007,
///////////////////////////////////////////////////////////////////////
// WatchDog Error Codes
///////////////////////////////////////////////////////////////////////
/// The input value is invalid
PAC_ERR_WDT_INVALID_VALUE = 0x12001,
/// The wdt doesn't exist
PAC_ERR_WDT_UNEXIST = 0x12002,
/// The wdt init error
PAC_ERR_WDT_BASE_NOT_SET = 0x12003,
///////////////////////////////////////////////////////////////////////
// Interrupt Error Codes
///////////////////////////////////////////////////////////////////////
/// Create interrupt's event failure
PAC_ERR_INTR_CREATE_EVENT_FAILURE = 0x13001,
///////////////////////////////////////////////////////////////////////
// UART Error Codes
///////////////////////////////////////////////////////////////////////
/// Uart check sum error
PAC_ERR_UART_CHECKSUM = 0x14001,
/// Uart read timeout
PAC_ERR_UART_READ_TIMEOUT = 0x14002,
/// Uart response error
PAC_ERR_UART_RESPONSE = 0x14003,
/// Uart under input range
PAC_ERR_UART_UNDER_INPUT_RANGE = 0x14004,
/// Uart exceed input range
PAC_ERR_UART_EXCEED_INPUT_RANGE = 0x14005,
/// Uart open filed
PAC_ERR_UART_OPEN_FAILED = 0x14006,
/// Uart get Comm Modem status error
PAC_ERR_UART_GET_COMM_STATUS_ERROR = 0x14007,
/// Uart get wrong line status
PAC_ERR_UART_INVALID_VALUE = 0x14008,
/// Uart internal buffer overflow
PAC_ERR_UART_INTERNAL_BUFFER_OVERFLOW = 0x14009,
///////////////////////////////////////////////////////////////////////
// IO Error Codes
///////////////////////////////////////////////////////////////////////
/// IO card does not support this API function
PAC_ERR_IO_NOT_SUPPORT = 0x15001,
/// API unsupport this IO card
PAC_ERR_IO_ID = 0x15002,
/// Slot's value exceeds its range
PAC_ERR_IO_SLOT = 0x15003,
/// Channel's value exceeds its range
PAC_ERR_IO_CHANNEL = 0x15004,
/// Gain's value exceeds its range
PAC_ERR_IO_GAIN = 0x15005,
/// Unsupported interrupt mode
PAC_ERR_IO_INT_MODE = 0x15006,
/// I/O value is out of the range
PAC_ERR_IO_VALUE_OUT_OF_RANGE = 0x15007,
/// I/O channel is out of the range
PAC_ERR_IO_CHANNEL_OUT_OF_RANGE = 0x15008,
/// DI/O channel can't overwrite
PAC_ERR_IO_DO_CANNOT_OVERWRITE = 0x1500A,
/// AI/O channel can't overwrite
PAC_ERR_IO_AO_CANNOT_OVERWRITE = 0x1500B,
///////////////////////////////////////////////////////////////////////
// Backplane Timer Error Codes
///////////////////////////////////////////////////////////////////////
/// Backplane Timer registed
PAC_ERR_BPTIMER_REGISTERED = 0x16001,
/// Backplane Timer not registed
PAC_ERR_BPTIMER_NOT_REGISTERED = 0x16002,
}
}