Measurement Computing   Easy to Use | Easy to Integrate | Easy to Support catalog banner

Measurement Computing Data Acquisition Knowledgebase

Welcome Guest ( )

USB-1208LS External Level Trigger Example

Expand / Collapse
 

USB-1208LS External Level Trigger Example


The following example demonstrates how to trigger using the External TTL input. Once triggered, the program continuously acquires data to buffer. 

To access the API, add a reference to the MccDaq object. Adding the reference is usually accomplished by right clicking the Project [under the Project Explorer] and selecting Add Reference.The complete project is attached to the article and was created with Visual Studio 2008 using CSharp. Compiling and execution is quick as there is minimal Windows overhead and associated code. 

Although not shown below, a few convenience functions were added such as IsError, GetBoardNum, DisplayData, and WaitForKey. To view all the functions download the complete Visual Studio 2008 project by extracting the zip file at the bottom. 

The functionality is fairly simple, the acquisition waits for a TTL level high signal to appear on the External Trigger input and when received it puts data into the buffer. To command the API to look at the External Trigger input use the Scan Options enumeration ExtTrigger is used along with the SetTrigger function. 

Disclaimer:
The attached Code or Example is provided As Is.  It has not been tested or validated as a product, for use in a deployed application or system, or for use in hazardous environments.  You assume all risks for use of the Code or Example.


---------------------------------------------------------------------------------------------------------------
        public const int BLOCKSIZE = 50;
        public const int CHANCOUNT = 4;
        public const int FIRSTCHANNEL = 0;
        public const int LASTCHANNEL = 3;
        public const int FREQ = 100;
        public const int PACKETSIZE = 32;
 
        public const string DEVICE = "USB-1208LS";

        public static MccBoard daq;

        static void Main(string[] args)
        {

            int BoardNum = 0;
            int DeviceChannels = 0;
            int Rate = FREQ;
            Console.WriteLine("\nExternal TTL trigger Example\n");
            Console.WriteLine("\nLocating board...\n");

            BoardNum = GetBoardNum(DEVICE);

            if (BoardNum == -1)
                Console.WriteLine("No {0} detected!", DEVICE);
            else
            {
                daq = new MccDaq.MccBoard(BoardNum);
                daq.BoardConfig.GetNumAdChans(out DeviceChannels);
                int chs = 0;
                daq.BoardConfig.GetNumAdChans(out chs);
                Console.WriteLine("Number of available channels {0}\n",chs);

                int BUFFERSIZE = PACKETSIZE * CHANCOUNT;
                int HALFBUFFSIZE = BUFFERSIZE / 2;
                IntPtr buffer = MccService.WinBufAllocEx(BUFFERSIZE);

                if (buffer == IntPtr.Zero)
                {
                    Console.WriteLine("Bad Handle");
                    return;
                }

                short[] chArray = new short[CHANCOUNT];
                Range[] chRange = new Range[CHANCOUNT];

                chArray[0] = 0;
                chArray[1] = 1;
                chArray[2] = 2;
                chArray[3] = 3;

                chRange[0] = Range.Bip10Volts;
                chRange[1] = Range.Bip10Volts;
                chRange[2] = Range.Bip10Volts;
                chRange[3] = Range.Bip10Volts;

                IsError( daq.ALoadQueue(chArray, chRange, CHANCOUNT));

                //TTL signal connected to Trigger input
                IsError(daq.SetTrigger(TriggerType.TrigHigh, 0, 0));
                Console.WriteLine("Waiting for level high trigger.");


                //setup the acquisiton
                IsError( daq.AInScan(   FIRSTCHANNEL,
                                        LASTCHANNEL,
                                        BUFFERSIZE,
                                        ref Rate,
                                        Range.Bip10Volts,
                                        buffer,
                                        ScanOptions.ExtTrigger|ScanOptions.ConvertData
                                    ));
                

                int Count = 0;
                int Index = 0;
                short daqStatus;

                ushort[] theArray = new ushort[BUFFERSIZE];

                do
                {   //spin here until the buffer is half full
                    System.Threading.Thread.Sleep(10);
                    IsError(daq.GetStatus(out daqStatus, out Count, out Index, FunctionType.AiFunction));
                    if (Console.KeyAvailable)
                    {
                        IsError(daq.StopBackground(FunctionType.AiFunction));
                        MccService.WinBufFreeEx(buffer);
                        return;
                    }

                } while( Count < BUFFERSIZE );

                IsError(MccService.WinBufToArray(buffer, theArray, 0, BUFFERSIZE));

                DisplayData(theArray, BUFFERSIZE/CHANCOUNT);
                
                IsError(daq.StopBackground(FunctionType.AiFunction));

                MccService.WinBufFreeEx(buffer);

                WaitForKey();
            }
        }


Rate this Article:

Attachments


AnalogInExtTtrigger.zip AnalogInExtTtrigger.zip (23.13 KB, 631 views)

Add Your Comments


For comments email TechSupport@mccdaq.com.

Details
Article ID: 50552

Last Modified:7/24/2014 3:41:34 PM

Article has been viewed 3,734 times.

Options