using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; ///I-8017HW version 0.2.1.3, 2011/07/05 ///I-8017HW version 0.2.1.4, 2011/07/19 /// namespace pac8017HWNet { public class pac8017HW { private static int[] slotCurrentChIndex = new int[8]; private static int[] slotCurrentGain = new int[8]; private class ICPDAS { private const string lib = "pac_i8017HW.dll"; [DllImport(lib)] public static extern Int16 pac_i8017HW_GetLibVersion(); [DllImport(lib)] public static extern void pac_i8017HW_GetLibDate(byte[] libDate); [DllImport(lib)] public static extern Int16 pac_i8017HW_GetFirmwareVersion(int slot,ref Int16 firmware); [DllImport(lib)] public static extern Int16 pac_i8017HW_GetSingleEndJumper(int slot, ref Int16 Jumper); [DllImport(lib)] public static extern Int16 pac_i8017HW_ReadGainOffset_Info(int slot, int gain, ref UInt16 gainValue, ref Int16 offsetValue); [DllImport(lib)] public static extern Int16 pac_i8017HW_Init(int slot); [DllImport(lib)] public static extern Int16 pac_i8017HW_SetLED(int slot, UInt32 led); [DllImport(lib)] public static extern Int16 pac_i8017HW_ReadAI(int slot,int ch,int gain,ref float fValue); [DllImport(lib)] public static extern Int16 pac_i8017HW_ReadAIHex(int slot,int ch, int gain, ref Int16 iValue); [DllImport(lib)] public static extern Int16 pac_i8017H_ReadAI_AVG(int slot, int ch, int gain, UInt16 averageCnt, ref float fValue); [DllImport(lib)] public static extern Int16 pac_i8017H_ReadAIHex_AVG(int slot, int ch, int gain, UInt16 averageCnt, ref Int16 iValue); } /// /// Get the library version of this DLL (pac_i8017HW.dll) /// /// library version public static Int16 LibVersion() { return ICPDAS.pac_i8017HW_GetLibVersion(); } /// /// Get the firmware version of the I-8017HW in the specified slot /// /// 1 ~ 7 (the slot which I-8017HW is inserted) /// the read-back firmware version /// the Error Codes which are defined in pac_i8017HW.h public static Int16 FirmwareVersion(int slot,ref Int16 firmware) { return ICPDAS.pac_i8017HW_GetFirmwareVersion(slot, ref firmware); } /// /// Get the building date of this DLL (pac_i8017HW.dll) /// /// library building date public static string LibDate() { //return Arr2Str(ICPDAS.pac_i8017H_GetLibDate()); byte[] libDate= new byte[32] ; ICPDAS.pac_i8017HW_GetLibDate(libDate); //return libDate.Length.ToString(); //Console.WriteLine("libDate= {0} Len= {1}\n", AscArr2Str(libDate), libDate.Length.ToString()); return AscArr2Str(libDate); } /// /// Initialize the I-8017HW in the specified slot /// /// 1 ~ 7 (the slot which I-8017HW is inserted) /// the Error Codes which are defined in pac_i8017HW.h public static Int16 Init(int slot) { return ICPDAS.pac_i8017HW_Init(slot); } /// /// Read the analog input value in the floating-point format from the specified channel /// /// 1 ~ 7 (the slot which I-8017HW is inserted) /// 0 ~ 7 if Differential mode; 0 ~ 15 if SingleEnded mode /// the gain which is defined by the enum Gain /// the read back floating-point value /// the Error Codes which are defined in pac_i8017HW.h public static Int16 ReadAI(int slot, int ch, int gain, ref float fValue) { return ICPDAS.pac_i8017HW_ReadAI(slot, ch, gain, ref fValue); } /// /// Read the analog input value in the hex format from the specified channel /// /// 1 ~ 7 (the slot which I-8017HW is inserted) /// 0 ~ 7 if Differential mode; 0 ~ 15 if SingleEnded mode /// the gain which is defined by the enum Gain /// the read back value in hexadecimal format /// the Error Codes which are defined in pac_i8017HW.h public static Int16 ReadAIHex(int slot, int ch, int gain, ref Int16 hex16Bit) { return ICPDAS.pac_i8017HW_ReadAIHex(slot, ch, gain, ref hex16Bit); } /// /// Read the analog input value in the floating-point format from the specified channel /// /// 1 ~ 7 (the slot which I-8017HW is inserted) /// 0 ~ 7 if Differential mode; 0 ~ 15 if SingleEnded mode /// the gain which is defined by the enum Gain /// the sample count to average the input values /// the read back floating-point value /// the Error Codes which are defined in pac_i8017HW.h public static Int16 ReadAI_AVG(int slot, int ch, int gain,UInt16 averageCnt, ref float fValue) { return ICPDAS.pac_i8017H_ReadAI_AVG(slot, ch, gain,averageCnt,ref fValue); } /// /// Read the analog input value in the hex format from the specified channel /// /// 1 ~ 7 (the slot which I-8017HW is inserted) /// 0 ~ 7 if Differential mode; 0 ~ 15 if SingleEnded mode /// the gain which is defined by the enum Gain /// the sample count to average the input values /// the read back value in hexadecimal format /// the Error Codes which are defined in pac_i8017HW.h public static Int16 ReadAIHex_AVG(int slot, int ch, int gain, UInt16 averageCnt, ref Int16 hex16Bit) { return ICPDAS.pac_i8017H_ReadAIHex_AVG(slot, ch, gain,averageCnt, ref hex16Bit); } /// /// Get the type of the input channels; differential or single-ended /// /// 1 ~ 7 (the slot which I-8017HW is inserted) /// jumper status of input channel type; Differential or SingleEnded /// the Error Codes which are defined in pac_i8017HW.h public static Int16 SingleEndJumper(int slot,ref Int16 selJumper) { return ICPDAS.pac_i8017HW_GetSingleEndJumper(slot,ref selJumper); } /// /// Get the gain value and the offset for a certain gain of I-8017HW in the specified slot /// /// 1 ~ 7 (the slot which I-8017HW is inserted) /// the gain which is defined by the enum Gain /// the calibated gain value /// the calibated offset value /// the Error Codes which are defined in pac_i8017HW.h public static Int16 GainOffset_Info(int slot, int gain, ref UInt16 gainValue, ref Int16 offsetValue) { return ICPDAS.pac_i8017HW_ReadGainOffset_Info(slot,gain,ref gainValue,ref offsetValue); } /// /// Set the LEDs on the I-8017HW in the specified slot /// /// 1 ~ 7 (the slot which I-8017HW is inserted) /// 0 ~ 0xFFFF, 16-bit unsigned value which represents the 16 LEDs /// the Error Codes which are defined in pac_i8017HW.h public static Int16 SetLED(int slot, UInt32 led) { return ICPDAS.pac_i8017HW_SetLED(slot, led); } 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); } } }