zoukankan      html  css  js  c++  java
  • 关于NuDaqPci 数据采集

    最近在做公司一个fct的测试及调试软件

    设计到的比较多的通信问题

    1,Gpib通信(调用ADL-GPIB)

    2,串口通信

    3,Usb通信(调用USBXpress)

    4,Pci通信(调用PCIS-DASK)

    大多数的驱动都是使用

    先写了一个Gpib通信的类,参照园子里的朋友的cs文件,有改动

    1.Gpibhelper如下:

    using System.Runtime.InteropServices;
    using System.Text;
    
    
    public class GPIB 
    {
        public enum ibsta_bit_numbers
        {
            DCAS_NUM = 0,
            DTAS_NUM = 1,
            LACS_NUM = 2,
            TACS_NUM = 3,
            ATN_NUM = 4,
            CIC_NUM = 5,
            REM_NUM = 6,
            LOK_NUM = 7,
            CMPL_NUM = 8,
            EVENT_NUM = 9,
            SPOLL_NUM = 10,
            RQS_NUM = 11,
            SRQI_NUM = 12,
            END_NUM = 13,
            TIMO_NUM = 14,
            ERR_NUM = 15
        };
    
        /* IBSTA status bits (returned by all functions) */
        public enum ibsta_bits
        {
            DCAS = ( 1 << ibsta_bit_numbers.DCAS_NUM ),    /* device clear state */
            DTAS = ( 1 << ibsta_bit_numbers.DTAS_NUM ),    /* device trigger state */
            LACS = ( 1 <<  ibsta_bit_numbers.LACS_NUM ),    /* GPIB interface is addressed as Listener */
            TACS = ( 1 <<  ibsta_bit_numbers.TACS_NUM ),    /* GPIB interface is addressed as Talker */
            ATN = ( 1 <<  ibsta_bit_numbers.ATN_NUM ),    /* Attention is asserted */
            CIC = ( 1 <<  ibsta_bit_numbers.CIC_NUM ),    /* GPIB interface is Controller-in-Charge */
            REM = ( 1 << ibsta_bit_numbers.REM_NUM ),    /* remote state */
            LOK = ( 1 << ibsta_bit_numbers.LOK_NUM ),    /* lockout state */
            CMPL = ( 1 <<  ibsta_bit_numbers.CMPL_NUM ),    /* I/O is complete  */
            EVENT = ( 1 << ibsta_bit_numbers.EVENT_NUM ),    /* DCAS, DTAS, or IFC has occurred */
            SPOLL = ( 1 << ibsta_bit_numbers.SPOLL_NUM ),    /* board serial polled by busmaster */
            RQS = ( 1 <<  ibsta_bit_numbers.RQS_NUM ),    /* Device requesting service  */
            SRQI = ( 1 << ibsta_bit_numbers.SRQI_NUM ),    /* SRQ is asserted */
            END = ( 1 << ibsta_bit_numbers.END_NUM ),    /* EOI or EOS encountered */
            TIMO = ( 1 << ibsta_bit_numbers.TIMO_NUM ),    /* Time limit on I/O or wait function exceeded */
            ERR = ( 1 << ibsta_bit_numbers.ERR_NUM )    /* Function call terminated on error */
        };
        /* IBERR error codes */
        public enum iberr_code
        {
            EDVR = 0,        /* system error */
            ECIC = 1,    /* not CIC */
            ENOL = 2,        /* no listeners */
            EADR = 3,        /* CIC and not addressed before I/O */
            EARG = 4,        /* bad argument to function call */
            ESAC = 5,        /* not SAC */
            EABO = 6,        /* I/O operation was aborted */
            ENEB = 7,        /* non-existent board (GPIB interface offline) */
            EDMA = 8,        /* DMA hardware error detected */
            EOIP = 10,        /* new I/O attempted with old I/O in progress  */
            ECAP = 11,        /* no capability for intended opeation */
            EFSO = 12,        /* file system operation error */
            EBUS = 14,        /* bus error */
            ESTB = 15,        /* lost serial poll bytes */
            ESRQ = 16,        /* SRQ stuck on */
            ETAB = 20              /* Table Overflow */
        };
        /* Timeout values and meanings */
    
        public enum gpib_timeout
        {
            TNONE = 0,        /* Infinite timeout (disabled)     */
            T10us = 1,        /* Timeout of 10 usec (ideal)      */
            T30us = 2,        /* Timeout of 30 usec (ideal)      */
            T100us = 3,        /* Timeout of 100 usec (ideal)     */
            T300us = 4,        /* Timeout of 300 usec (ideal)     */
            T1ms = 5,        /* Timeout of 1 msec (ideal)       */
            T3ms = 6,        /* Timeout of 3 msec (ideal)       */
            T10ms = 7,        /* Timeout of 10 msec (ideal)      */
            T30ms = 8,        /* Timeout of 30 msec (ideal)      */
            T100ms = 9,        /* Timeout of 100 msec (ideal)     */
            T300ms = 10,    /* Timeout of 300 msec (ideal)     */
            T1s = 11,        /* Timeout of 1 sec (ideal)        */
            T3s = 12,        /* Timeout of 3 sec (ideal)        */
            T10s = 13,        /* Timeout of 10 sec (ideal)       */
            T30s = 14,        /* Timeout of 30 sec (ideal)       */
            T100s = 15,        /* Timeout of 100 sec (ideal)      */
            T300s = 16,        /* Timeout of 300 sec (ideal)      */
            T1000s = 17        /* Timeout of 1000 sec (maximum)   */
        };
    
        /* End-of-string (EOS) modes for use with ibeos */
    
        public enum eos_flags
        {
            EOS_MASK = 0x1c00,
            REOS = 0x0400,        /* Terminate reads on EOS    */
            XEOS = 0x800,    /* assert EOI when EOS char is sent */
            BIN = 0x1000        /* Do 8-bit compare on EOS    */
        };
    
        /* GPIB Bus Control Lines bit vector */
        public enum bus_control_line
        {
            ValidDAV = 0x01,
            ValidNDAC = 0x02,
            ValidNRFD = 0x04,
            ValidIFC = 0x08,
            ValidREN = 0x10,
            ValidSRQ = 0x20,
            ValidATN = 0x40,
            ValidEOI = 0x80,
            ValidALL = 0xff,
            BusDAV = 0x0100,        /* DAV  line status bit */
            BusNDAC = 0x0200,        /* NDAC line status bit */
            BusNRFD = 0x0400,        /* NRFD line status bit */
            BusIFC = 0x0800,        /* IFC  line status bit */
            BusREN = 0x1000,        /* REN  line status bit */
            BusSRQ = 0x2000,        /* SRQ  line status bit */
            BusATN = 0x4000,        /* ATN  line status bit */
            BusEOI = 0x8000        /* EOI  line status bit */
        };
    
    
        const int gpib_addr_max = 30;    /* max address for primary/secondary gpib addresses */
    
        public enum ibask_option
        {
            IbaPAD = 0x1,
            IbaSAD = 0x2,
            IbaTMO = 0x3,
            IbaEOT = 0x4,
            IbaPPC = 0x5,    /* board only */
            IbaREADDR = 0x6,    /* device only */
            IbaAUTOPOLL = 0x7,    /* board only */
            IbaCICPROT = 0x8,    /* board only */
            IbaIRQ = 0x9,    /* board only */
            IbaSC = 0xa,    /* board only */
            IbaSRE = 0xb,    /* board only */
            IbaEOSrd = 0xc,
            IbaEOSwrt = 0xd,
            IbaEOScmp = 0xe,
            IbaEOSchar = 0xf,
            IbaPP2 = 0x10,    /* board only */
            IbaTIMING = 0x11,    /* board only */
            IbaDMA = 0x12,    /* board only */
            IbaReadAdjust = 0x13,
            IbaWriteAdjust = 0x14,
            IbaEventQueue = 0x15,    /* board only */
            IbaSPollBit = 0x16,    /* board only */
            IbaSpollBit = 0x16,    /* board only */
            IbaSendLLO = 0x17,    /* board only */
            IbaSPollTime = 0x18,    /* device only */
            IbaPPollTime = 0x19,    /* board only */
            IbaEndBitIsNormal = 0x1a,
            IbaUnAddr = 0x1b,    /* device only */
            IbaHSCableLength = 0x1f,    /* board only */
            IbaIst = 0x20,    /* board only */
            IbaRsv = 0x21,    /* board only */
            IbaBNA = 0x200,    /* device only */
            IbaBaseAddr    = 0x201    /* GPIB board's base I/O address.*/
        };
    
        public enum ibconfig_option
        {
            IbcPAD = 0x1,
            IbcSAD = 0x2,
            IbcTMO = 0x3,
            IbcEOT = 0x4,
            IbcPPC = 0x5,    /* board only */
            IbcREADDR = 0x6,    /* device only */
            IbcAUTOPOLL = 0x7,    /* board only */
            IbcCICPROT = 0x8,    /* board only */
            IbcIRQ = 0x9,    /* board only */
            IbcSC = 0xa,    /* board only */
            IbcSRE = 0xb,    /* board only */
            IbcEOSrd = 0xc,
            IbcEOSwrt = 0xd,
            IbcEOScmp = 0xe,
            IbcEOSchar = 0xf,
            IbcPP2 = 0x10,    /* board only */
            IbcTIMING = 0x11,    /* board only */
            IbcDMA = 0x12,    /* board only */
            IbcReadAdjust = 0x13,
            IbcWriteAdjust = 0x14,
            IbcEventQueue = 0x15,    /* board only */
            IbcSPollBit = 0x16,    /* board only */
            IbcSpollBit = 0x16,    /* board only */
            IbcSendLLO = 0x17,    /* board only */
            IbcSPollTime = 0x18,    /* device only */
            IbcPPollTime = 0x19,    /* board only */
            IbcEndBitIsNormal = 0x1a,
            IbcUnAddr = 0x1b,    /* device only */
            IbcHSCableLength = 0x1f,    /* board only */
            IbcIst = 0x20,    /* board only */
            IbcRsv = 0x21,    /* board only */
            IbcLON = 0x22,
            IbcBNA = 0x200    /* device only */
        };
    
        public enum t1_delays
        {
            T1_DELAY_2000ns = 1,
            T1_DELAY_500ns = 2,
            T1_DELAY_350ns = 3
        };
        //    typedef ushort Addr4882_t;
    //    typedef int  ssize_t;
    //    typedef uint  size_t;
        public const ushort NOADDR = 0xffff;
    
        /*  IEEE 488 Function Prototypes  */
        [DllImport("Gpib-32.dll")]
        public static extern int ibask( int ud, int option,  ref int value );
        [DllImport("Gpib-32.dll")]
        public static extern int ibbna( int ud, string board_name );
        [DllImport("Gpib-32.dll")]
        public static extern int ibcac( int ud, int synchronous );
        [DllImport("Gpib-32.dll")]
        public static extern int ibclr( int ud );
        [DllImport("Gpib-32.dll")]
        public static extern int ibcmd( int ud, string cmd, long cnt );
        [DllImport("Gpib-32.dll")]
        public static extern int ibcmda( int ud, string cmd, long cnt );
        [DllImport("Gpib-32.dll")]
        public static extern int ibconfig( int ud, int option, int value );
        [DllImport("Gpib-32.dll")]
        public static extern int ibdev( int board_index, int pad, int sad, int timo, int send_eoi, int eosmode );
        [DllImport("Gpib-32.dll")]
        public static extern int ibdma( int ud, int v );
        [DllImport("Gpib-32.dll")]
        public static extern int ibeot( int ud, int v );
        [DllImport("Gpib-32.dll")]
        public static extern int ibeos( int ud, int v );
        [DllImport("Gpib-32.dll")]
        public static extern int ibfind( string dev );
        [DllImport("Gpib-32.dll")]
        public static extern int ibgts(int ud, int shadow_handshake);
        [DllImport("Gpib-32.dll")]
        public static extern int ibist( int ud, int ist );
        [DllImport("Gpib-32.dll")]
        public static extern int iblines( int ud, short line_status );
        [DllImport("Gpib-32.dll")]
        public static extern int ibln( int ud, int pad, int sad, short found_listener );
        [DllImport("Gpib-32.dll")]
        public static extern int ibloc( int ud );
        [DllImport("Gpib-32.dll")]
        public static extern int ibonl( int ud, int onl );
        [DllImport("Gpib-32.dll")]
        public static extern int ibpad( int ud, int v );
        [DllImport("Gpib-32.dll")]
        public static extern int ibpct( int ud );
        [DllImport("Gpib-32.dll")]
        public static extern int ibppc( int ud, int v );
        [DllImport("Gpib-32.dll")]
        public static extern int ibrd( int ud, StringBuilder buf, int count );
        [DllImport("Gpib-32.dll")]
        public static extern int ibrda( int ud, StringBuilder buf, int count );
        [DllImport("Gpib-32.dll")]
        public static extern int ibrdf( int ud, char file_path );
        [DllImport("Gpib-32.dll")]
        public static extern int ibrpp( int ud, char ppr );
        [DllImport("Gpib-32.dll")]
        public static extern int ibrsc( int ud, int v );
        [DllImport("Gpib-32.dll")]
        public static extern int ibrsp( int ud, StringBuilder spr );
        [DllImport("Gpib-32.dll")]
        public static extern int ibrsv( int ud, int v );
        [DllImport("Gpib-32.dll")]
        public static extern int ibsad( int ud, int v );
        [DllImport("Gpib-32.dll")]
        public static extern int ibsic( int ud );
        [DllImport("Gpib-32.dll")]
        public static extern int ibsre( int ud, int v );
        [DllImport("Gpib-32.dll")]
        public static extern int ibstop( int ud );
        [DllImport("Gpib-32.dll")]
        public static extern int ibtmo( int ud, int v );
        [DllImport("Gpib-32.dll")]
        public static extern int ibtrg( int ud );
        [DllImport("Gpib-32.dll")]
        public static extern int ibwait( int ud, int mask );
        [DllImport("Gpib-32.dll")]
        public static extern int ibwrt( int ud, string buf, int  count );
        [DllImport("Gpib-32.dll")]
        public static extern int ibwrta( int ud, string buf, int  count );
        [DllImport("Gpib-32.dll")]
        public static extern int ibwrtf( int ud, StringBuilder file_path );
    
        [DllImport("Gpib-32.dll")]
        public static extern int gpib_get_globals (out int pibsta, out int piberr, out int pibcnt, out int pibcntl);
    
        /*  IEEE 488.2 Function Prototypes  */
        [DllImport("Gpib-32.dll")]
        public static extern void AllSPoll( int board_desc, ushort[] addressList, ushort[] resultList );
        [DllImport("Gpib-32.dll")]
        public static extern void AllSpoll( int board_desc, ushort[] addressLis, ushort[] resultList );
        [DllImport("Gpib-32.dll")]
        public static extern void DevClear( int board_desc, ushort address );
        [DllImport("Gpib-32.dll")]
        public static extern void DevClearList( int board_desc, ushort[] addressLis );
        [DllImport("Gpib-32.dll")]
        public static extern void EnableLocal( int board_desc, ushort[] addressLis );
        [DllImport("Gpib-32.dll")]
        public static extern void EnableRemote( int board_desc, ushort[] addressLis );
        [DllImport("Gpib-32.dll")]
        public static extern void FindLstn( int board_desc,  ushort[] padList, ushort[] resultList, int maxNumResults );
        [DllImport("Gpib-32.dll")]
        public static extern void FindRQS( int board_desc, ushort[] addressList, out short result );
        [DllImport("Gpib-32.dll")]
        public static extern void PassControl( int board_desc, ushort address );
        [DllImport("Gpib-32.dll")]
        public static extern void PPoll( int board_desc, out short result );
        [DllImport("Gpib-32.dll")]
        public static extern void PPollConfig( int board_desc, ushort address, int dataLine, int lineSense );
        [DllImport("Gpib-32.dll")]
        public static extern void PPollUnconfig( int board_desc, ushort[] addressList );
        [DllImport("Gpib-32.dll")]
        public static extern void RcvRespMsg( int board_desc, char[] buffer, long count, int termination );
        [DllImport("Gpib-32.dll")]
        public static extern void ReadStatusByte( int board_desc, ushort address, out short result );
        [DllImport("Gpib-32.dll")]
        public static extern void Receive( int board_desc, ushort address, char[] buffer, long count, int termination );
        [DllImport("Gpib-32.dll")]
        public static extern void ReceiveSetup( int board_desc, ushort address );
        [DllImport("Gpib-32.dll")]
        public static extern void ResetSys( int board_desc, ushort[] addressList );
        [DllImport("Gpib-32.dll")]
        public static extern void Send( int board_desc, ushort address, char[] buffer,    long count, int eot_mode );
        [DllImport("Gpib-32.dll")]
        public static extern void SendCmds( int board_desc, char[] cmds, long count );
        [DllImport("Gpib-32.dll")]
        public static extern void SendDataBytes( int board_desc, char[] buffer, long count, int eotmode );
        [DllImport("Gpib-32.dll")]
        public static extern void SendIFC( int board_desc );
        [DllImport("Gpib-32.dll")]
        public static extern void SendLLO( int board_desc );
        [DllImport("Gpib-32.dll")]
        public static extern void SendList( int board_desc, ushort[] addressList, char[] buffer, long count, int eotmode );
        [DllImport("Gpib-32.dll")]
        public static extern void SendSetup( int board_desc, ushort[] addressList );
        [DllImport("Gpib-32.dll")]
        public static extern void SetRWLS( int board_desc, ushort[] addressList );
        [DllImport("Gpib-32.dll")]
        public static extern void TestSRQ( int board_desc, out short result );
        [DllImport("Gpib-32.dll")]
        public static extern void TestSys( int board_desc, ushort[] addrlist, short[] resultList );
        [DllImport("Gpib-32.dll")]
        public static extern void Trigger( int board_desc, ushort address );
        [DllImport("Gpib-32.dll")]
        public static extern void TriggerList( int board_desc, ushort[] addressList );
        [DllImport("Gpib-32.dll")]
        public static extern void WaitSRQ( int board_desc, out short result );
    
    }
    工具类
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Threading;
    
    namespace Common.GpibProtocol
    {
       public class GpibHelper 
        {
            #region GPIB读写操作
            private short address = 0;
            private int ibsta, iberr, ibcnt, ibcntl;
    
            private GpibHelper()
            {
    
            }
    
            public GpibHelper(short address)
            {
                this.address = address;
            }
    
            public bool write(string strWrite)
            {
                //Open and intialize an GPIB instrument
                int dev = GPIB.ibdev(0, address, 0, (int)GPIB.gpib_timeout.T1s, 1, 0);
                GPIB.gpib_get_globals(out ibsta, out iberr, out ibcnt, out ibcntl);
                if ((ibsta & (int)GPIB.ibsta_bits.ERR) != 0)
                {
                    //MessageBox.Show("Error in initializing the GPIB instrument.");
                    return false;
                }
    
                //clear the specific GPIB instrument
                GPIB.ibclr(dev);
                GPIB.gpib_get_globals(out ibsta, out iberr, out ibcnt, out ibcntl);
                if ((ibsta & (int)GPIB.ibsta_bits.ERR) != 0)
                {
                    //MessageBox.Show("Error in clearing the GPIB device.");
                    return false;
                }
    
                //Write a string command to a GPIB instrument using the ibwrt() command
                GPIB.ibwrt(dev, strWrite, strWrite.Length);
                GPIB.gpib_get_globals(out ibsta, out iberr, out ibcnt, out ibcntl);
                if ((ibsta & (int)GPIB.ibsta_bits.ERR) != 0)
                {
                    //MessageBox.Show("Error in writing the string command to the GPIB instrument.");
                    return false;
                }
    
                //Offline the GPIB interface card
                GPIB.ibonl(dev, 0);
                GPIB.gpib_get_globals(out ibsta, out iberr, out ibcnt, out ibcntl);
                if ((ibsta & (int)GPIB.ibsta_bits.ERR) != 0)
                {
                    //MessageBox.Show("Error in offline the GPIB interface card.");
                    return false;
                }
                return true;
            }
    
            public bool read(string strWrite, ref string strRead)
            {
                StringBuilder str = new StringBuilder(100);
                //Open and intialize an GPIB instrument
                int dev = GPIB.ibdev(0, address, 0, (int)GPIB.gpib_timeout.T1s, 1, 0);
                GPIB.gpib_get_globals(out ibsta, out iberr, out ibcnt, out ibcntl);
                if ((ibsta & (int)GPIB.ibsta_bits.ERR) != 0)
                {
                    //MessageBox.Show("Error in initializing the GPIB instrument.");
                    return false;
                }
    
                //clear the specific GPIB instrument
                GPIB.ibclr(dev);
                GPIB.gpib_get_globals(out ibsta, out iberr, out ibcnt, out ibcntl);
                if ((ibsta & (int)GPIB.ibsta_bits.ERR) != 0)
                {
                    //MessageBox.Show("Error in clearing the GPIB device.");
                    return false;
                }
    
                //Write a string command to a GPIB instrument using the ibwrt() command
                GPIB.ibwrt(dev, strWrite, strWrite.Length);
                GPIB.gpib_get_globals(out ibsta, out iberr, out ibcnt, out ibcntl);
                if ((ibsta & (int)GPIB.ibsta_bits.ERR) != 0)
                {
                    //MessageBox.Show("Error in writing the string command to the GPIB instrument.");
                    return false;
                }
                Thread.Sleep(500);
                //Read the response string from the GPIB instrument using the ibrd() command
                GPIB.ibrd(dev, str, 100);
                strRead = str.ToString();
                GPIB.gpib_get_globals(out ibsta, out iberr, out ibcnt, out ibcntl);
                if ((ibsta & (int)GPIB.ibsta_bits.ERR) != 0)
                {
                    //MessageBox.Show("Error in reading the response string from the GPIB instrument.");
                    return false;
                }
    
                //Offline the GPIB interface card
                GPIB.ibonl(dev, 0);
                GPIB.gpib_get_globals(out ibsta, out iberr, out ibcnt, out ibcntl);
                if ((ibsta & (int)GPIB.ibsta_bits.ERR) != 0)
                {
                    //MessageBox.Show("Error in offline the GPIB interface card.");
                    return false;
                }
                return true;
            }
    
            #endregion
    
    
        }
    }
    GpibHelper

    2.PCI操作类

    using System.Runtime.InteropServices;
    using System;
    
    namespace Common.PciProtocol
    {
        public delegate void CallbackDelegate();
        public class DASK
        {
            #region  PCI Card Type
            //ADLink PCI Card Type
            public const ushort PCI_6208V = 1;
            public const ushort PCI_6208A = 2;
            public const ushort PCI_6308V = 3;
            public const ushort PCI_6308A = 4;
            public const ushort PCI_7200 = 5;
            public const ushort PCI_7230 = 6;
            public const ushort PCI_7233 = 7;
            public const ushort PCI_7234 = 8;
            public const ushort PCI_7248 = 9;
            public const ushort PCI_7249 = 10;
            public const ushort PCI_7250 = 11;
            public const ushort PCI_7252 = 12;
            public const ushort PCI_7296 = 13;
            public const ushort PCI_7300A_RevA = 14;
            public const ushort PCI_7300A_RevB = 15;
            public const ushort PCI_7432 = 16;
            public const ushort PCI_7433 = 17;
            public const ushort PCI_7434 = 18;
            public const ushort PCI_8554 = 19;
            public const ushort PCI_9111DG = 20;
            public const ushort PCI_9111HR = 21;
            public const ushort PCI_9112 = 22;
            public const ushort PCI_9113 = 23;
            public const ushort PCI_9114DG = 24;
            public const ushort PCI_9114HG = 25;
            public const ushort PCI_9118DG = 26;
            public const ushort PCI_9118HG = 27;
            public const ushort PCI_9118HR = 28;
            public const ushort PCI_9810 = 29;
            public const ushort PCI_9812 = 30;
            public const ushort PCI_7396 = 31;
            public const ushort PCI_9116 = 32;
            public const ushort PCI_7256 = 33;
            public const ushort PCI_7258 = 34;
            public const ushort PCI_7260 = 35;
            public const ushort PCI_7452 = 36;
            public const ushort PCI_7442 = 37;
    
            public const ushort MAX_CARD = 32;
     #endregion
            #region Error Number
            //Error Number
            public const short NoError = 0;
            public const short ErrorUnknownCardType = -1;
            public const short ErrorInvalidCardNumber = -2;
            public const short ErrorTooManyCardRegistered = -3;
            public const short ErrorCardNotRegistered = -4;
            public const short ErrorFuncNotSupport = -5;
            public const short ErrorInvalidIoChannel = -6;
            public const short ErrorInvalidAdRange = -7;
            public const short ErrorContIoNotAllowed = -8;
            public const short ErrorDiffRangeNotSupport = -9;
            public const short ErrorLastChannelNotZero = -10;
            public const short ErrorChannelNotDescending = -11;
            public const short ErrorChannelNotAscending = -12;
            public const short ErrorOpenDriverFailed = -13;
            public const short ErrorOpenEventFailed = -14;
            public const short ErrorTransferCountTooLarge = -15;
            public const short ErrorNotDoubleBufferMode = -16;
            public const short ErrorInvalidSampleRate = -17;
            public const short ErrorInvalidCounterMode = -18;
            public const short ErrorInvalidCounter = -19;
            public const short ErrorInvalidCounterState = -20;
            public const short ErrorInvalidBinBcdParam = -21;
            public const short ErrorBadCardType = -22;
            public const short ErrorInvalidDaRefVoltage = -23;
            public const short ErrorAdTimeOut = -24;
            public const short ErrorNoAsyncAI = -25;
            public const short ErrorNoAsyncAO = -26;
            public const short ErrorNoAsyncDI = -27;
            public const short ErrorNoAsyncDO = -28;
            public const short ErrorNotInputPort = -29;
            public const short ErrorNotOutputPort = -30;
            public const short ErrorInvalidDioPort = -31;
            public const short ErrorInvalidDioLine = -32;
            public const short ErrorContIoActive = -33;
            public const short ErrorDblBufModeNotAllowed = -34;
            public const short ErrorConfigFailed = -35;
            public const short ErrorInvalidPortDirection = -36;
            public const short ErrorBeginThreadError = -37;
            public const short ErrorInvalidPortWidth = -38;
            public const short ErrorInvalidCtrSource = -39;
            public const short ErrorOpenFile = -40;
            public const short ErrorAllocateMemory = -41;
            public const short ErrorDaVoltageOutOfRange = -42;
            public const short ErrorDaExtRefNotAllowed = -43;
            public const short ErrorDIODataWidthError = -44;
            public const short ErrorTaskCodeError = -45;
            public const short ErrortriggercountError = -46;
            public const short ErrorInvalidTriggerMode = -47;
            public const short ErrorInvalidTriggerType = -48;
            public const short ErrorInvalidCounterValue = -50;
            public const short ErrorInvalidEventHandle = -60;
            public const short ErrorNoMessageAvailable = -61;
            public const short ErrorEventMessgaeNotAdded = -62;
            #endregion
            #region Error number for driver API
            //Error number for driver API 
            public const short ErrorConfigIoctl = -201;
            public const short ErrorAsyncSetIoctl = -202;
            public const short ErrorDBSetIoctl = -203;
            public const short ErrorDBHalfReadyIoctl = -204;
            public const short ErrorContOPIoctl = -205;
            public const short ErrorContStatusIoctl = -206;
            public const short ErrorPIOIoctl = -207;
            public const short ErrorDIntSetIoctl = -208;
            public const short ErrorWaitEvtIoctl = -209;
            public const short ErrorOpenEvtIoctl = -210;
            public const short ErrorCOSIntSetIoctl = -211;
            public const short ErrorMemMapIoctl = -212;
            public const short ErrorMemUMapSetIoctl = -213;
            public const short ErrorCTRIoctl = -214;
            public const short ErrorGetResIoctl = -215;
     #endregion
            #region  Synchronous Mode
            //Synchronous Mode
            public const ushort SYNCH_OP = 1;
            public const ushort ASYNCH_OP = 2;
            #endregion
            #region AD Range
    
            //AD Range
            public const ushort AD_B_10_V = 1;
            public const ushort AD_B_5_V = 2;
            public const ushort AD_B_2_5_V = 3;
            public const ushort AD_B_1_25_V = 4;
            public const ushort AD_B_0_625_V = 5;
            public const ushort AD_B_0_3125_V = 6;
            public const ushort AD_B_0_5_V = 7;
            public const ushort AD_B_0_05_V = 8;
            public const ushort AD_B_0_005_V = 9;
            public const ushort AD_B_1_V = 10;
            public const ushort AD_B_0_1_V = 11;
            public const ushort AD_B_0_01_V = 12;
            public const ushort AD_B_0_001_V = 13;
            public const ushort AD_U_20_V = 14;
            public const ushort AD_U_10_V = 15;
            public const ushort AD_U_5_V = 16;
            public const ushort AD_U_2_5_V = 17;
            public const ushort AD_U_1_25_V = 18;
            public const ushort AD_U_1_V = 19;
            public const ushort AD_U_0_1_V = 20;
            public const ushort AD_U_0_01_V = 21;
            public const ushort AD_U_0_001_V = 22;
    #endregion
            #region Clock Mode
            //Clock Mode
            public const ushort TRIG_SOFTWARE = 0;
            public const ushort TRIG_INT_PACER = 1;
            public const ushort TRIG_EXT_STROBE = 2;
            public const ushort TRIG_HANDSHAKE = 3;
            public const ushort TRIG_CLK_10MHZ = 4; //PCI-7300A
            public const ushort TRIG_CLK_20MHZ = 5; //PCI-7300A
            public const ushort TRIG_DO_CLK_TIMER_ACK = 6; //PCI-7300A Rev. B
            public const ushort TRIG_DO_CLK_10M_ACK = 7; //PCI-7300A Rev. B
            public const ushort TRIG_DO_CLK_20M_ACK = 8; //PCI-7300A Rev. B
            //Virtual Sampling Rate for using external clock as the clock source
            public const double CLKSRC_EXT_SampRate = 10000;
     #endregion
            #region Constants for PCI-6208A/PCI-6308A/PCI-6308V
    
            //-------- Constants for PCI-6208A/PCI-6308A/PCI-6308V -------------------
            //Output Mode
            public const ushort P6208_CURRENT_0_20MA = 0;
            public const ushort P6208_CURRENT_4_20MA = 3;
            public const ushort P6208_CURRENT_5_25MA = 1;
            public const ushort P6308_CURRENT_0_20MA = 0;
            public const ushort P6308_CURRENT_4_20MA = 3;
            public const ushort P6308_CURRENT_5_25MA = 1;
            //AO Setting
            public const ushort P6308V_AO_CH0_3 = 0;
            public const ushort P6308V_AO_CH4_7 = 1;
            public const ushort P6308V_AO_UNIPOLAR = 0;
            public const ushort P6308V_AO_BIPOLAR = 1;
            #endregion
            #region  Constants for PCI-7200
            //-------- Constants for PCI-7200 --------------------
            //InputMode
            public const ushort DI_WAITING = 0x02;
            public const ushort DI_NOWAITING = 0x00;
    
            public const ushort DI_TRIG_RISING = 0x04;
            public const ushort DI_TRIG_FALLING = 0x00;
    
            public const ushort IREQ_RISING = 0x08;
            public const ushort IREQ_FALLING = 0x00;
    
            //Output Mode
            public const ushort OREQ_ENABLE = 0x10;
            public const ushort OREQ_DISABLE = 0x00;
    
            public const ushort OTRIG_HIGH = 0x20;
            public const ushort OTRIG_LOW = 0x00;
    #endregion
            #region Constants for PCI-7248/7296/7396/7442
    
            //-------- Constants for PCI-7248/7296/7396/7442 ---------------
            //DIO Port Direction
            public const ushort INPUT_PORT = 1;
            public const ushort OUTPUT_PORT = 2;
            //DIO Line Direction
            public const ushort INPUT_LINE = 1;
            public const ushort OUTPUT_LINE = 2;
    
            //Channel & Port
            public const ushort Channel_P1A = 0;
            public const ushort Channel_P1B = 1;
            public const ushort Channel_P1C = 2;
            public const ushort Channel_P1CL = 3;
            public const ushort Channel_P1CH = 4;
            public const ushort Channel_P1AE = 10;
            public const ushort Channel_P1BE = 11;
            public const ushort Channel_P1CE = 12;
            public const ushort Channel_P2A = 5;
            public const ushort Channel_P2B = 6;
            public const ushort Channel_P2C = 7;
            public const ushort Channel_P2CL = 8;
            public const ushort Channel_P2CH = 9;
            public const ushort Channel_P2AE = 15;
            public const ushort Channel_P2BE = 16;
            public const ushort Channel_P2CE = 17;
            public const ushort Channel_P3A = 10;
            public const ushort Channel_P3B = 11;
            public const ushort Channel_P3C = 12;
            public const ushort Channel_P3CL = 13;
            public const ushort Channel_P3CH = 14;
            public const ushort Channel_P4A = 15;
            public const ushort Channel_P4B = 16;
            public const ushort Channel_P4C = 17;
            public const ushort Channel_P4CL = 18;
            public const ushort Channel_P4CH = 19;
            public const ushort Channel_P5A = 20;
            public const ushort Channel_P5B = 21;
            public const ushort Channel_P5C = 22;
            public const ushort Channel_P5CL = 23;
            public const ushort Channel_P5CH = 24;
            public const ushort Channel_P6A = 25;
            public const ushort Channel_P6B = 26;
            public const ushort Channel_P6C = 27;
            public const ushort Channel_P6CL = 28;
            public const ushort Channel_P6CH = 29;
            //the following are used for PCI7396
            public const ushort Channel_P1 = 30;
            public const ushort Channel_P2 = 31;
            public const ushort Channel_P3 = 32;
            public const ushort Channel_P4 = 33;
            public const ushort Channel_P1E = 34; //only used by DIO_PortConfig function
            public const ushort Channel_P2E = 35; //only used by DIO_PortConfig function
            public const ushort Channel_P3E = 36; //only used by DIO_PortConfig function
            public const ushort Channel_P4E = 37; //only used by DIO_PortConfig function
            //7442
            public const ushort P7442_CH0 = 0;
            public const ushort P7442_CH1 = 1;
            public const ushort P7442_TTL0 = 2;
            public const ushort P7442_TTL1 = 3;
            //-------- Constants for PCI-7300A -------------------
            //Wait Status
            public const ushort P7300_WAIT_NO = 0;
            public const ushort P7300_WAIT_TRG = 1;
            public const ushort P7300_WAIT_FIFO = 2;
            public const ushort P7300_WAIT_BOTH = 3;
    
            //Terminator control
            public const ushort P7300_TERM_OFF = 0;
            public const ushort P7300_TERM_ON = 1;
    
            //DI control signals polarity for PCI-7300A Rev. B
            public const ushort P7300_DIREQ_POS = 0x00000000;
            public const ushort P7300_DIREQ_NEG = 0x00000001;
            public const ushort P7300_DIACK_POS = 0x00000000;
            public const ushort P7300_DIACK_NEG = 0x00000002;
            public const ushort P7300_DITRIG_POS = 0x00000000;
            public const ushort P7300_DITRIG_NEG = 0x00000004;
    
            //DO control signals polarity for PCI-7300A Rev. B
            public const ushort P7300_DOREQ_POS = 0x00000000;
            public const ushort P7300_DOREQ_NEG = 0x00000008;
            public const ushort P7300_DOACK_POS = 0x00000000;
            public const ushort P7300_DOACK_NEG = 0x00000010;
            public const ushort P7300_DOTRIG_POS = 0x00000000;
            public const ushort P7300_DOTRIG_NEG = 0x00000020;
            //-------- Constants for PCI-7432/7433/7434 ---------------
            public const ushort PORT_DI_LOW = 0;
            public const ushort PORT_DI_HIGH = 1;
            public const ushort PORT_DO_LOW = 0;
            public const ushort PORT_DO_HIGH = 1;
            public const ushort P7432R_DO_LED = 1;
            public const ushort P7433R_DO_LED = 0;
            public const ushort P7434R_DO_LED = 2;
            public const ushort P7432R_DI_SLOT = 1;
            public const ushort P7433R_DI_SLOT = 2;
            public const ushort P7434R_DI_SLOT = 0;
            //-- Dual-Interrupt Source control for PCI-7248/96 & 7432/33 & 7230 & 8554 & 7396 &7256 &7260 ---
            public const short INT1_DISABLE = -1; //INT1 Disabled
            public const short INT1_COS = 0; //INT1 COS : only available for PCI-7396, PCI-7256, PCI-7260
            public const short INT1_FP1C0 = 1; //INT1 by Falling edge of P1C0 : only available for PCI7248/96/7396
    
            public const short INT1_RP1C0_FP1C3 = 2;
                               //INT1 by P1C0 Rising or P1C3 Falling : only available for PCI7248/96/7396
    
            public const short INT1_EVENT_COUNTER = 3;
                               //INT1 by Event Counter down to zero : only available for PCI7248/96/7396
    
            public const short INT1_EXT_SIGNAL = 1; //INT1 by external signal : only available for PCI7432/7433/7230/8554
            public const short INT1_COUT12 = 1; //INT1 COUT12 : only available for PCI8554
            public const short INT1_CH0 = 1; //INT1 CH0 : only available for PCI7256, PCI7260
            public const short INT1_COS0 = 1; //INT1 COS0 : only available for PCI-7452/PCI-7442
            public const short INT1_COS1 = 2; //INT1 COS1 : only available for PCI-7452/PCI-7442
            public const short INT1_COS2 = 4; //INT1 COS2 : only available for PCI-7452/PCI-7442
            public const short INT1_COS3 = 8; //INT1 COS3 : only available for PCI-7452/PCI-7442
            public const short INT2_DISABLE = -1; //INT2 Disabled
            public const short INT2_COS = 0; //INT2 COS : only available for PCI-7396
            public const short INT2_FP2C0 = 1; //INT2 by Falling edge of P2C0 : only available for PCI7248/96/7396
    
            public const short INT2_RP2C0_FP2C3 = 2;
                               //INT2 by P2C0 Rising or P2C3 Falling : only available for PCI7248/96/7396
    
            public const short INT2_TIMER_COUNTER = 3;
                               //INT2 by Timer Counter down to zero : only available for PCI7248/96/7396
    
            public const short INT2_EXT_SIGNAL = 1; //INT2 by external signal : only available for PCI7432/7433/7230/8554
            public const short INT2_CH1 = 2; //INT2 CH1 : only available for PCI7256, PCI7260
            public const short INT2_WDT = 4; //INT2 by WDT
    
            public const ushort ManualResetIEvt = 0x4000; //interrupt event is manually reset by user
            public const ushort WDT_OVRFLOW_SAFETYOUT = 0x8000; // enable safteyout while WDT overflow
    #endregion
            #region Constants for PCI-8554
            //-------- Constants for PCI-8554 --------------------
            //Clock Source of Cunter N
            public const ushort ECKN = 0;
            public const ushort COUTN_1 = 1;
            public const ushort CK1 = 2;
            public const ushort COUT10 = 3;
    
            //Clock Source of CK1
            public const ushort CK1_C8M = 0;
            public const ushort CK1_COUT11 = 1;
    
            //Debounce Clock
            public const ushort DBCLK_COUT11 = 0;
            public const ushort DBCLK_2MHZ = 1;
     #endregion
            #region  Constants for PCI-9111
    
            //-------- Constants for PCI-9111 --------------------
            //Dual Interrupt Mode
            public const ushort P9111_INT1_EOC = 0; //Ending of AD conversion
            public const ushort P9111_INT1_FIFO_HF = 1; //FIFO Half Full
            public const ushort P9111_INT2_PACER = 0; //Every Timer tick
            public const ushort P9111_INT2_EXT_TRG = 1; //ExtTrig High->Low
    
            //Channel Count
            public const ushort P9111_CHANNEL_DO = 0;
            public const ushort P9111_CHANNEL_EDO = 1;
            public const ushort P9111_CHANNEL_DI = 0;
            public const ushort P9111_CHANNEL_EDI = 1;
    
            //EDO function
            public const ushort P9111_EDO_INPUT = 1; //EDO port set as Input port
            public const ushort P9111_EDO_OUT_EDO = 2; //EDO port set as Output port
            public const ushort P9111_EDO_OUT_CHN = 3; //EDO port set as channel number ouput port
    
            //Trigger Mode
            public const ushort P9111_TRGMOD_SOFT = 0x00; //Software Trigger Mode
            public const ushort P9111_TRGMOD_PRE = 0x01; //Pre-Trigger Mode
            public const ushort P9111_TRGMOD_POST = 0x02; //Post Trigger Mode
    
            //AO Setting
            public const ushort P9111_AO_UNIPOLAR = 0;
            public const ushort P9111_AO_BIPOLAR = 1;
    #endregion
            #region Constants for PCI-9118
            //-------- Constants for PCI-9118 --------------------
            public const ushort P9118_AI_BiPolar = 0x00;
            public const ushort P9118_AI_UniPolar = 0x01;
    
            public const ushort P9118_AI_SingEnded = 0x00;
            public const ushort P9118_AI_Differential = 0x02;
    
            public const ushort P9118_AI_ExtG = 0x04;
    
            public const ushort P9118_AI_ExtTrig = 0x08;
    
            public const ushort P9118_AI_DtrgNegative = 0x00;
            public const ushort P9118_AI_DtrgPositive = 0x10;
    
            public const ushort P9118_AI_EtrgNegative = 0x00;
            public const ushort P9118_AI_EtrgPositive = 0x20;
    
            public const ushort P9118_AI_BurstModeEn = 0x40;
            public const ushort P9118_AI_SampleHold = 0x80;
            public const ushort P9118_AI_PostTrgEn = 0x100;
            public const ushort P9118_AI_AboutTrgEn = 0x200;
     #endregion
            #region Constants for PCI-9116
            //-------- Constants for PCI-9116 --------------------
            public const ushort P9116_AI_LocalGND = 0x00;
            public const ushort P9116_AI_UserCMMD = 0x01;
            public const ushort P9116_AI_SingEnded = 0x00;
            public const ushort P9116_AI_Differential = 0x02;
            public const ushort P9116_AI_BiPolar = 0x00;
            public const ushort P9116_AI_UniPolar = 0x04;
    
            public const ushort P9116_TRGMOD_SOFT = 0x00; //Software Trigger Mode
            public const ushort P9116_TRGMOD_POST = 0x10; //Post Trigger Mode
            public const ushort P9116_TRGMOD_DELAY = 0x20; //Delay Trigger Mode
            public const ushort P9116_TRGMOD_PRE = 0x30; //Pre-Trigger Mode
            public const ushort P9116_TRGMOD_MIDL = 0x40; //Middle Trigger Mode
            public const ushort P9116_AI_TrgPositive = 0x00;
            public const ushort P9116_AI_TrgNegative = 0x80;
            public const ushort P9116_AI_ExtTimeBase = 0x100;
            public const ushort P9116_AI_IntTimeBase = 0x000;
            public const ushort P9116_AI_DlyInSamples = 0x200;
            public const ushort P9116_AI_DlyInTimebase = 0x000;
            public const ushort P9116_AI_ReTrigEn = 0x400;
            public const ushort P9116_AI_MCounterEn = 0x800;
            public const ushort P9116_AI_SoftPolling = 0x0000;
            public const ushort P9116_AI_INT = 0x1000;
            public const ushort P9116_AI_DMA = 0x2000;
            #endregion
    
            //-------- Constants for PCI-9812 --------------------
            //Trigger Mode
            public const ushort P9812_TRGMOD_SOFT = 0x00; //Software Trigger Mode
            public const ushort P9812_TRGMOD_POST = 0x01; //Post Trigger Mode
            public const ushort P9812_TRGMOD_PRE = 0x02; //Pre-Trigger Mode
            public const ushort P9812_TRGMOD_DELAY = 0x03; //Delay Trigger Mode
            public const ushort P9812_TRGMOD_MIDL = 0x04; //Middle Trigger Mode
    
            public const ushort P9812_AIEvent_Manual = 0x08; //Middle Trigger Mode
    
            //Trigger Source
            public const ushort P9812_TRGSRC_CH0 = 0x00; //trigger source --CH0
            public const ushort P9812_TRGSRC_CH1 = 0x08; //trigger source --CH1
            public const ushort P9812_TRGSRC_CH2 = 0x10; //trigger source --CH2
            public const ushort P9812_TRGSRC_CH3 = 0x18; //trigger source --CH3
            public const ushort P9812_TRGSRC_EXT_DIG = 0x20; //External Digital Trigger
    
            //Trigger Polarity
            public const ushort P9812_TRGSLP_POS = 0x00; //Positive slope trigger
            public const ushort P9812_TRGSLP_NEG = 0x40; //Negative slope trigger
    
            //Frequency Selection
            public const ushort P9812_AD2_GT_PCI = 0x80; //Freq. of A/D clock > PCI clock freq.
            public const ushort P9812_AD2_LT_PCI = 0x00; //Freq. of A/D clock < PCI clock freq.
    
            //Clock Source
            public const ushort P9812_CLKSRC_INT = 0x000; //Internal clock
            public const ushort P9812_CLKSRC_EXT_SIN = 0x100; //External SIN wave clock
            public const ushort P9812_CLKSRC_EXT_DIG = 0x200; //External Square wave clock
    
            //EMG shdn ctrl code
            public const ushort EMGSHDN_OFF = 0; //off
            public const ushort EMGSHDN_ON = 1; //on
            public const ushort EMGSHDN_RECOVERY = 2; //recovery
    
            //Hot Reset Hold ctrl code
            public const ushort HRH_OFF = 0; //off
            public const ushort HRH_ON = 1; //on
    
            //-------- Timer/Counter -----------------------------
            //Counter Mode (8254)
            public const ushort TOGGLE_OUTPUT = 0; //Toggle output from low to high on terminal count
            public const ushort PROG_ONE_SHOT = 1; //Programmable one-shot
            public const ushort RATE_GENERATOR = 2; //Rate generator
            public const ushort SQ_WAVE_RATE_GENERATOR = 3; //Square wave rate generator
            public const ushort SOFT_TRIG = 4; //Software-triggered strobe
            public const ushort HARD_TRIG = 5; //Hardware-triggered strobe
    
            //General Purpose Timer/Counter
            //Counter Mode
            public const ushort General_Counter = 0x00; //general counter
            public const ushort Pulse_Generation = 0x01; //pulse generation
            //GPTC clock source
            public const ushort GPTC_CLKSRC_EXT = 0x08;
            public const ushort GPTC_CLKSRC_INT = 0x00;
            public const ushort GPTC_GATESRC_EXT = 0x10;
            public const ushort GPTC_GATESRC_INT = 0x00;
            public const ushort GPTC_UPDOWN_SELECT_EXT = 0x20;
            public const ushort GPTC_UPDOWN_SELECT_SOFT = 0x00;
            public const ushort GPTC_UP_CTR = 0x40;
            public const ushort GPTC_DOWN_CTR = 0x00;
            public const ushort GPTC_ENABLE = 0x80;
            public const ushort GPTC_DISABLE = 0x00;
    
            //Watchdog Timer
            //Counter action
            public const ushort WDT_DISARM = 0;
            public const ushort WDT_ARM = 1;
            public const ushort WDT_RESTART = 2;
    
            //Pattern ID
            public const ushort INIT_PTN = 0;
            public const ushort EMGSHDN_PTN = 1;
    
            //16-bit binary or 4-decade BCD counter
            public const ushort BIN = 0;
            public const ushort BCD = 1;
    
            //Pattern ID for 7442
            public const ushort INIT_PTN_CH0 = 0;
            public const ushort INIT_PTN_CH1 = 1;
            public const ushort SAFTOUT_PTN_CH0 = 4;
            public const ushort SAFTOUT_PTN_CH1 = 5;
    
            //DAQ Event type for the event message  
            public const ushort AIEnd = 0;
            public const ushort DIEnd = 0;
            public const ushort DOEnd = 0;
            public const ushort DBEvent = 1;
    
            public const ushort RegBySlot = 0x8000;
    
            /*------------------------------------------------------------------
            ** PCIS-DASK Function prototype
            ------------------------------------------------------------------*/
    
            [DllImport("PCI-Dask.dll")]
            public static extern short Register_Card(ushort CardType, ushort card_num);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short Release_Card(ushort CardNumber);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short GetActualRate(ushort CardNumber, double fSampleRate, out double fActualRate);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short EMGShutDownControl(ushort CardNumber, byte ctrl);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short EMGShutDownStatus(ushort CardNumber, out byte sts);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short HotResetHoldControl(ushort wCardNumber, byte enable);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short HotResetHoldStatus(ushort wCardNumber, out byte sts);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short GetInitPattern(ushort CardNumber, byte patID, out uint pattern);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short SetInitPattern(ushort wCardNumber, byte patID, uint pattern);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short IdentifyLED_Control(ushort CardNumber, byte ctrl);
    
            /*---------------------------------------------------------------------------*/
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_9111_Config(ushort CardNumber, ushort TrigSource, ushort TrgMode, ushort TraceCnt);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_9112_Config(ushort CardNumber, ushort TrigSource);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_9113_Config(ushort CardNumber, ushort TrigSource);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_9114_Config(ushort CardNumber, ushort TrigSource);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_9116_Config(ushort CardNumber, ushort ConfigCtrl, ushort TrigCtrl, ushort PostCnt,
                                                      ushort MCnt, ushort ReTrgCnt);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_9118_Config(ushort CardNumber, ushort ModeCtrl, ushort FunCtrl, ushort BurstCnt,
                                                      ushort PostCnt);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_9812_Config(ushort CardNumber, ushort TrgMode, ushort TrgSrc, ushort TrgPol,
                                                      ushort ClkSel, ushort TrgLevel, ushort PostCnt);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_9812_SetDiv(ushort wCardNumber, uint PacerVal);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_9114_PreTrigConfig(ushort CardNumber, ushort PreTrgEn, ushort TraceCnt);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_9116_CounterInterval(ushort wCardNumber, uint ScanIntrv, uint SampIntrv);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_InitialMemoryAllocated(ushort CardNumber, out uint MemSize);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_ReadChannel(ushort CardNumber, ushort Channel, ushort AdRange, out ushort Value);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_VReadChannel(ushort CardNumber, ushort Channel, ushort AdRange, out double voltage);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_VoltScale(ushort CardNumber, ushort AdRange, ushort reading, out double voltage);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_ContReadChannel(ushort CardNumber, ushort Channel, ushort AdRange,
                                                          ushort[] Buffer, uint ReadCount, double SampleRate,
                                                          ushort SyncMode);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_ContReadMultiChannels(ushort CardNumber, ushort NumChans, ushort[] Chans,
                                                                ushort[] AdRanges, ushort[] Buffer, uint ReadCount,
                                                                double SampleRate, ushort SyncMode);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_ContScanChannels(ushort CardNumber, ushort Channel, ushort AdRange,
                                                           ushort[] Buffer, uint ReadCount, double SampleRate,
                                                           ushort SyncMode);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_ContReadChannelToFile(ushort CardNumber, ushort Channel, ushort AdRange,
                                                                string FileName, uint ReadCount, double SampleRate,
                                                                ushort SyncMode);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_ContReadMultiChannelsToFile(ushort CardNumber, ushort NumChans, ushort[] Chans,
                                                                      ushort[] AdRanges, string[] FileName, uint ReadCount,
                                                                      double SampleRate, ushort SyncMode);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_ContScanChannelsToFile(ushort CardNumber, ushort Channel, ushort AdRange,
                                                                 string FileName, uint ReadCount, double SampleRate,
                                                                 ushort SyncMode);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_ContStatus(ushort CardNumber, out ushort Status);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_ContVScale(ushort wCardNumber, ushort adRange, ushort[] readingArray,
                                                     double[] voltageArray, int count);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_AsyncCheck(ushort CardNumber, out byte Stopped, out uint AccessCnt);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_AsyncClear(ushort CardNumber, out uint AccessCnt);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_AsyncDblBufferHalfReady(ushort CardNumber, out byte HalfReady, out byte StopFlag);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_AsyncDblBufferMode(ushort CardNumber, bool Enable);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_AsyncDblBufferTransfer(ushort CardNumber, ushort[] Buffer);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_AsyncDblBufferOverrun(ushort CardNumber, ushort op, out ushort overrunFlag);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_EventCallBack(ushort CardNumber, ushort mode, ushort EventType,
                                                        MulticastDelegate callbackAddr);
    
            /*---------------------------------------------------------------------------*/
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AO_6208A_Config(ushort CardNumber, ushort V2AMode);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AO_6308A_Config(ushort CardNumber, ushort V2AMode);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AO_6308V_Config(ushort wCardNumber, ushort Channel, ushort wOutputPolarity,
                                                       double refVoltage);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AO_9111_Config(ushort CardNumber, ushort OutputPolarity);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AO_9112_Config(ushort CardNumber, ushort Channel, double refVoltage);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AO_WriteChannel(ushort CardNumber, ushort Channel, short Value);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AO_VWriteChannel(ushort CardNumber, ushort Channel, double Voltage);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AO_VoltScale(ushort CardNumber, ushort Channel, double Voltage, out short binValue);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AO_SimuWriteChannel(ushort wCardNumber, ushort wGroup, short[] pwBuffer);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AO_SimuVWriteChannel(ushort wCardNumber, ushort wGroup, double[] VBuffer);
    
            /*---------------------------------------------------------------------------*/
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_7200_Config(ushort CardNumber, ushort TrigSource, ushort ExtTrigEn, ushort TrigPol,
                                                      ushort I_REQ_Pol);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_7300A_Config(ushort CardNumber, ushort PortWidth, ushort TrigSource,
                                                       ushort WaitStatus, ushort Terminator, ushort I_REQ_Pol,
                                                       bool clear_fifo, bool disable_di);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_7300B_Config(ushort CardNumber, ushort PortWidth, ushort TrigSource,
                                                       ushort WaitStatus, ushort Terminator, ushort I_Cntrl_Pol,
                                                       bool clear_fifo, bool disable_di);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_InitialMemoryAllocated(ushort CardNumber, out uint DmaSize);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_ReadLine(ushort CardNumber, ushort Port, ushort Line, out ushort State);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_ReadPort(ushort CardNumber, ushort Port, out uint Value);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_ContReadPort(ushort CardNumber, ushort Port, byte[] Buffer,
                                                       uint ReadCount, double SampleRate, ushort SyncMode);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_ContReadPort(ushort CardNumber, ushort Port, ushort[] Buffer,
                                                       uint ReadCount, double SampleRate, ushort SyncMode);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_ContReadPort(ushort CardNumber, ushort Port, uint[] Buffer,
                                                       uint ReadCount, double SampleRate, ushort SyncMode);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_ContReadPortToFile(ushort CardNumber, ushort Port, string FileName,
                                                             uint ReadCount, double SampleRate, ushort SyncMode);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_ContStatus(ushort CardNumber, out ushort Status);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_AsyncCheck(ushort CardNumber, out byte Stopped, out uint AccessCnt);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_AsyncClear(ushort CardNumber, out uint AccessCnt);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_AsyncDblBufferHalfReady(ushort CardNumber, out byte HalfReady);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_AsyncDblBufferMode(ushort CardNumber, bool Enable);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_AsyncDblBufferTransfer(ushort CardNumber, byte[] Buffer);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_AsyncDblBufferTransfer(ushort CardNumber, short[] Buffer);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_AsyncDblBufferTransfer(ushort CardNumber, uint[] Buffer);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_ContMultiBufferSetup(ushort wCardNumber, byte[] pwBuffer, uint dwReadCount,
                                                               out ushort BufferId);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_ContMultiBufferSetup(ushort wCardNumber, short[] pwBuffer, uint dwReadCount,
                                                               out ushort BufferId);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_ContMultiBufferSetup(ushort wCardNumber, uint[] pwBuffer, uint dwReadCount,
                                                               out ushort BufferId);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_ContMultiBufferStart(ushort wCardNumber, ushort wPort, double fSampleRate);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_AsyncMultiBufferNextReady(ushort CardNumber, out byte bNextReady,
                                                                    out ushort wBufferId);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_AsyncDblBufferOverrun(ushort CardNumber, ushort op, out ushort overrunFlag);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_EventCallBack(ushort CardNumber, short mode, short EventType,
                                                        MulticastDelegate callbackAddr);
    
            /*---------------------------------------------------------------------------*/
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_7200_Config(ushort CardNumber, ushort TrigSource, ushort OutReqEn,
                                                      ushort OutTrigSig);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_7300A_Config(ushort CardNumber, ushort PortWidth, ushort TrigSource,
                                                       ushort WaitStatus, ushort Terminator, ushort O_REQ_Pol);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_7300B_Config(ushort CardNumber, ushort PortWidth, ushort TrigSource,
                                                       ushort WaitStatus, ushort Terminator, ushort O_Cntrl_Pol,
                                                       uint FifoThreshold);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_InitialMemoryAllocated(ushort CardNumber, out uint MemSize);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_WriteLine(ushort CardNumber, ushort Port, ushort Line, ushort Value);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_WritePort(ushort CardNumber, byte Port, uint Value);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_WritePort(ushort CardNumber, ushort Port, uint Value);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_WritePort(ushort CardNumber, uint Port, uint Value);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_WriteExtTrigLine(ushort CardNumber, ushort Value);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_ReadLine(ushort CardNumber, ushort Port, ushort Line, out ushort Value);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_ReadPort(ushort CardNumber, ushort Port, out uint Value);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_ContWritePort(ushort CardNumber, ushort Port, byte[] Buffer,
                                                        uint WriteCount, ushort Iterations, double SampleRate,
                                                        ushort SyncMode);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_ContWritePort(ushort CardNumber, ushort Port, ushort[] Buffer,
                                                        uint WriteCount, ushort Iterations, double SampleRate,
                                                        ushort SyncMode);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_ContWritePort(ushort CardNumber, ushort Port, uint[] Buffer,
                                                        uint WriteCount, ushort Iterations, double SampleRate,
                                                        ushort SyncMode);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_PGStart(ushort CardNumber, byte[] Buffer, uint WriteCount, double SampleRate);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_PGStart(ushort CardNumber, short[] Buffer, uint WriteCount, double SampleRate);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_PGStart(ushort CardNumber, uint[] Buffer, uint WriteCount, double SampleRate);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_PGStop(ushort CardNumber);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_ContStatus(ushort CardNumber, out ushort Status);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_AsyncCheck(ushort CardNumber, out byte Stopped, out uint AccessCnt);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_AsyncClear(ushort CardNumber, out uint AccessCnt);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short EDO_9111_Config(ushort CardNumber, ushort EDO_Fun);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_ContMultiBufferSetup(ushort CardNumber, byte[] pwBuffer, uint dwWriteCount,
                                                               out ushort BufferId);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_ContMultiBufferSetup(ushort CardNumber, short[] pwBuffer, uint dwWriteCount,
                                                               out ushort BufferId);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_ContMultiBufferSetup(ushort CardNumber, uint[] pwBuffer, uint dwWriteCount,
                                                               out ushort BufferId);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_AsyncMultiBufferNextReady(ushort CardNumber, out byte bNextReady,
                                                                    out ushort wBufferId);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_ContMultiBufferStart(ushort wCardNumber, ushort wPort, double fSampleRate);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_EventCallBack(ushort CardNumber, short mode, short EventType,
                                                        MulticastDelegate callbackAddr);
    
            /*---------------------------------------------------------------------------*/
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DIO_PortConfig(ushort CardNumber, ushort Port, ushort Direction);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DIO_LinesConfig(ushort wCardNumber, ushort wPort, ushort wLinesdirmap);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DIO_LineConfig(ushort wCardNumber, ushort wPort, ushort wLine, ushort wDirection);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DIO_SetDualInterrupt(ushort CardNumber, short Int1Mode, short Int2Mode, long hEvent);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DIO_SetCOSInterrupt(ushort CardNumber, ushort Port, ushort ctlA, ushort ctlB,
                                                           ushort ctlC);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DIO_INT1_EventMessage(ushort CardNumber, short Int1Mode, long windowHandle,
                                                             long message, MulticastDelegate callbackAddr);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DIO_INT2_EventMessage(ushort CardNumber, short Int2Mode, long windowHandle,
                                                             long message, MulticastDelegate callbackAddr);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DIO_7300SetInterrupt(ushort CardNumber, short AuxDIEn, short T2En, long hEvent);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DIO_AUXDI_EventMessage(ushort CardNumber, short AuxDIEn, long windowHandle,
                                                              uint message, MulticastDelegate callbackAddr);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DIO_T2_EventMessage(ushort CardNumber, short T2En, long windowHandle, uint message,
                                                           MulticastDelegate callbackAddr);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DIO_GetCOSLatchData(ushort wCardNumber, out ushort CosLData);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DIO_SetCOSInterrupt32(ushort wCardNumber, byte Port, uint ctl, out long hEvent,
                                                             bool bManualReset);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DIO_GetCOSLatchDataInt32(ushort wCardNumber, byte Port, out uint CosLData);
    
            /*---------------------------------------------------------------------------*/
    
            [DllImport("PCI-Dask.dll")]
            public static extern short CTR_Setup(ushort CardNumber, ushort Ctr, ushort Mode, uint Count, ushort BinBcd);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short CTR_Clear(ushort CardNumber, ushort Ctr, ushort State);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short CTR_Read(ushort CardNumber, ushort Ctr, out uint Value);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short CTR_Update(ushort CardNumber, ushort Ctr, uint Count);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short CTR_8554_ClkSrc_Config(ushort CardNumber, ushort Ctr, ushort ClockSource);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short CTR_8554_CK1_Config(ushort CardNumber, ushort ClockSource);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short CTR_8554_Debounce_Config(ushort CardNumber, ushort DebounceClock);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short GCTR_Setup(ushort wCardNumber, ushort wGCtr, ushort wGCtrCtrl, uint dwCount);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short GCTR_Clear(ushort wCardNumber, ushort wGCtr);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short GCTR_Read(ushort wCardNumber, ushort wGCtr, out uint pValue);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short WDT_Setup(ushort CardNumber, ushort wCtr, float ovflowSec, out float actualSec,
                                                 out long hEvent);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short WDT_Control(ushort wCardNumber, ushort wCtr, ushort action);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short WDT_Status(ushort wCardNumber, ushort Ctr, out uint pValue);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short WDT_Reload(ushort wCardNumber, float ovflowSec, out float actualSec);
    
            /*---------------------------------------------------------------------------*/
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_GetEvent(ushort wCardNumber, out long hEvent);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AO_GetEvent(ushort wCardNumber, out long hEvent);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_GetEvent(ushort wCardNumber, out long hEvent);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_GetEvent(ushort wCardNumber, out long hEvent);
    
            /*---------------------------------------------------------------------------*/
    
            [DllImport("PCI-Dask.dll")]
            public static extern short AI_GetView(ushort wCardNumber, uint[] pView);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DI_GetView(ushort wCardNumber, uint[] pView);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short DO_GetView(ushort wCardNumber, uint[] pView);
    
            /*---------------------------------------------------------------------------*/
    
            [DllImport("PCI-Dask.dll")]
            public static extern short GetCardType(ushort wCardNumber, out ushort cardType);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short GetCardIndexFromID(ushort wCardNumber, out ushort cardType, out ushort cardIndex);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short GetBaseAddr(ushort wCardNumber, uint[] BaseAddr, uint[] BaseAddr2);
    
            [DllImport("PCI-Dask.dll")]
            public static extern short GetLCRAddr(ushort wCardNumber, uint[] LcrAddr);
        }
    }
    PCI-DASK工具类
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Common.PciProtocol;
    using System.Collections;
    
    namespace PCI.PciProtocol
    {
        public class Card_7234
        {
            ushort cardNum = 0;//卡号
    
            public int iDI_7234_Max = 32;//端口数量
    
            int sum = 0;
    
    
            private Card_7234() { }
    
            public Card_7234(ushort cardNum)
            {
                this.cardNum = cardNum;
            }
    
            /*注册一个7234卡*/
            public void Register()
            {
                short state = DASK.Register_Card(DASK.PCI_7234, cardNum);
                if (state < 0)
                {
                    throw new Exception("Register failed!");
                }
                //给端口赋值0
                writePort(0);
            }
          
            /*向端口写数据*/
            public bool writePort(int out_value)
            {
                short ret;
                ret = DASK.DO_WritePort((ushort)cardNum,0, (uint)out_value);
    
                if (ret < 0)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
    
            /*从端口读数据*/
            public bool readPort(out uint int_value, ref int[] arr)
            {
                short ret; 
                ret = DASK.DO_ReadPort((ushort)  cardNum, 0, out int_value);
                if (ret < 0)
                {
                     return false;
                }
                else
                {
                    arr = getArr(int_value);
                    return true;
                }
            }
            /*从端口读数据*/
            public bool readPort(out uint int_value)
            {
                short ret;
                ret = DASK.DO_ReadPort((ushort)cardNum, 0, out int_value);
                if (ret < 0)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
    
    
            public bool openLight(int indexLight)
            {
                uint sum=0;
                if(readPort(out sum))
                {
                   sum+=(uint)Math.Pow(2,indexLight-1);
                }
                if(writePort((int)sum))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
    
            public bool closeLight(int indexLight)
            {
                uint sum = 0;
                uint temp = (uint)Math.Pow(2, indexLight-1);
                if (readPort(out sum))
                {
                    if (sum >= temp)
                    {
                        sum -= temp;
                    }
                }
                if (writePort((int)sum))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
    
             /*获取一个int类型的二进制数组*/
            private static int[] getArr(uint count)
            {
                object[] objArr=IntConvert.Ten2TwoArr((int)count).ToArray();
                int[] result=new int[objArr.Length];
                for (int i = 0; i < objArr.Length; i++)
                {
                    result[i] = Convert.ToInt32(objArr[i]);
                }
                return result;
            }
    
            /*释放端口*/
            public void Release()
            {
                DASK.Release_Card(cardNum);
            }
    
    
        }
    }
    Card_7234
    /***********************************/
    /*     Author: Made by Anby        */
    /*  Date Time: 2013-7-19           */
    /*      Using:用于读取9113数据     */
    /***********************************/
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Common.PciProtocol;
    
    namespace PCI.PciProtocol
    {
    
        #region 用法
        /*   
         *      Card_9113 c9113 = new Card_9113(0);
         *       c9113.Register();
         *       double value;
         *       if (c9113.ReadChannel(1, out  value))
         *       {
         *            //@TODO
         *       }
         *       c9113.Release();
         */
        #endregion
    
        public class Card_9113
        {
            ushort cardNum = 0;//卡号
    
            public int iAD_9113_MAX = 32;//端口数量
    
            int sum = 0;
    
    
            private Card_9113() { }
    
            public Card_9113(ushort cardNum)
            {
                this.cardNum = cardNum;
            }
    
            /*注册一个9113卡*/
            public void Register()
            {
                short state = DASK.Register_Card(DASK.PCI_9113, cardNum);
                if (state < 0)
                {
                    throw new Exception("Register failed!");
                }
            }
    
            /*读通道数据*/
            public bool ReadChannel(ushort channel, out double data)
            {
                //所有的通道都是一样的
    
                if (channel > iAD_9113_MAX || channel < 1)
                {
                    data = 0;
                    return false;
                }
    
                ushort value;//用来接收摸拟信号
    
                //AD_B_10_V表示正负10v,AD_U_10_V表示正10v
    
                DASK.AI_ReadChannel(cardNum, channel, DASK.AD_B_10_V, out value);
    
                data = ((double)value * 10) / 4096;//将读的摸拟信号转换为数字信号 公式: 10/4096=x/摸拟信号
                return true;
    
            }
    
    
            /*释放端口*/
            public void Release()
            {
                DASK.Release_Card(cardNum);
            }
        }
    }
    Card_9113

    3.串口操作(使用的是vs自带的串口控件)

    (略过)

    4.usb操作

    using System;
    using System.Runtime.InteropServices;
    using System.Text;
    
    namespace USBXpress_TestPanel
    {
        internal class SLUSBXpressDLL
        {
            // Return Codes
            public const Int32 SI_SUCCESS = 0x00;
            public const Int32 SI_DEVICE_NOT_FOUND = 0xFF;
            public const Int32 SI_INVALID_HANDLE = 0x01;
            public const Int32 SI_READ_ERROR = 0x02;
            public const Int32 SI_RX_QUEUE_NOT_READY = 0x03;
            public const Int32 SI_WRITE_ERROR = 0x04;
            public const Int32 SI_RESET_ERROR = 0x05;
            public const Int32 SI_INVALID_PARAMETER = 0x06;
            public const Int32 SI_INVALID_REQUEST_LENGTH = 0x07;
            public const Int32 SI_DEVICE_IO_FAILED = 0x08;
            public const Int32 SI_INVALID_BAUDRATE = 0x09;
            public const Int32 SI_FUNCTION_NOT_SUPPORTED = 0x0a;
            public const Int32 SI_GLOBAL_DATA_ERROR = 0x0b;
            public const Int32 SI_SYSTEM_ERROR_CODE = 0x0c;
            public const Int32 SI_READ_TIMED_OUT = 0x0d;
            public const Int32 SI_WRITE_TIMED_OUT = 0x0e;
            public const Int32 SI_IO_PENDING = 0x0f;
    
            // GetProductString() function flags
            public const Int32 SI_RETURN_SERIAL_NUMBER = 0x00;
            public const Int32 SI_RETURN_DESCRIPTION = 0x01;
            public const Int32 SI_RETURN_LINK_NAME = 0x02;
            public const Int32 SI_RETURN_VID = 0x03;
            public const Int32 SI_RETURN_PID = 0x04;
    
            // RX Queue status flags
            public const Int32 SI_RX_NO_OVERRUN = 0x00;
            public const Int32 SI_RX_EMPTY = 0x00;
            public const Int32 SI_RX_OVERRUN = 0x01;
            public const Int32 SI_RX_READY = 0x02;
    
            // Buffer size limits
            public const Int32 SI_MAX_DEVICE_STRLEN = 256;
            public const Int32 SI_MAX_READ_SIZE = 4096*1;
            public const Int32 SI_MAX_WRITE_SIZE = 4096;
    
            // Input and Output pin Characteristics
            public const Int32 SI_HELD_INACTIVE = 0x00;
            public const Int32 SI_HELD_ACTIVE = 0x01;
            public const Int32 SI_FIRMWARE_CONTROLLED = 0x02;
            public const Int32 SI_RECEIVE_FLOW_CONTROL = 0x02;
            public const Int32 SI_TRANSMIT_ACTIVE_SIGNAL = 0x03;
            public const Int32 SI_STATUS_INPUT = 0x00;
            public const Int32 SI_HANDSHAKE_LINE = 0x01;
    
            // Mask and Latch value bit definitions
            public const Int32 SI_GPIO_0 = 0x01;
            public const Int32 SI_GPIO_1 = 0x02;
            public const Int32 SI_GPIO_2 = 0x04;
            public const Int32 SI_GPIO_3 = 0x08;
    
            // GetDeviceVersion() return codes
            public const Int32 SI_CP2101_VERSION = 0x01;
            public const Int32 SI_CP2102_VERSION = 0x02;
            public const Int32 SI_CP2103_VERSION = 0x03;
    
            public static Int32 Status;
            public static UInt32 hUSBDevice;
    
            [DllImport("SiUSBXp.dll")]
            public static extern int SI_GetNumDevices
                (ref Int32 lpdwNumDevices);
    
            [DllImport("SiUSBXp.dll")]
            public static extern int SI_GetProductString
                (Int32 dwDeviceNum,
                 StringBuilder lpvDeviceString,
                 Int32 dwFlags);
    
            [DllImport("SiUSBXp.dll")]
            public static extern int SI_Open
                (Int32 dwDevice,
                 ref UInt32 cyHandle);
    
            [DllImport("SiUSBXp.dll")]
            public static extern int SI_Close
                (UInt32 cyHandle);
    
            [DllImport("SiUSBXp.dll")]
            public static extern int SI_Read
                (UInt32 cyHandle,
                 ref Byte lpBuffer,
                 Int32 dwBytesToRead,
                 ref Int32 lpdwBytesReturned,
                 Int32 lpOverlapped);
    
            [DllImport("SiUSBXp.dll")]
            public static extern int SI_Write
                (UInt32 cyHandle,
                 ref Byte lpBuffer,
                 Int32 dwBytesToWrite,
                 ref Int32 lpdwBytesWritten,
                 Int32 lpOverlapped);
    
            [DllImport("SiUSBXp.dll")]
            public static extern int SI_SetTimeouts
                (Int32 dwReadTimeout,
                 Int32 dwWriteTimeout);
    
            [DllImport("SiUSBXp.dll")]
            public static extern int SI_GetTimeouts
                (ref Int32 dwReadTimeout,
                 ref Int32 dwWriteTimeout);
    
            [DllImport("SiUSBXp.dll")]
            public static extern int SI_CheckRXQueue
                (UInt32 cyHandle,
                 ref UInt32 lpdwNumBytesInQueue,
                 ref UInt32 lpdwQueueStatus);
        }
    }
    SLUSBXpressDLL
  • 相关阅读:
    Go语言学习笔记(二)十分钟上手
    Go语言学习笔记(一)Let's 干吧
    Windows下visual studio code搭建golang开发环境
    dotweb——go语言的一个微型web框架(三)路由注册
    dotweb——go语言的一个微型web框架(二)启动dotweb
    dotweb——go语言的一个微型web框架(一)
    【转】URL的井号
    39行代码实现JS HTML模板(轻量+高效+易用)
    “void * __cdecl operator new(unsigned int)”(??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)
    C++ Compiling… Error spawning cl.exe
  • 原文地址:https://www.cnblogs.com/anbylau2130/p/3193951.html
Copyright © 2011-2022 走看看