using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
namespace PACNET
{
/// System Information API
public partial class Sys
{
//module type const
/// Genernal I-8000W module
public const int PAC_PARALLEL = 0x80;
/// I-8000RW module (R version: Provide PowerOn and Safe value)
public const int PAC_PARALLEL_RW = 0x81;
/// No module defined
public const int PAC_SCAN = 0x40;
/// I-8000W module with 32 DI channels
public const int PAC_DI32 = 0xE3;
///
public const int PAC_32BIT = 0x20;
/// I-8000W module with 32 DO channels
public const int PAC_DO32 = 0xE0;
/// I-8000W module with 16 DI channels and 16 DO channels
public const int PAC_DI16DO16 = 0xE2;
/// I-8000W module with 16 DI channels
public const int PAC_DI16 = 0xC3;
/// I-8000W module with 16 DO channels
public const int PAC_DO16 = 0xC0;
/// I-8000W module with 8 DI channels and 8 DO channels
public const int PAC_DI8DO8 = 0xC2;
///
public const int PAC_8K = 8000;
//1.1. PAC_API bool pac_BackwardCompatible()
///
/// This function retrieves the PAC running in the backward compatible mode or not.
///
/// Return true if the PAC is running in a backward compatible mode, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_BackwardCompatible")]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool BackwardCompatible();
//1.2. PAC_API void pac_ChangeSlot(BYTE slotNo)
///
/// This function specifies the slot from one to another.
///
/// [in]Specifies the slot number.
[DllImport("PACSDK.dll", EntryPoint = "pac_ChangeSlot")]
public static extern void ChangeSlot(byte slotNo);
//1.3. PAC_API void pac_EnableLED(int pin, bool bFlag)
///
/// This function decides the LED turning on or not.
///
/// [in] True: On, False:Off
[DllImport("PACSDK.dll", EntryPoint = "pac_EnableLED")]
public static extern void EnableLED(bool bFlag);
///
/// This function decides the LED turning on or not.
///
/// [in] 0: L1 LED, 1:L2 LED
/// [in] True: On, False:Off
[DllImport("PACSDK.dll", EntryPoint = "pac_EnableLEDs")]
public static extern void EnableLEDs(int pin, bool bFlag);
//1.4. PAC_API void pac_GetCPUVersion(LPSTR cpu_version)
///
/// This function retrieves the CPU version.
///
/// [out]Retrieves the CPU version of the PAC.
[DllImport("PACSDK.dll", EntryPoint = "pac_GetCPUVersion")]
public static extern void GetCPUVersion(byte[] cpu_version);
///
/// This function retrieves the CPU version.
///
/// Return the CPU version.
public static string GetCPUVersion()
{
byte[] result = new byte[128];
GetCPUVersion(result);
string CPUVersion = StrConvert.WideString(result);
return CPUVersion;
}
//1.5. PAC_API void pac_GetEbootVersion(LPSTR eboot_version)
///
/// This function retrieves the eboot version.
///
/// [out]Retrieves the Eboot version.
[DllImport("PACSDK.dll", EntryPoint = "pac_GetEbootVersion")]
public static extern void GetEbootVersion(byte[] eboot_version);
///
/// This function retrieves the eboot version.
///
/// Return the eboot version.
public static string GetEbootVersion()
{
byte[] result = new byte[32];
GetEbootVersion(result);
string EbootVersion = StrConvert.WideString(result);
if (EbootVersion.Length >= 8)
{
string temp = EbootVersion.Substring(6, 1);
if (temp == "0")
{ temp = EbootVersion.Substring(7, 1); }
else
{ temp = EbootVersion.Substring(6, 2); }
return EbootVersion.Substring(1, 1) + "." + EbootVersion.Substring(3, 1) + "." + EbootVersion.Substring(5, 1) + "." + temp;
}
else
return "";
}
//1.6. PAC_API void pac_GetMacAddress(BYTE LAN, LPSTR MacAddr)
///
/// This function retrieves the Mac address.
///
/// [in] Specifies the LAN number.
/// [out] Retrieves the MAC address of the specified LAN port.
[DllImport("PACSDK.dll", EntryPoint = "pac_GetMacAddress")]
public static extern void GetMacAddress(byte LAN, byte[] MacAddr);
///
/// This function retrieves the Mac address.
///
/// Specifies the LAN number.
/// Return the Mac address.
public static string GetMacAddress(byte LAN)
{
byte[] result = new byte[32];
GetMacAddress(LAN, result);
string MacAddr = StrConvert.WideString(result);
if (Environment.OSVersion.Version.Major == 5)
{
return MacAddr.Substring(0, 2) + "-" + MacAddr.Substring(2, 2) + "-" + MacAddr.Substring(4, 2) + "-" + MacAddr.Substring(6, 2) + "-" + MacAddr.Substring(8, 2) + "-" + MacAddr.Substring(10, 2);
}
else
{
return MacAddr;
}
}
//1.7. pac_GetMapCOM SDK 沒有
//1.8. PAC_API int pac_GetModuleName(BYTE slot, LPSTR strName)
///
/// This function is used to retrieve the name of an 8000 series I/O module, which is plugged
/// into a specific I/O slot in the Pac system. This function supports the collection of system
/// hardware configurations.
///
/// [in] Specify the slot number where the I/O module is plugged into.
/// [out] The pointer to a buffer to receive the name of the I/O module.
/// Return 255 if the module is I-8K series module, otherwise, undefined.
[DllImport("PACSDK.dll", EntryPoint = "pac_GetModuleName")]
public static extern int GetModuleName(byte slot, byte[] strName);
///
/// This function is used to retrieve the name of an 8000 series I/O module, which is plugged
/// into a specific I/O slot in the Pac system. This function supports the collection of system
/// hardware configurations.
///
/// [in]Specify the slot number where the I/O module is plugged into.
/// [out]The pointer to a buffer to receive the name of the I/O module.
/// Return 255 if the module is I-8K series module, otherwise, undefined.
public static int GetModuleName(byte slot, ref string strName)
{
int iRet;
byte[] str = new byte[128];
iRet = GetModuleName(slot, str);
strName = StrConvert.WideString(str);
return iRet;
}
///
/// This function is used to retrieve the name of an 8000 series I/O module, which is plugged
/// into a specific I/O slot in the Pac system. This function supports the collection of system
/// hardware configurations.
///
/// [in]Specify the slot number where the I/O module is plugged into.
/// Return the name of the I/O module.
public static string GetModuleName(byte slot)
{
byte[] str = new byte[128];
GetModuleName(slot, str);
return StrConvert.WideString(str);
}
//1.9. PAC_API int pac_GetModuleType(BYTE slot)
///
/// This function is used to retrieve the type of I/O modules.
///
/// [in] Specify the slot number where the I/O module is plugged into.
[DllImport("PACSDK.dll", EntryPoint = "pac_GetModuleType")]
public static extern int GetModuleType(int slot);
//1.10. PAC_API void pac_GetOSVersion(LPSTR os_version)
///
/// This function retrieves the OS version.
///
/// [out] Retrieves the OS version of the PAC.
[DllImport("PACSDK.dll", EntryPoint = "pac_GetOSVersion")]
public static extern void GetOSVersion(byte[] os_version);
///
/// This function retrieves the OS version.
///
/// Return the OS version.
public static string GetOSVersion()
{
byte[] result = new byte[32];
GetOSVersion(result);
string OSVersion = StrConvert.WideString(result);
if (Environment.OSVersion.Version.Major == 5)
{
return OSVersion.Substring(1, 1) + "." + OSVersion.Substring(3, 1) + "." + OSVersion.Substring(5, 1) + "." + OSVersion.Substring(7, 1);
}
else
{
return OSVersion;
}
}
//1.11. PAC_API int pac_GetRotaryID()
///
/// This function retrieves the rotary switch ID.
///
/// Return the position of the rotary switch.
[DllImport("PACSDK.dll", EntryPoint = "pac_GetRotaryID")]
public static extern int GetRotaryID();
//1.12. PAC_API void pac_GetSerialNumber(LPSTR SerialNumber)
///
/// This function retrieves the serial number.
///
/// [out] Retrieves the serial number of the PAC.
[DllImport("PACSDK.dll", EntryPoint = "pac_GetSerialNumber")]
public static extern int GetSerialNumber(byte[] SerialNumber);
///
/// This function retrieves the serial number.
///
/// Return the serial number.
public static string GetSerialNumber()
{
byte[] result = new byte[32];
GetSerialNumber(result);
string SN = StrConvert.WideString(result);
return string.Format("{0}-{1}-{2}-{3}-{4}-{5}-{6}-{7}",
SN.Substring(0, 2),
SN.Substring(2, 2),
SN.Substring(4, 2),
SN.Substring(6, 2),
SN.Substring(8, 2),
SN.Substring(10, 2),
SN.Substring(12, 2),
SN.Substring(14, 2));
}
//1.13. pac_GetPacNetVersion()
///
/// This function retrieves the version of the PacNet.dll.
///
/// Return the version of the PacNet.dll.
public static string GetPacNetVersion()
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();//"1.2.1.1";
}
//1.14. PAC_API void pac_GetSDKVersion(LPSTR sdk_version)
///
/// This function retrieves the SDK version.
///
/// [out] Retrieves the version of the PacSDK.
[DllImport("PACSDK.dll", EntryPoint = "pac_GetSDKVersion")]
public static extern int GetSDKVersion(byte[] sdk_version);
///
/// This function retrieves the SDK version.
///
/// Return the SDK version.
public static string GetPacSDKVersion()
{
byte[] result = new byte[32];
GetSDKVersion(result);
string SDKVersion = StrConvert.WideString(result);
return SDKVersion;
}
//1.15. PAC_API void pac_Reboot(void)
///
/// This function reboots the device.
///
[DllImport("PACSDK.dll", EntryPoint = "pac_Reboot")]
public static extern void Reboot();
///////////////////////////////////////////////////////////////////////
//
// from Xpac
//
///////////////////////////////////////////////////////////////////////
//1.6. PAC_API bool pac_CheckSDKVersion(DWORD version)
///
/// This function specifies the application not access the XPacSDK.dll which is wrong version.
///
/// [in] Specifies SDK version.
/// Return TRUE, if the version is correctly. Otherwise, return false.
[DllImport("PACSDK.dll", EntryPoint = "pac_CheckSDKVersion")]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool CheckSDKVersion(uint version);
//1.7. PAC_API bool pac_ModuleExists(HANDLE hPort, int slot)
///
/// This function specifies the IO module whether exist or not, no matter the module is local or remote.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// It your IO module is located at local, this Parameter should be 0.
/// [in] The slot in which module is to check exists or not.
/// If the IO module is remote, please input the module’s ID.
/// Return TRUE, if the module exists. Otherwise, return false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ModuleExists")]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool ModuleExists(IntPtr hPort, byte slot);
///////////////////////////////////////////////////////////////////////
//
// Undocumented
//
///////////////////////////////////////////////////////////////////////
//1.?. PAC_API int pac_GetModuleVersion(BYTE slot, LPSTR strName);
///
///
///
///
///
[DllImport("PACSDK.dll", EntryPoint = "pac_GetModuleVersion")]
public static extern int GetModuleVersion(int slot, byte[] strName);
}
}