using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
namespace PACNET
{
/// PAC_IO API
public partial class PAC_IO
{
///
/// remote mode, the address need call a macro.
///
public static int PAC_REMOTE_IO(int iAddress)
{
return (0x1000 | iAddress);
}
///
///
public static int PAC_REMOTE_UNIT(int iAddress, int iSlot)
{
return (0x100000 | iAddress << 8 | iSlot);
}
//9.1. pac_GetBit
///
/// The function can retrieve the value which in specific bit.
///
/// Which IO result wants to get bit.
/// Specific bit to retrieve.
/// The value of specific index.
public static bool GetBit(int value, int index)
{
int bit = (value & (1 << index));
if (bit == 0)
return false;
else
return true;
}
//9.2. PAC_API bool pac_WriteDO(HANDLE hPort, int slot, int iDO_TotalCh, DWORD lDO_Value)
///
/// This function writes the DO values to DO modules.
///
/// [in] the serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO (Address).
/// [in] The total number of DO channels of the DO modules.
/// [in] A 8-digit hexadecimal value, where bit 0 corresponds to DO0, bit 31 corresponds to
/// DO31, etc. When the bit is 1, it denotes that the digital output channel is on, and 0
/// denotes that the digital output channel is off.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_WriteDO")]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool WriteDO(IntPtr hPort, int slot, int iDO_TotalCh, uint lDO_Value);
//9.3. PAC_API bool pac_WriteDOBit(HANDLE hPort, int slot, int iDO_TotalCh, int iChannel, int iBitValue)
///
/// This function writes a single bit of value to the DO module, that is, only the channel
/// corresponding to the bit is changed.
///
/// [in] the serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [in] The total number of DO channels of the DO modules.
/// [in] The DO channel to change.
/// [in] 1 is to turn on the DO channel; 0 is off.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_WriteDOBit")]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool WriteDOBit(IntPtr hPort, int slot, int iDO_TotalCh, int iChannel, int iBitValue);
//9.4. PAC_API bool pac_ReadDO(HANDLE hPort, int slot, int iDO_TotalCh, DWORD *lDO_Value)
///
/// This function reads the DO value of the DO module.
///
/// [in] the serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [in] The total number of DO channels of the DO modules.
/// [in] The pointer of the DO value to read from the DO module.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ReadDO")]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool ReadDO(IntPtr hPort, int slot, int iDO_TotalCh, ref uint lDO_Value);
//9.5. PAC_API bool pac_ReadDI(HANDLE hPort, int slot, int iDI_TotalCh, DWORD *lDI_Value)
///
/// This function reads the DI value of the DI module.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [in] The total channels of the DI module.
/// [out] The pointer to DI value to read back.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ReadDI")]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool ReadDI(IntPtr hPort, int slot, int iDO_TotalCh, ref uint lDO_Value);
//9.6. PAC_API bool pac_ReadDIO(HANDLE hPort, int slot, int iDI_TotalCh, int iDO_TotalCh, DWORD* lDI_Value, DWORD* lDO_Value)
///
/// This function reads the DI and the DO values of the DIO module.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [in] The total number of DI channels of the DIO module.
/// [in] The total number of DO channels of the DIO module.
/// [out] The pointer to the value of DI read back.
/// [out] The pointers to the value of DO read back.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ReadDIO")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ReadDIO(IntPtr hPort, int slot, int iDI_TotalCh, int iDO_TotalCh, ref uint lDI_Value, ref uint lDO_Value);
//9.7. PAC_API bool pac_ReadDILatch(HANDLE hPort, int slot, int iDI_TotalCh, int iLatchType, DWORD *lDI_Latch_Value)
///
/// This function reads the DI latch value of the DI module.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [in] The total number of the DI channels of the DI module.
/// [in] The latch type specified to read latch value back.
/// 1: latched high status, 0: latched low status
/// [out] The pointer to the latch value read back from the DI module.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ReadDILatch")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ReadDILatch(IntPtr hPort, int slot, int iDI_TotalCh, int iLatchType, ref uint lDI_Latch_Value);
//9.8. PAC_API bool pac_ClearDILatch(HANDLE hPort, int slot)
///
/// This function clears the latch value of the DI module.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ClearDILatch")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ClearDILatch(IntPtr hPort, int slot);
//9.9. PAC_API bool pac_ReadDIOLatch(HANDLE hPort, int slot, int iDI_TotalCh, int iDO_TotalCh, int iLatchType, DWORD *lDI_Latch_Value, DWORD *lDO_Latch_Value)
///
/// This function reads the latch values of the DI and DO channels of the DIO module.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [in] The total number of the DI channels of the DIO module.
/// [in] The total number of the DO channels of the DIO module.
/// [in] The type of the latch value read back.
/// [out] The pointer to the DI latch value read back.
/// [out] The pointer to the DO latch value read back.
[DllImport("PACSDK.dll", EntryPoint = "pac_ReadDIOLatch")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ReadDIOLatch(IntPtr hPort, int slot, int iDI_TotalCh, int iDO_TotalCh, int iLatchType, ref uint lDI_Latch_Value, ref uint lDO_Latch_Value);
//9.10. PAC_API bool pac_ClearDIOLatch(HANDLE hPort, int slot)
///
/// This function clears the latch values of DI and DO channels of the DIO module.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ClearDIOLatch")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ClearDIOLatch(IntPtr hPort, int slot);
//9.11. PAC_API bool pac_ReadDICNT(HANDLE hPort, int slot, int iChannel, int iDI_TotalCh, DWORD *lCounter_Value)
///
/// This function reads the counts of the DI channels of the DI module.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [in] The channel that the counter value belongs.
/// [in] Total number of the DI channels of the DI module.
/// [out] The pointer to the counter value.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ReadDICNT")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ReadDICNT(IntPtr hPort, int slot, int iChannel, int iDI_TotalCh, ref uint lCounter_Value);
//9.12. PAC_API bool pac_ClearDICNT(HANDLE hPort, int slot, int iChannel, int iDI_TotalCh)
///
/// This function clears the counter value of the DI channel of the DI module.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [in] The channel that the counter value belongs.
/// [in] Total number of the DI channels of the DI module.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ClearDICNT")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ClearDICNT(IntPtr hPort, int slot, int iChannel, int iDI_TotalCh);
//9.13. PAC_API bool pac_WriteAO(HANDLE hPort, int slot, int iChannel, int iAO_TotalCh, float fValue)
///
/// This function writes the AO value to the AO modules.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [in] The channel that is written thee AO value to.
/// [in] The total number of the AO channels of the AO module.
/// [in] The AO value to write to the AO module.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_WriteAO")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool WriteAO(IntPtr hPort, int slot, int iChannel, int iAO_TotalCh, float fValue);
//9.14. PAC_API bool pac_ReadAO(HANDLE hPort, int slot, int iChannel, int iAO_TotalCh, float *fValue)
///
/// This function reads the AO value of the AO module.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [in] Read the AO value from the channel.
/// [in] The total number of the AO channels of the AO module.
/// [in] The pointer to the AO value that is read back from the AO module.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ReadAO")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ReadAO(IntPtr hPort, int slot, int iChannel, int iAO_TotalCh, ref float fValue);
//9.15. PAC_API bool pac_ReadAI(HANDLE hPort, int slot, int iChannel, int iAI_TotalCh, float *fValue)
///
/// This function reads the engineering-mode AI value of the AI module.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [in] Read the AI value from the channel.
/// [in] The total number of the AI channels of the AI module.
/// [in] The pointer to the AI value that is read back from the AI module.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ReadAI")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ReadAI(IntPtr hPort, int slot, int iChannel, int iAI_TotalCh, ref float fValue);
//9.16. PAC_API bool pac_ReadAIHex(HANDLE hPort, int slot, int iChannel, int iAI_TotalCh, int *iValue)
///
/// This function reads the 2's complement-mode AI value of the AI module.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [in] Read the AI value from the channel.
/// [in] The total number of the AI channels of the AI module.
/// [in] The pointer to the AI value that is read back from the AI module.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ReadAIHex")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ReadAIHex(IntPtr hPort, int slot, int iChannel, int iAI_TotalCh, ref int iValue);
//9.17. PAC_API bool pac_ReadAIAll(HANDLE hPort, int slot, float fValue[])
///
/// This function reads all the AI values of all channels in engineering-mode of the AI module.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [out] The array contains the AI values that read back from the AI module.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ReadAIAll")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ReadAIAll(IntPtr hPort, int slot, float[] fValue);
//9.18. PAC_API bool pac_ReadAIAllHex(HANDLE hPort, int slot, int iValue[])
///
/// This function reads all the AI values of all channels in 2's complement-mode of the AI module.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [out] The array contains the AI values that read back from the AI module.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ReadAIAllHex")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ReadAIAllHex(IntPtr hPort, int slot, int[] iValue);
//9.19. PAC_API bool pac_ReadCNT(HANDLE hPort, int slot, int iChannel, DWORD *lCounter_Value)
///
/// This function reads the counter values of the counter/frequency modules.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [in] The channel that reads the counter value back from the counter/frequency module.
/// [out] The pointer to the counter value that reads back from the counter/frequency module.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ReadCNT")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ReadCNT(IntPtr hPort, int slot, int iChannel, ref uint lCounter_Value);
//9.20. PAC_API bool pac_ClearCNT(HANDLE hPort, int slot, int iChannel)
///
/// This function clears the counter values of the counter/frequency modules.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [in] The channel that clears the counter value back from the counter/frequency module.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ClearCNT")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ClearCNT(IntPtr hPort, int slot, int iChannel);
//9.21. PAC_API bool pac_ReadCNTOverflow(HANDLE hPort, int slot, int iChannel, int *iOverflow)
///
/// This function clears the counter values of the counter/frequency modules.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [in] The channel that reads the counter overflows value back from the counter/frequency module.
/// [out] The pointer to the counter overflow that is read back from the counter/frequency module.
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ReadCNTOverflow")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ReadCNTOverflow(IntPtr hPort, int slot, int iChannel, ref int iOverflow);
//9.17. PAC_API bool pac_ReadAIAll(HANDLE hPort, int slot, float fValue[])
///
/// This function reads all the AI values of all channels in engineering-mode of the AI module.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [out] The array contains the AI values that read back from the AI module.
///
///
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ReadAIAllExt")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ReadAIAllExt(IntPtr hPort, int slot, float[] fValue, int Buff_Len, ref int Channel);
//9.18. PAC_API bool pac_ReadAIAllHex(HANDLE hPort, int slot, int iValue[])
///
/// This function reads all the AI values of all channels in 2's complement-mode of the AI module.
///
/// [in] The serial port HANDLE opened by uart_Open().
/// 0, if the module is 8k modules in local
/// [in] The slot in which module is to receive the command. Default is local.
/// If the IO module is remote, please use the macro, pac_REMOTE_IO(0...255).
/// [out] The array contains the AI values that read back from the AI module.
///
///
/// Return true if success, otherwise false.
[DllImport("PACSDK.dll", EntryPoint = "pac_ReadAIAllHexExt")]
[return:MarshalAs(UnmanagedType.I1)]
public static extern bool ReadAIAllHexExt(IntPtr hPort, int slot, int[] iValue, int Buff_Len, ref int Channel);
}
}