示例#1
0
        static void Main(string[] args)
        {
            try
            {
                //Declare an frequencycounter object
                FrequencyCounter freq = new FrequencyCounter();

                //Hook the basic event handlers
                freq.Attach += new AttachEventHandler(accel_Attach);
                freq.Detach += new DetachEventHandler(accel_Detach);
                freq.Error  += new ErrorEventHandler(accel_Error);

                //hook the phidget specific event handlers
                freq.Count += new FrequencyCounterCountEventHandler(freq_Count);

                //open the acclerometer object for device connections
                freq.open();

                //get the program to wait for an frequencycounter device to be attached
                Console.WriteLine("Waiting for frequencycounter to be attached....");
                freq.waitForAttachment();

                //enable the inputs
                for (int i = 0; i < freq.inputs.Count; i++)
                {
                    freq.inputs[i].Enabled = true;
                    freq.inputs[i].Filter  = FrequencyCounterInput.FilterType.LOGIC_LEVEL;
                }

                //Get the program to wait for user input before moving on so that we can
                //watch for some events
                Console.WriteLine("Press any key to end");
                Console.Read();

                //If user input has been read, we can now terminate the program, so
                //close the phidget object
                freq.close();

                //set the object to null to clear it from memory
                freq = null;

                //if no exceptions have been trhown at this point, the program can
                //terminate safely
                Console.WriteLine("ok");
            }
            catch (PhidgetException ex)
            {
                Console.WriteLine(ex.Description);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                //Declare an frequencycounter object
                FrequencyCounter freq = new FrequencyCounter();

                //Hook the basic event handlers
                freq.Attach += new AttachEventHandler(accel_Attach);
                freq.Detach += new DetachEventHandler(accel_Detach);
                freq.Error += new ErrorEventHandler(accel_Error);

                //hook the phidget specific event handlers
                freq.Count += new FrequencyCounterCountEventHandler(freq_Count);

                //open the acclerometer object for device connections
                freq.open();

                //get the program to wait for an frequencycounter device to be attached
                Console.WriteLine("Waiting for frequencycounter to be attached....");
                freq.waitForAttachment();

                //enable the inputs
                for (int i = 0; i < freq.inputs.Count; i++)
                {
                    freq.inputs[i].Enabled = true;
                    freq.inputs[i].Filter = FrequencyCounterInput.FilterType.LOGIC_LEVEL;
                }

                //Get the program to wait for user input before moving on so that we can
                //watch for some events
                Console.WriteLine("Press any key to end");
                Console.Read();

                //If user input has been read, we can now terminate the program, so
                //close the phidget object
                freq.close();

                //set the object to null to clear it from memory
                freq = null;

                //if no exceptions have been trhown at this point, the program can
                //terminate safely
                Console.WriteLine("ok");
            }
            catch (PhidgetException ex)
            {
                Console.WriteLine(ex.Description);
            }
        }