using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; ///I-8088W version 1.0.0.6, 2011/07/05 ///I-8088W version 1.0.0.7, 2011/07/19 ///remove SetPWMDutyCount function namespace pac8026WNet { public class pac8026W { private class ICPDAS { // for I/O version management [DllImport("pac_i8026W.dll", EntryPoint = "pac_i8026W_GetLibVersion")] public static extern Int16 pac_i8026W_GetLibVersion(); [DllImport("pac_i8026W.dll", EntryPoint = "pac_i8026W_GetLibDate")] public static extern void pac_i8026W_GetLibDate(byte[] libDate); [DllImport("pac_i8026W.dll", EntryPoint = "pac_i8026W_GetFirmwareVer")] public static extern Int16 pac_i8026W_GetFirmwareVer(int Slot); [DllImport("pac_i8026W.dll", EntryPoint = "pac_i8026W_Init")] public static extern Int16 pac_i8026W_Init(int Slot); [DllImport("pac_i8026W.dll", EntryPoint = "pac_i8026W_WriteDO")] public static extern void pac_i8026W_WriteDO(int slot, Int16 doVal); [DllImport("pac_i8026W.dll", EntryPoint = "pac_i8026W_WriteDOBit")] public static extern void pac_i8026W_WriteDOBit(int slot, int chIndex, Int16 bitVal); [DllImport("pac_i8026W.dll", EntryPoint = "pac_i8026W_ReadDIO")] public static extern Int16 pac_i8026W_ReadDIO(int slot, ref Int16 diVal, ref Int16 doVal, byte[] diBitArr, byte[] doBitArr); [DllImport("pac_i8026W.dll", EntryPoint = "pac_i8026W_WriteAO")] public static extern Int16 pac_i8026W_WriteAO(int slot, int chIndex, Int16 gain, float aoData); [DllImport("pac_i8026W.dll", EntryPoint = "pac_i8026W_WriteAOHex")] public static extern Int16 pac_i8026W_WriteAOHex(int slot, int chIndex, Int16 gain, Int16 hexData); [DllImport("pac_i8026W.dll", EntryPoint = "pac_i8026W_ReadbackAO")] public static extern Int16 pac_i8026W_ReadbackAO(int slot, int chIndex, ref float fVal); [DllImport("pac_i8026W.dll", EntryPoint = "pac_i8026W_ReadbackAOHex")] public static extern Int16 pac_i8026W_ReadbackAOHex(int slot, int chIndex, ref Int16 hVal); [DllImport("pac_i8026W.dll", EntryPoint = "pac_i8026W_ReadAO_GainOffset")] public static extern void pac_i8026W_ReadAO_GainOffset(int slot, int chIndex, Int16 gain, ref UInt16 gainValue, ref Int16 offsetValue); [DllImport("pac_i8026W.dll", EntryPoint = "pac_i8026W_ReadAIHex")] public static extern Int16 pac_i8026W_ReadAIHex(int slot, int chIndex, Int16 gain, ref Int16 hVal); [DllImport("pac_i8026W.dll", EntryPoint = "pac_i8026W_ReadAI")] public static extern Int16 pac_i8026W_ReadAI(int slot, int chIndex, short gain, ref float fVal); // // public static extern float pac_i8026W_ReadAI(int slot, int chIndex, Int16 gain); [DllImport("pac_i8026W.dll", EntryPoint = "pac_i8026W_ReadAIRefGainEEP")] public static extern Int16 pac_i8026W_ReadAIRefGainEEP(int slot, int ch, Int16 gain, ref UInt16 gainValue); } /// /// Get the library version of this DLL (pac_i8026W.dll) /// /// library version public static Int16 LibVersion() { return ICPDAS.pac_i8026W_GetLibVersion(); } /// /// Get the firmware version of I-8088W in the specified slot. /// /// 1 ~ 7 (the slot which I-8088W is inserted) /// firmware version public static Int16 FirmwareVersion(int slot) { return ICPDAS.pac_i8026W_GetFirmwareVer(slot); } /// /// Get the building date of this DLL (pac_i8026W.dll) /// /// library building date public static string LibDate() { //return Arr2Str(ICPDAS.pac_i8017H_GetLibDate()); byte[] libDate = new byte[32]; ICPDAS.pac_i8026W_GetLibDate(libDate); return AscArr2Str(libDate); } /// /// Initialize the I-8088W in the specified slot /// /// 1 ~ 7 (the slot which I-8088W is inserted) /// the Error Codes which are defined in pac_i8026W.h public static Int16 Init(int slot) { return ICPDAS.pac_i8026W_Init(slot); } private static string AscArr2Str(byte[] b) { return System.Text.UnicodeEncoding.Unicode.GetString( System.Text.ASCIIEncoding.Convert(System.Text.Encoding.ASCII, System.Text.Encoding.Unicode, b), 0, b.Length); } public static string Arr2Str(byte[] buffer) { return (new UnicodeEncoding()).GetString(buffer, 0, buffer.Length); } public static void WriteDO(int slot, Int16 doVal) { ICPDAS.pac_i8026W_WriteDO(slot, doVal); } public static void WriteDOBit(int slot, int chIndex, Int16 bitVal) { ICPDAS.pac_i8026W_WriteDOBit(slot, chIndex, bitVal); } public static Int16 ReadDIO(int slot, ref Int16 diVal, ref Int16 doVal, byte[] diBitArr, byte[] doBitArr) { return ICPDAS.pac_i8026W_ReadDIO(slot, ref diVal, ref doVal, diBitArr, doBitArr); } public static Int16 WriteAO(int slot, int chIndex, Int16 gain, float aoData) { return ICPDAS.pac_i8026W_WriteAO(slot, chIndex, gain, aoData); } public static Int16 WriteAOHex(int slot, int chIndex, Int16 gain, Int16 hexData) { return ICPDAS.pac_i8026W_WriteAOHex(slot, chIndex, gain, hexData); } public static Int16 AOReadback(int slot, int chIndex, ref float fVal) { return ICPDAS.pac_i8026W_ReadbackAO(slot, chIndex, ref fVal); } public static Int16 AOHexReadback(int slot, int chIndex, ref Int16 hVal) { return ICPDAS.pac_i8026W_ReadbackAOHex(slot, chIndex,ref hVal ); } public static void ReadAO_GainOffset(int slot, int chIndex, Int16 gain, ref UInt16 gainValue, ref Int16 offsetValue) { ICPDAS.pac_i8026W_ReadAO_GainOffset(slot, chIndex, gain, ref gainValue, ref offsetValue); } // QC 專用 // rV =0, 4 倍參考電壓 , 1 2 倍參考電壓 // 10-bit refGain for ref Voltage // 程式對 library 傳入 gain 數值 // public static Int16 ReadAIRefGainEEP(int slot, int ch, Int16 gain, ref UInt16 gainValue) { return ICPDAS.pac_i8026W_ReadAIRefGainEEP(slot, ch, gain, ref gainValue); } public static Int16 ReadAIHex(int slot, int chIndex, Int16 gain,ref Int16 hVal) { return ICPDAS.pac_i8026W_ReadAIHex(slot, chIndex, gain, ref hVal); } public static Int16 ReadAI(int slot, int chIndex, Int16 gain ,ref float fVal) { return ICPDAS.pac_i8026W_ReadAI(slot, chIndex, gain, ref fVal ); } } }