Exemplo n.º 1
0
        private void Initialize()
        {
            double value = 0;

            evth.LogMessage(this, new LogEventArgs(LogLevel.INFO, "Initializing."));


            try {  //Open the first found LabJack U3 through USB.
                u3      = new U3(LJUD.CONNECTION.USB, "0", true);
                isValid = true;
            } catch (Exception ex) {
                evth.LogMessage(this, new LogEventArgs(LogLevel.ERROR, "Initialize exception: " + ex.Message));
                return;
            }
            value = LJUD.GetDriverVersion();
            evth.LogMessage(this, new LogEventArgs(LogLevel.INFO, "UD Driver Version: " + value.ToString()));
            LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.HARDWARE_VERSION, ref value, 0);
            evth.LogMessage(this, new LogEventArgs(LogLevel.INFO, "Hardware Version: " + value));
            LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.FIRMWARE_VERSION, ref value, 0);
            evth.LogMessage(this, new LogEventArgs(LogLevel.INFO, "Firmware Version: " + value));
            evth.LogMessage(this, new LogEventArgs(LogLevel.INFO, "Initialized."));

            Execute(LJU3Commands.PIN_CONFIGURATION_RESET, new object[] { });            //pin assignments in factory default condition.
            Execute(LJU3Commands.PUT_ANALOG_ENABLE_PORT, new object[] { 0, 0, 16 });    //all assignments digital input.
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads / configures the U3 and displays the UD driver version
        /// </summary>
        /// <param name="sender">The object that executed this method</param>
        /// <param name="e">Event parameters</param>
        private void TimedWindow_Load(object sender, System.EventArgs e)
        {
            double dblDriverVersion;

            // Disable the go button until the device has loaded
            goStopButton.Enabled = false;

            // Create the event timer but do not start it
            updateTimer          = new System.Timers.Timer();
            updateTimer.Elapsed += new ElapsedEventHandler(TimerEvent);
            updateTimer.Interval = TIMER_INTERVAL;

            //Read and display the UD version.
            dblDriverVersion    = LJUD.GetDriverVersion();
            versionDisplay.Text = String.Format("{0:0.000}", dblDriverVersion);

            try
            {
                //Open the first found LabJack U3.
                u3 = new U3(LJUD.CONNECTION.USB, "0", true);                 // Connection through USB

                //Start by using the pin_configuration_reset IOType so that all
                //pin assignments are in the factory default condition.
                LJUD.ePut(u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0);

                //Configure FIO0-FIO3 as analog, all else as digital.  That means we
                //will start from channel 0 and update all 16 flexible bits.  We will
                //pass a value of b0000000000001111 or d15.
                LJUD.ePut(u3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 15, 16);
            }
            catch (LabJackUDException exc)
            {
                ShowErrorMessage(exc);
                return;
            }

            // Re-enable the go button
            goStopButton.Enabled = true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Configure and start the stream on the LabJack
        /// </summary>
        /// <returns>True if successful and false otherwise</returns>
        private bool StartStreaming()
        {
            //Read and display the UD version.
            dblValue            = LJUD.GetDriverVersion();
            versionDisplay.Text = String.Format("{0:0.000}", dblValue);

            try
            {
                //Open the first found LabJack U3.
                u3 = new U3(LJUD.CONNECTION.USB, "0", true);                 // Connection through USB

                //Read and display the hardware version of this U3.
                LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.HARDWARE_VERSION, ref dblValue, 0);
                hardwareDisplay.Text = String.Format("{0:0.000}", dblValue);

                //Read and display the firmware version of this U3.
                LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.FIRMWARE_VERSION, ref dblValue, 0);
                firmwareDisplay.Text = String.Format("{0:0.000}", dblValue);

                //Start by using the pin_configuration_reset IOType so that all
                //pin assignments are in the factory default condition.
                LJUD.ePut(u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0);

                //Configure FIO0 and FIO1 as analog, all else as digital.  That means we
                //will start from channel 0 and update all 16 flexible bits.  We will
                //pass a value of b0000000000000011 or d3.
                LJUD.ePut(u3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 3, 16);

                //Configure the stream:
                //Set the scan rate.
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_SCAN_FREQUENCY, scanRate, 0, 0);

                //Give the driver a 5 second buffer (scanRate * 2 channels * 5 seconds).
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_BUFFER_SIZE, scanRate * 2 * 5, 0, 0);

                //Configure reads to retrieve whatever data is available without waiting (wait mode LJUD.STREAMWAITMODES.NONE).
                //See comments below to change this program to use LJUD.STREAMWAITMODES.SLEEP mode.
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_WAIT_MODE, (double)LJUD.STREAMWAITMODES.NONE, 0, 0);

                //Define the scan list as AIN0 then AIN1.
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.CLEAR_STREAM_CHANNELS, 0, 0, 0, 0);
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.ADD_STREAM_CHANNEL, 0, 0, 0, 0);
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.ADD_STREAM_CHANNEL_DIFF, 1, 0, 32, 0);

                //Execute the list of requests.
                LJUD.GoOne(u3.ljhandle);
            }
            catch (LabJackUDException e)
            {
                ShowErrorMessage(e);
                return(false);
            }

            //Get all the results just to check for errors.
            try { LJUD.GetFirstResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
            catch (LabJackUDException e) { ShowErrorMessage(e); }
            bool finished = false;

            while (!finished)
            {
                try { LJUD.GetNextResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
                catch (LabJackUDException e)
                {
                    // If we get an error, report it.  If the error is NO_MORE_DATA_AVAILABLE we are done
                    if (e.LJUDError == UE9.LJUDERROR.NO_MORE_DATA_AVAILABLE)
                    {
                        finished = true;
                    }
                    else
                    {
                        ShowErrorMessage(e);
                    }
                }
            }

            //Start the stream.
            try { LJUD.eGet(u3.ljhandle, LJUD.IO.START_STREAM, 0, ref dblValue, 0); }
            catch (LabJackUDException e)
            {
                ShowErrorMessage(e);
                return(false);
            }

            //The actual scan rate is dependent on how the desired scan rate divides into
            //the LabJack clock.  The actual scan rate is returned in the value parameter
            //from the start stream command.
            scanDisplay.Text   = String.Format("{0:0.000}", dblValue);
            sampleDisplay.Text = String.Format("{0:0.000}", 2 * dblValue);          // # channels * scan rate

            // The stream started successfully
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Opens the LabJack, gets the UD driver version, and
        /// configures the device.
        /// </summary>
        /// <param name="sender">The object that called this event</param>
        /// <param name="e">Event details</param>
        private void TimedWindow_Load(object sender, System.EventArgs e)
        {
            double dblDriverVersion;

            LJUD.IO      ioType   = 0;
            LJUD.CHANNEL channel  = 0;
            double       dblValue = 0;

            // dummy variables to satisfy certian method signatures
            double dummyDouble = 0;
            int    dummyInt    = 0;

            // Create the event timer but do not start it
            updateTimer          = new System.Timers.Timer();
            updateTimer.Elapsed += new ElapsedEventHandler(TimerEvent);
            updateTimer.Interval = TIMER_INTERVAL;

            // Disable the start button while the device is loading
            goStopButton.Enabled = false;
            Update();

            //Read and display the UD version.
            dblDriverVersion    = LJUD.GetDriverVersion();
            versionDisplay.Text = String.Format("{0:0.000}", dblDriverVersion);

            // Open and configure U6
            try
            {
                //Open the device
                u6 = new U6(LJUD.CONNECTION.USB, "0", true);

                //Configure the resolution of the analog inputs (pass a non-zero value for quick sampling).
                //See section 2.6 / 3.1 for more information.
                LJUD.AddRequest(u6.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.AIN_RESOLUTION, 0, 0, 0);

                //Configure the analog input range on channels 2 and 3 for bipolar 10v.
                LJUD.AddRequest(u6.ljhandle, LJUD.IO.PUT_AIN_RANGE, (LJUD.CHANNEL) 2, (double)LJUD.RANGES.BIP10V, 0, 0);
                LJUD.AddRequest(u6.ljhandle, LJUD.IO.PUT_AIN_RANGE, (LJUD.CHANNEL) 3, (double)LJUD.RANGES.BIP10V, 0, 0);
            }
            catch (LabJackUDException exc)
            {
                ShowErrorMessage(exc);
                return;
            }

            try
            {
                //Execute the requests.
                LJUD.GoOne(u6.ljhandle);

                //Get all the results.  The input measurement results are stored.  All other
                //results are for configuration or output requests so we are just checking
                //whether there was an error. The rest of the results are in the below loop.
                LJUD.GetFirstResult(u6.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble);
            }
            catch (LabJackUDException exc)
            {
                ShowErrorMessage(exc);
                return;
            }

            bool isFinished = false;

            while (!isFinished)
            {
                try { LJUD.GetNextResult(u6.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
                catch (LabJackUDException exc)
                {
                    // If we get an error, report it.  If the error is NO_MORE_DATA_AVAILABLE we are done
                    if (exc.LJUDError == U6.LJUDERROR.NO_MORE_DATA_AVAILABLE)
                    {
                        isFinished = true;
                    }
                    else
                    {
                        ShowErrorMessage(exc);
                        return;
                    }
                }
            }

            // Enable the start button
            goStopButton.Enabled = true;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Configure and start the stream on the LabJack
        /// </summary>
        /// <returns>True if successful and false otherwise</returns>
        private bool StartStreaming()
        {
            //Read and display the UD version.
            dblValue            = LJUD.GetDriverVersion();
            versionDisplay.Text = String.Format("{0:0.000}", dblValue);

            try
            {
                //Open the first found LabJack U6.
                u6 = new U6(LJUD.CONNECTION.USB, "0", true);                 // Connection through USB

                //Read and display the hardware version of this U6.
                LJUD.eGet(u6.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.HARDWARE_VERSION, ref dblValue, 0);
                hardwareDisplay.Text = String.Format("{0:0.000}", dblValue);

                //Read and display the firmware version of this U6.
                LJUD.eGet(u6.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.FIRMWARE_VERSION, ref dblValue, 0);
                firmwareDisplay.Text = String.Format("{0:0.000}", dblValue);

                //Configure the analog input range on channel 0 for bipolar +-10 volts.
                LJUD.AddRequest(u6.ljhandle, LJUD.IO.PUT_AIN_RANGE, 0, (double)LJUD.RANGES.BIP10V, 0, 0);

                //Configure the stream:
                //Set the scan rate.
                LJUD.AddRequest(u6.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_SCAN_FREQUENCY, scanRate, 0, 0);

                //Give the driver a 5 second buffer (scanRate * 2 channels * 5 seconds).
                LJUD.AddRequest(u6.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_BUFFER_SIZE, scanRate * 2 * 5, 0, 0);

                //Configure reads to retrieve whatever data is available without waiting (wait mode LJUD.STREAMWAITMODES.NONE).
                //See comments below to change this program to use LJUD.STREAMWAITMODES.SLEEP mode.
                LJUD.AddRequest(u6.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_WAIT_MODE, (double)LJUD.STREAMWAITMODES.NONE, 0, 0);

                //Define the scan list as AIN0 then AIN1.
                LJUD.AddRequest(u6.ljhandle, LJUD.IO.CLEAR_STREAM_CHANNELS, 0, 0, 0, 0);
                LJUD.AddRequest(u6.ljhandle, LJUD.IO.ADD_STREAM_CHANNEL, 0, 0, 0, 0);
                LJUD.AddRequest(u6.ljhandle, LJUD.IO.ADD_STREAM_CHANNEL, 1, 0, 0, 0);

                //Execute the list of requests.
                LJUD.GoOne(u6.ljhandle);
            }
            catch (LabJackUDException e)
            {
                ShowErrorMessage(e);
                return(false);
            }

            //Get all the results just to check for errors.
            try { LJUD.GetFirstResult(u6.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
            catch (LabJackUDException e) { ShowErrorMessage(e); }
            bool finished = false;

            while (!finished)
            {
                try { LJUD.GetNextResult(u6.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
                catch (LabJackUDException e)
                {
                    // If we get an error, report it.  If the error is NO_MORE_DATA_AVAILABLE we are done
                    if (e.LJUDError == UE9.LJUDERROR.NO_MORE_DATA_AVAILABLE)
                    {
                        finished = true;
                    }
                    else
                    {
                        ShowErrorMessage(e);
                    }
                }
            }

            //Start the stream.
            try { LJUD.eGet(u6.ljhandle, LJUD.IO.START_STREAM, 0, ref dblValue, 0); }
            catch (LabJackUDException e)
            {
                ShowErrorMessage(e);
                return(false);
            }

            //The actual scan rate is dependent on how the desired scan rate divides into
            //the LabJack clock.  The actual scan rate is returned in the value parameter
            //from the start stream command.
            scanDisplay.Text   = String.Format("{0:0.000}", dblValue);
            sampleDisplay.Text = String.Format("{0:0.000}", 2 * dblValue);          // # channels * scan rate

            // The stream started successfully
            return(true);
        }
Exemplo n.º 6
0
        public void performActions()
        {
            double dblDriverVersion;

            LJUD.IO      ioType = 0;
            LJUD.CHANNEL channel = 0;
            double       dblValue = 0;
            double       Value22 = 9999, Value32 = 9999, Value42 = 9999;
            double       Value23 = 9999, Value33 = 9999, Value43 = 9999;

            // Variables to satisfy certain method signatures
            int    dummyInt    = 0;
            double dummyDouble = 0;

            //Read and display the UD version.
            dblDriverVersion = LJUD.GetDriverVersion();
            Console.Out.WriteLine("UD Driver Version = {0:0.000}\n\n", dblDriverVersion);


            //Open the U3 with local ID 2.
            try
            {
                unit2 = new U3(LJUD.CONNECTION.USB, "2", false);                 // Connection through USB
                unit3 = new U3(LJUD.CONNECTION.USB, "3", false);                 // Connection through USB

                //Start by using the pin_configuration_reset IOType so that all
                //pin assignments are in the factory default condition.
                LJUD.ePut(unit2.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0);
                LJUD.ePut(unit3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0);


                //First a configuration command.  These will be done with the ePut
                //function which combines the add/go/get into a single call.

                //Configure FIO2-FIO4 as analog, all else as digital, on both devices.
                //That means we will start from channel 0 and update all 16 flexible bits.
                //We will pass a value of b0000000000011100 or d28.
                LJUD.ePut(unit2.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 28, 16);
                LJUD.ePut(unit3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 28, 16);


                //The following commands will use the add-go-get method to group
                //multiple requests into a single low-level function.

                //Request a single-ended reading from AIN2.
                LJUD.AddRequest(unit2.ljhandle, LJUD.IO.GET_AIN, 2, 0, 0, 0);
                LJUD.AddRequest(unit3.ljhandle, LJUD.IO.GET_AIN, 2, 0, 0, 0);

                //Request a single-ended reading from AIN3.
                LJUD.AddRequest(unit2.ljhandle, LJUD.IO.GET_AIN, 3, 0, 0, 0);
                LJUD.AddRequest(unit3.ljhandle, LJUD.IO.GET_AIN, 3, 0, 0, 0);

                //Request a reading from AIN4 using the Special 0-3.6 range.
                LJUD.AddRequest(unit2.ljhandle, LJUD.IO.GET_AIN_DIFF, 4, 0, 32, 0);
                LJUD.AddRequest(unit3.ljhandle, LJUD.IO.GET_AIN_DIFF, 4, 0, 32, 0);
            }
            catch (LabJackUDException e)
            {
                showErrorMessage(e);
            }

            bool isFinished = false;

            while (!isFinished)
            {
                try
                {
                    //Execute all requests on all open LabJacks.
                    LJUD.Go();

                    //Get all the results for unit 2.  The input measurement results are stored.
                    LJUD.GetFirstResult(unit2.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble);
                }
                catch (LabJackUDException e)
                {
                    showErrorMessage(e);
                }

                bool unit2Finished = false;
                while (!unit2Finished)
                {
                    switch (ioType)
                    {
                    case LJUD.IO.GET_AIN:
                        switch ((int)channel)
                        {
                        case 2:
                            Value22 = dblValue;
                            break;

                        case 3:
                            Value32 = dblValue;
                            break;
                        }
                        break;

                    case LJUD.IO.GET_AIN_DIFF:
                        Value42 = dblValue;
                        break;
                    }

                    try { LJUD.GetNextResult(unit2.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
                    catch (LabJackUDException e)
                    {
                        // If we get an error, report it.  If the error is NO_MORE_DATA_AVAILABLE we are done
                        if (e.LJUDError == UE9.LJUDERROR.NO_MORE_DATA_AVAILABLE)
                        {
                            unit2Finished = true;
                        }
                        else
                        {
                            showErrorMessage(e);
                        }
                    }
                }


                //Get all the results for unit 3.  The input measurement results are stored.
                try { LJUD.GetFirstResult(unit3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
                catch (LabJackUDException e)  { showErrorMessage(e); }

                bool unit3Finished = false;
                while (!unit3Finished)
                {
                    switch (ioType)
                    {
                    case LJUD.IO.GET_AIN:
                        switch ((int)channel)
                        {
                        case 2:
                            Value23 = dblValue;
                            break;

                        case 3:
                            Value33 = dblValue;
                            break;
                        }
                        break;

                    case LJUD.IO.GET_AIN_DIFF:
                        Value43 = dblValue;
                        break;
                    }

                    try { LJUD.GetNextResult(unit3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
                    catch (LabJackUDException e)
                    {
                        // If we get an error, report it.  If the error is NO_MORE_DATA_AVAILABLE we are done
                        if (e.LJUDError == UE9.LJUDERROR.NO_MORE_DATA_AVAILABLE)
                        {
                            unit3Finished = true;
                        }
                        else
                        {
                            showErrorMessage(e);
                        }
                    }
                }

                Console.Out.WriteLine("AIN2 (Unit 2) = {0:0.###}\n", Value22);
                Console.Out.WriteLine("AIN2 (Unit 3) = {0:0.###}\n", Value23);
                Console.Out.WriteLine("AIN3 (Unit 2) = {0:0.###}\n", Value32);
                Console.Out.WriteLine("AIN3 (Unit 3) = {0:0.###}\n", Value33);
                Console.Out.WriteLine("AIN4 (Unit 2) = {0:0.###}\n", Value42);
                Console.Out.WriteLine("AIN4 (Unit 3) = {0:0.###}\n", Value43);

                Console.Out.WriteLine("\nPress Enter to go again or (q) to quit\n");
                isFinished = Console.ReadLine() == "q";                 // Pause for user
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Actually performs actions on the UE9 and updates the displaye
        /// </summary>
        /// <param name="sender">The object that executed this method</param>
        /// <param name="e">Event parameters</param>
        private void goButton_Click(object sender, System.EventArgs e)
        {
            double dblDriverVersion;

            LJUD.IO      ioType = 0;
            LJUD.CHANNEL channel = 0;
            double       dblValue = 0;
            double       Value2 = 0, Value3 = 0;
            double       ValueDIBit = 0, ValueDIPort = 0, ValueCounter = 0;

            // dummy variables to satisfy certian method signatures
            double dummyDouble = 0;
            int    dummyInt    = 0;

            //Read and display the UD version.
            dblDriverVersion    = LJUD.GetDriverVersion();
            versionDisplay.Text = String.Format("{0:0.000}", dblDriverVersion);

            // Open UE9
            try
            {
                ue9 = new UE9(LJUD.CONNECTION.USB, "0", true);                 // Connection through USB
            }
            catch (LabJackUDException exc)
            {
                ShowErrorMessage(exc);
                return;
            }

            try
            {
                //First some configuration commands.  These will be done with the ePut
                //function which combines the add/go/get into a single call.

                //Configure for 16-bit analog input measurements.
                LJUD.ePut(ue9.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.AIN_RESOLUTION, 16, 0);

                //Configure the analog input range on channels 2 and 3 for bipolar 5v.
                LJUD.ePut(ue9.ljhandle, LJUD.IO.PUT_AIN_RANGE, (LJUD.CHANNEL) 2, (double)LJUD.RANGES.BIP5V, 0);
                LJUD.ePut(ue9.ljhandle, LJUD.IO.PUT_AIN_RANGE, (LJUD.CHANNEL) 3, (double)LJUD.RANGES.BIP5V, 0);

                //Enable Counter0 which will appear on FIO0 (assuming no other
                //program has enabled any timers or Counter1).
                LJUD.ePut(ue9.ljhandle, LJUD.IO.PUT_COUNTER_ENABLE, 0, 1, 0);

                //Now we add requests to write and read I/O.  These requests
                //will be processed repeatedly by go/get statements in every
                //iteration of the while loop below.

                //Request AIN2 and AIN3.
                LJUD.AddRequest(ue9.ljhandle, LJUD.IO.GET_AIN, 2, 0, 0, 0);
                LJUD.AddRequest(ue9.ljhandle, LJUD.IO.GET_AIN, 3, 0, 0, 0);

                //Set DAC0 to 2.5 volts.
                LJUD.AddRequest(ue9.ljhandle, LJUD.IO.PUT_DAC, 0, 2.5, 0, 0);

                //Read digital input FIO1.
                LJUD.AddRequest(ue9.ljhandle, LJUD.IO.GET_DIGITAL_BIT, 1, 0, 0, 0);

                //Read digital inputs FIO2 through FIO3.
                LJUD.AddRequest(ue9.ljhandle, LJUD.IO.GET_DIGITAL_PORT, 2, 0, 2, 0);
                // LJUD.AddRequest (ue9.ljhandle, LJUD.IO.GET_DIGITAL_PORT, 2, 0, 3, 0); would request through FIO4

                //Request the value of Counter0.
                LJUD.AddRequest(ue9.ljhandle, LJUD.IO.GET_COUNTER, 0, 0, 0, 0);
            }
            catch (LabJackUDException exc)
            {
                ShowErrorMessage(exc);
                return;
            }

            try
            {
                //Execute the requests.
                LJUD.GoOne(ue9.ljhandle);

                //Get all the results.  The input measurement results are stored.  All other
                //results are for configuration or output requests so we are just checking
                //whether there was an error.
                LJUD.GetFirstResult(ue9.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble);
            }
            catch (LabJackUDException exc)
            {
                ShowErrorMessage(exc);
                return;
            }

            bool isFinished = false;

            while (!isFinished)
            {
                switch (ioType)
                {
                case LJUD.IO.GET_AIN:
                    switch ((int)channel)
                    {
                    case 2:
                        Value2 = dblValue;
                        break;

                    case 3:
                        Value3 = dblValue;
                        break;
                    }
                    break;

                case LJUD.IO.GET_DIGITAL_BIT:
                    ValueDIBit = dblValue;
                    break;

                case LJUD.IO.GET_DIGITAL_PORT:
                    ValueDIPort = dblValue;
                    break;

                case LJUD.IO.GET_COUNTER:
                    ValueCounter = dblValue;
                    break;
                }
                try { LJUD.GetNextResult(ue9.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
                catch (LabJackUDException exc)
                {
                    // If we get an error, report it.  If the error is NO_MORE_DATA_AVAILABLE we are done
                    if (exc.LJUDError == UE9.LJUDERROR.NO_MORE_DATA_AVAILABLE)
                    {
                        isFinished = true;
                    }
                    else
                    {
                        ShowErrorMessage(exc);
                    }
                }
            }

            // Display results
            ain2Display.Text     = String.Format("{0:0.###}", Value2);
            ain3Display.Text     = String.Format("{0:0.###}", Value3);
            fio1Display.Text     = String.Format("{0:0.###}", ValueDIBit);
            fio2Display.Text     = String.Format("{0:0.###}", ValueDIPort);         //Will read 30 (binary 11) if both lines are pulled-high as normal.
            counter0Display.Text = String.Format("{0:0.###}", ValueCounter);
        }
Exemplo n.º 8
0
        public void performActions()
        {
            double dblDriverVersion;

            LJUD.IO      ioType = 0;
            LJUD.CHANNEL channel = 0;
            double       dblValue = 0;
            double       Value0 = 9999, Value1 = 9999, Value2 = 9999;
            double       ValueDIBit = 9999, ValueDIPort = 9999, ValueCounter = 9999;

            // Variables to satisfy certain method signatures
            int    dummyInt    = 0;
            double dummyDouble = 0;

            //Read and display the UD version.
            dblDriverVersion = LJUD.GetDriverVersion();
            Console.Out.WriteLine("UD Driver Version = {0:0.000}\n\n", dblDriverVersion);

            try
            {
                //Open the first found LabJack U3.
                u3 = new U3(LJUD.CONNECTION.USB, "0", true);                 // Connection through USB

                //Start by using the pin_configuration_reset IOType so that all
                //pin assignments are in the factory default condition.
                LJUD.ePut(u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0);


                //First some configuration commands.  These will be done with the ePut
                //function which combines the add/go/get into a single call.

                //Configure FIO0-FIO3 as analog, all else as digital.  That means we
                //will start from channel 0 and update all 16 flexible bits.  We will
                //pass a value of b0000000000001111 or d15.
                LJUD.ePut(u3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 15, 16);

                //Set the timer/counter pin offset to 7, which will put the first
                //timer/counter on FIO7.
                LJUD.ePut(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.TIMER_COUNTER_PIN_OFFSET, 7, 0);

                //Enable Counter1 (FIO7).
                LJUD.ePut(u3.ljhandle, LJUD.IO.PUT_COUNTER_ENABLE, (LJUD.CHANNEL) 1, 1, 0);


                //The following commands will use the add-go-get method to group
                //multiple requests into a single low-level function.

                //Request a single-ended reading from AIN0.
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.GET_AIN, 0, 0, 0, 0);

                //Request a single-ended reading from AIN1.
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.GET_AIN, 1, 0, 0, 0);

                //Request a reading from AIN2 using the Special range.
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.GET_AIN_DIFF, 2, 0, 32, 0);

                //Set DAC0 to 3.5 volts.
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_DAC, 0, 3.5, 0, 0);

                //Set digital output FIO4 to output-high.
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_DIGITAL_BIT, 4, 1, 0, 0);

                //Read digital input FIO5.
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.GET_DIGITAL_BIT, 5, 0, 0, 0);

                //Read digital inputs FIO5 through FIO6.
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.GET_DIGITAL_PORT, 5, 0, 2, 0);

                //Request the value of Counter1 (FIO7).
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.GET_COUNTER, 1, 0, 0, 0);
            }
            catch (LabJackUDException e)
            {
                ShowErrorMessage(e);
            }
            bool requestedExit = false;

            while (!requestedExit)
            {
                try
                {
                    //Execute the requests.
                    LJUD.GoOne(u3.ljhandle);

                    //Get all the results.  The input measurement results are stored.  All other
                    //results are for configuration or output requests so we are just checking
                    //whether there was an error.
                    LJUD.GetFirstResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble);
                }
                catch (LabJackUDException e)
                {
                    ShowErrorMessage(e);
                }

                bool finished = false;
                while (!finished)
                {
                    switch (ioType)
                    {
                    case LJUD.IO.GET_AIN:
                        switch ((int)channel)
                        {
                        case 0:
                            Value0 = dblValue;
                            break;

                        case 1:
                            Value1 = dblValue;
                            break;
                        }
                        break;

                    case LJUD.IO.GET_AIN_DIFF:
                        Value2 = dblValue;
                        break;

                    case LJUD.IO.GET_DIGITAL_BIT:
                        ValueDIBit = dblValue;
                        break;

                    case LJUD.IO.GET_DIGITAL_PORT:
                        ValueDIPort = dblValue;
                        break;

                    case LJUD.IO.GET_COUNTER:
                        ValueCounter = dblValue;
                        break;
                    }
                    try { LJUD.GetNextResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
                    catch (LabJackUDException e)
                    {
                        // If we get an error, report it.  If the error is NO_MORE_DATA_AVAILABLE we are done
                        if (e.LJUDError == U3.LJUDERROR.NO_MORE_DATA_AVAILABLE)
                        {
                            finished = true;
                        }
                        else
                        {
                            ShowErrorMessage(e);
                        }
                    }
                }

                Console.Out.WriteLine("AIN0 = {0:0.###}\n", Value0);
                Console.Out.WriteLine("AIN1 = {0:0.###}\n", Value1);
                Console.Out.WriteLine("AIN2 = {0:0.###}\n", Value2);
                Console.Out.WriteLine("FIO5 = {0:0.###}\n", ValueDIBit);
                Console.Out.WriteLine("FIO5-FIO6 = {0:0.###}\n", ValueDIPort);                 //Will read 3 (binary 11) if both lines are pulled-high as normal.
                Console.Out.WriteLine("Counter1 (FIO7) = {0:0.###}\n", ValueCounter);

                Console.Out.WriteLine("\nPress Enter to go again or (q) to quit\n");
                requestedExit = Console.ReadLine().Equals("q");
            }
        }
Exemplo n.º 9
0
        public void performActions()
        {
            long i = 0, k = 0;

            LJUD.IO      ioType = 0;
            LJUD.CHANNEL channel = 0;
            double       dblValue = 0, dblCommBacklog = 0, dblUDBacklog = 0;
            double       scanRate = 2000;
            int          delayms  = 1000;
            double       numScans = 4000;        //2x the expected # of scans (2*scanRate*delayms/1000)
            double       numScansRequested;

            double[] adblData     = new double[8000];          //Max buffer size (#channels*numScansRequested)

            // Variables to satisfy certain method signatures
            int    dummyInt    = 0;
            double dummyDouble = 0;

            double[] dummyDoubleArray = { 0 };

            //Read and display the UD version.
            dblValue = LJUD.GetDriverVersion();

            Console.Out.WriteLine("UD Driver Version = {0:0.000}\n\n", dblValue);

            try
            {
                //Open the first found LabJack U3.
                u3 = new U3(LJUD.CONNECTION.USB, "0", true);                 // Connection through USB
                //LJUD.ResetLabJack(u3.ljhandle);

                //Read and display the hardware version of this U3.
                LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.HARDWARE_VERSION, ref dblValue, 0);
                Console.Out.WriteLine("U3 Hardware Version = {0:0.000}\n\n", dblValue);

                //Read and display the firmware version of this U3.
                LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.FIRMWARE_VERSION, ref dblValue, 0);
                Console.Out.WriteLine("U3 Firmware Version = {0:0.000}\n\n", dblValue);

                //Start by using the pin_configuration_reset IOType so that all
                //pin assignments are in the factory default condition.
                LJUD.ePut(u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0);
                LJUD.ePut(u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0);

                //Configure FIO0 and FIO1 as analog, all else as digital.  That means we
                //will start from channel 0 and update all 16 flexible bits.  We will
                //pass a value of b0000000000000011 or d3.
                LJUD.ePut(u3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 3, 16);


                //Configure the stream:
                //Set the scan rate.
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_SCAN_FREQUENCY, scanRate, 0, 0);

                //Give the driver a 5 second buffer (scanRate * 2 channels * 5 seconds).
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_BUFFER_SIZE, scanRate * 2 * 5, 0, 0);

                //Configure reads to retrieve whatever data is available without waiting (wait mode LJUD.STREAMWAITMODES.NONE).
                //See comments below to change this program to use LJUD.STREAMWAITMODES.SLEEP mode.
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_WAIT_MODE, (double)LJUD.STREAMWAITMODES.NONE, 0, 0);

                //Define the scan list as AIN0 then AIN1.
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.CLEAR_STREAM_CHANNELS, 0, 0, 0, 0);
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.ADD_STREAM_CHANNEL, 0, 0, 0, 0);
                LJUD.AddRequest(u3.ljhandle, LJUD.IO.ADD_STREAM_CHANNEL_DIFF, 1, 0, 32, 0);

                //Execute the list of requests.
                LJUD.GoOne(u3.ljhandle);
            }
            catch (LabJackUDException e)
            {
                showErrorMessage(e);
            }

            //Get all the results just to check for errors.
            try { LJUD.GetFirstResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
            catch (LabJackUDException e) { showErrorMessage(e); }
            bool finished = false;

            while (!finished)
            {
                try { LJUD.GetNextResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
                catch (LabJackUDException e)
                {
                    // If we get an error, report it.  If the error is NO_MORE_DATA_AVAILABLE we are done
                    if (e.LJUDError == UE9.LJUDERROR.NO_MORE_DATA_AVAILABLE)
                    {
                        finished = true;
                    }
                    else
                    {
                        showErrorMessage(e);
                    }
                }
            }

            //Start the stream.
            try
            {
                LJUD.eGet(u3.ljhandle, LJUD.IO.START_STREAM, 0, ref dblValue, 0);
            }
            catch (LabJackUDException e) { showErrorMessage(e); }

            //The actual scan rate is dependent on how the desired scan rate divides into
            //the LabJack clock.  The actual scan rate is returned in the value parameter
            //from the start stream command.
            Console.Out.WriteLine("Actual Scan Rate = {0:0.000}\n", dblValue);
            Console.Out.WriteLine("Actual Sample Rate = {0:0.000}\n", 2 * dblValue);          // # channels * scan rate


            //Read data
            while (Win32Interop._kbhit() == 0)                  //Loop will run until any key is hit
            {
                //Since we are using wait mode LJUD.STREAMWAITMODES.NONE, we will wait a little, then
                //read however much data is available.  Thus this delay will control how
                //fast the program loops and how much data is read each loop.  An
                //alternative common method is to use wait mode LJUD.STREAMWAITMODES.SLEEP where the
                //stream read waits for a certain number of scans.  In such a case
                //you would not have a delay here, since the stream read will actually
                //control how fast the program loops.
                //
                //To change this program to use sleep mode,
                //	-change numScans to the actual number of scans desired per read,
                //	-change wait mode addrequest value to LJUD.STREAMWAITMODES.SLEEP,
                //	-comment out the following Thread.Sleep command.

                Thread.Sleep(delayms);                  //Remove if using LJUD.STREAMWAITMODES.SLEEP.

                //init array so we can easily tell if it has changed
                for (k = 0; k < numScans * 2; k++)
                {
                    adblData[k] = 9999.0;
                }

                try
                {
                    //Read the data.  We will request twice the number we expect, to
                    //make sure we get everything that is available.
                    //Note that the array we pass must be sized to hold enough SAMPLES, and
                    //the Value we pass specifies the number of SCANS to read.
                    numScansRequested = numScans;
                    LJUD.eGet(u3.ljhandle, LJUD.IO.GET_STREAM_DATA, LJUD.CHANNEL.ALL_CHANNELS, ref numScansRequested, adblData);

                    //The displays the number of scans that were actually read.
                    Console.Out.WriteLine("\nIteration # {0:0.#}\n", i);
                    Console.Out.WriteLine("Number read = {0:0}\n", numScansRequested);

                    //This displays just the first scan.
                    Console.Out.WriteLine("First scan = {0:0.000}, {1:0.000}\n", adblData[0], adblData[1]);

                    //Retrieve the current backlog.  The UD driver retrieves stream data from
                    //the U3 in the background, but if the computer is too slow for some reason
                    //the driver might not be able to read the data as fast as the U3 is
                    //acquiring it, and thus there will be data left over in the U3 buffer.
                    LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.STREAM_BACKLOG_COMM, ref dblCommBacklog, 0);
                    Console.Out.WriteLine("Comm Backlog = {0:0}\n", dblCommBacklog);
                    LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.STREAM_BACKLOG_UD, ref dblUDBacklog, 0);
                    Console.Out.WriteLine("UD Backlog = {0:0}\n", dblUDBacklog);
                    i++;
                }
                catch (LabJackUDException e) { showErrorMessage(e); }
            }


            //Stop the stream
            try{ LJUD.eGet(u3.ljhandle, LJUD.IO.STOP_STREAM, 0, ref dummyDouble, dummyDoubleArray); }
            catch (LabJackUDException e) { showErrorMessage(e); }

            Console.Out.WriteLine("\nDone");
            Console.ReadLine();             // Pause for user
        }
Exemplo n.º 10
0
        public void preformActions()
        {
            long   lngGetNextIteration;
            double dblDriverVersion;

            LJUD.IO      ioType = 0;
            LJUD.CHANNEL channel = 0;
            double       dblValue = 0;
            double       Value12 = 9999, Value22 = 9999, Value32 = 9999;
            double       Value13 = 9999, Value23 = 9999, Value33 = 9999;

            //Read and display the UD version.
            dblDriverVersion = LJUD.GetDriverVersion();
            Console.Out.WriteLine("UD Driver Version = {0:0.000}\n\n", dblDriverVersion);

            // Variables to satisfy certain method signatures
            int    dummyInt    = 0;
            double dummyDouble = 0;

            //Open the U6 with local ID 2.
            try
            {
                unit2 = new U6(LJUD.CONNECTION.USB, "0", true);                 // Connection through USB
            }
            catch (LabJackUDException e)
            {
                showErrorMessage(e);
            }
            //Open the U6 with local ID 3.
            try
            {
                unit3 = new U6(LJUD.CONNECTION.USB, "0", true);                 // Connection through USB
            }
            catch (LabJackUDException e)
            {
                showErrorMessage(e);
            }

            try
            {
                //The following commands will use the add-go-get method to group
                //multiple requests into a single low-level function.

                //Request a single-ended reading from AIN1.
                LJUD.AddRequest(unit2.ljhandle, LJUD.IO.GET_AIN, 1, 0, 0, 0);
                LJUD.AddRequest(unit3.ljhandle, LJUD.IO.GET_AIN, 1, 0, 0, 0);

                //Request a single-ended reading from AIN2.
                LJUD.AddRequest(unit2.ljhandle, LJUD.IO.GET_AIN, 2, 0, 0, 0);
                LJUD.AddRequest(unit3.ljhandle, LJUD.IO.GET_AIN, 2, 0, 0, 0);
            }
            catch (LabJackUDException e)
            {
                showErrorMessage(e);
            }

            bool isFinished = false;

            while (!isFinished)
            {
                try
                {
                    //Execute all requests on all open LabJacks.
                    LJUD.Go();

                    //Get all the results for unit 2.  The input measurement results are stored.
                    LJUD.GetFirstResult(unit2.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble);
                }
                catch (LabJackUDException e)
                {
                    showErrorMessage(e);
                }

                bool unit2Finished = false;
                while (!unit2Finished)
                {
                    switch (ioType)
                    {
                    case LJUD.IO.GET_AIN:
                        switch ((int)channel)
                        {
                        case 1:
                            Value12 = dblValue;
                            break;

                        case 2:
                            Value22 = dblValue;
                            break;
                        }
                        break;

                    case LJUD.IO.GET_AIN_DIFF:
                        Value32 = dblValue;
                        break;
                    }

                    try { LJUD.GetNextResult(unit2.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
                    catch (LabJackUDException e)
                    {
                        // If we get an error, report it.  If the error is NO_MORE_DATA_AVAILABLE we are done
                        if (e.LJUDError == UE9.LJUDERROR.NO_MORE_DATA_AVAILABLE)
                        {
                            unit2Finished = true;
                        }
                        else
                        {
                            showErrorMessage(e);
                        }
                    }
                }


                //Get all the results for unit 3.  The input measurement results are stored.
                try { LJUD.GetFirstResult(unit3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
                catch (LabJackUDException e)  { showErrorMessage(e); }

                bool unit3Finished = false;
                while (!unit3Finished)
                {
                    switch (ioType)
                    {
                    case LJUD.IO.GET_AIN:
                        switch ((int)channel)
                        {
                        case 1:
                            Value13 = dblValue;
                            break;

                        case 2:
                            Value23 = dblValue;
                            break;
                        }
                        break;

                    case LJUD.IO.GET_AIN_DIFF:
                        Value33 = dblValue;
                        break;
                    }

                    try { LJUD.GetNextResult(unit3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
                    catch (LabJackUDException e)
                    {
                        // If we get an error, report it.  If the error is NO_MORE_DATA_AVAILABLE we are done
                        if (e.LJUDError == UE9.LJUDERROR.NO_MORE_DATA_AVAILABLE)
                        {
                            unit3Finished = true;
                        }
                        else
                        {
                            showErrorMessage(e);
                        }
                    }
                }



                Console.Out.WriteLine("AIN1 (Unit 2) = {0:0.###}\n", Value12);
                Console.Out.WriteLine("AIN1 (Unit 3) = {0:0.###}\n", Value13);
                Console.Out.WriteLine("AIN2 (Unit 2) = {0:0.###}\n", Value22);
                Console.Out.WriteLine("AIN2 (Unit 3) = {0:0.###}\n", Value23);
                Console.Out.WriteLine("AIN3 (Unit 2) = {0:0.###}\n", Value32);
                Console.Out.WriteLine("AIN3 (Unit 3) = {0:0.###}\n", Value33);

                Console.Out.WriteLine("\nPress Enter to go again or (q) to quit\n");
                String str1 = Console.ReadLine();                 // Pause for user
                isFinished = str1 == "q";
            }
        }
Exemplo n.º 11
0
        public void performActions()
        {
            double dblDriverVersion;

            LJUD.IO      ioType = 0;
            LJUD.CHANNEL channel = 0;
            double       dblValue = 0;
            double       Value0 = 9999, Value1 = 9999, Value2 = 9999;
            double       ValueDIBit = 9999, ValueDIPort = 9999, ValueCounter = 9999;


            //Read and display the UD version.
            dblDriverVersion = LJUD.GetDriverVersion();
            Console.Out.WriteLine("UD Driver Version = {0:0.000}\n\n", dblDriverVersion);


            //Open the first found LabJack U6.
            try
            {
                u6 = new U6(LJUD.CONNECTION.USB, "0", true);                 // Connection through USB
            }
            catch (LabJackUDException e)
            {
                showErrorMessage(e);
            }


            //First some configuration commands.  These will be done with the ePut
            //function which combines the add/go/get into a single call.

            //Set the timer/counter pin offset to 3, which will put the first
            //timer/counter on FIO3.
            LJUD.ePut(u6.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.TIMER_COUNTER_PIN_OFFSET, 3, 0);

            //Enable Counter1 (FIO3).
            LJUD.ePut(u6.ljhandle, LJUD.IO.PUT_COUNTER_ENABLE, (LJUD.CHANNEL) 1, 1, 0);


            //The following commands will use the add-go-get method to group
            //multiple requests into a single low-level function.

            //Request a single-ended reading from AIN0.
            LJUD.AddRequest(u6.ljhandle, LJUD.IO.GET_AIN, 0, 0, 0, 0);

            //Request a single-ended reading from AIN1.
            LJUD.AddRequest(u6.ljhandle, LJUD.IO.GET_AIN, 1, 0, 0, 0);

            //Request a reading from AIN2 using the Special range.
            LJUD.AddRequest(u6.ljhandle, LJUD.IO.GET_AIN_DIFF, 2, 0, 15, 0);

            //Set DAC0 to 3.5 volts.
            LJUD.AddRequest(u6.ljhandle, LJUD.IO.PUT_DAC, 0, 3.5, 0, 0);

            //Set digital output FIO0 to output-high.
            LJUD.AddRequest(u6.ljhandle, LJUD.IO.PUT_DIGITAL_BIT, 0, 1, 0, 0);

            //Read digital input FIO1.
            LJUD.AddRequest(u6.ljhandle, LJUD.IO.GET_DIGITAL_BIT, 1, 0, 0, 0);

            //Read digital inputs FIO1 through FIO2.
            LJUD.AddRequest(u6.ljhandle, LJUD.IO.GET_DIGITAL_PORT, 1, 0, 2, 0);

            //Request the value of Counter1 (FIO3).
            LJUD.AddRequest(u6.ljhandle, LJUD.IO.GET_COUNTER, 1, 0, 0, 0);


            bool requestedExit = false;

            while (!requestedExit)
            {
                try
                {
                    //Execute the requests.
                    LJUD.GoOne(u6.ljhandle);

                    //Get all the results.  The input measurement results are stored.  All other
                    //results are for configuration or output requests so we are just checking
                    //whether there was an error.
                    LJUD.GetFirstResult(u6.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble);
                }
                catch (LabJackUDException e)
                {
                    showErrorMessage(e);
                }

                bool finished = false;
                while (!finished)
                {
                    switch (ioType)
                    {
                    case LJUD.IO.GET_AIN:
                        switch ((int)channel)
                        {
                        case 0:
                            Value0 = dblValue;
                            break;

                        case 1:
                            Value1 = dblValue;
                            break;
                        }
                        break;

                    case LJUD.IO.GET_AIN_DIFF:
                        Value2 = dblValue;
                        break;

                    case LJUD.IO.GET_DIGITAL_BIT:
                        ValueDIBit = dblValue;
                        break;

                    case LJUD.IO.GET_DIGITAL_PORT:
                        ValueDIPort = dblValue;
                        break;

                    case LJUD.IO.GET_COUNTER:
                        ValueCounter = dblValue;
                        break;
                    }
                    try { LJUD.GetNextResult(u6.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
                    catch (LabJackUDException e)
                    {
                        // If we get an error, report it.  If the error is NO_MORE_DATA_AVAILABLE we are done
                        if (e.LJUDError == U6.LJUDERROR.NO_MORE_DATA_AVAILABLE)
                        {
                            finished = true;
                        }
                        else
                        {
                            showErrorMessage(e);
                        }
                    }
                }

                Console.Out.WriteLine("AIN0 = {0:0.###}\n", Value0);
                Console.Out.WriteLine("AIN1 = {0:0.###}\n", Value1);
                Console.Out.WriteLine("AIN2 = {0:0.###}\n", Value2);
                Console.Out.WriteLine("FIO1 = {0:0.###}\n", ValueDIBit);
                Console.Out.WriteLine("FIO1-FIO2 = {0:0.###}\n", ValueDIPort);                 //Will read 3 (binary 11) if both lines are pulled-high as normal.
                Console.Out.WriteLine("Counter1 (FIO3) = {0:0.###}\n", ValueCounter);

                Console.Out.WriteLine("\nPress Enter to go again or (q) to quit\n");
                str1          = Console.ReadLine();        // Pause for user
                requestedExit = str1 == "q";
            }
        }