Example #1
0
        static public void opendevice()
        {
            StringBuilder UnitInfo = new StringBuilder(80);

            short handle;

            string[] description =
            {
                "Driver Version    ",
                "USB Version       ",
                "Hardware Version  ",
                "Variant Info      ",
                "Serial            ",
                "Cal Date          ",
                "Kernel Ver        ",
                "Digital Hardware  ",
                "Analogue Hardware "
            };

            Imports.DeviceResolution resolution = Imports.DeviceResolution.PS5000A_DR_14BIT;
            //Imports.DeviceResolution resolution = Imports.DeviceResolution.PS5000A_DR_8BIT;


            if (_handle > 0)
            {
                Imports.CloseUnit(_handle);

                devicelogs   = "";
                _handle      = 0;
                devicelogs  += "Closed\n";
                deviceisopen = false;
            }
            else
            {
                if (channelson[0] || channelson[1] || channelson[2] || channelson[3] || channelson[4])
                {
                    short status = Imports.OpenUnit(out handle, null, resolution);
                    if (handle > 0)
                    {
                        _handle = handle;

                        devicelogs = "Handle " + _handle.ToString() + "\r\n";

                        for (int i = 0; i < 9; i++)
                        {
                            short requiredSize;
                            Imports.GetUnitInfo(_handle, UnitInfo, 80, out requiredSize, i);
                            devicelogs += description[i] + UnitInfo + "\r\n";
                        }
                        deviceisopen = true;
                        devicelogs  += "Open\n";
                    }
                }
                else
                {
                    devicelogs += "Activate channels or generator\n";
                }
            }
        }
        /****************************************************************************
        * Select resolution of device
        ****************************************************************************/
        void SetResolution()
        {
            bool valid;
            int  maxSelection = 2;
            uint status;

            Console.WriteLine("0 : 8 bits");
            Console.WriteLine("1 : 12 bits");
            Console.WriteLine("2 : 14 bits");

            if (_noEnabledChannels <= 2)
            {
                Console.WriteLine("3 : 15 bits"); //can only use up to 2 channels with 15 bit mode
                if (_noEnabledChannels < 2)
                {
                    Console.WriteLine("4 : 16 bits"); //can only use 1 channel with 16 bit mode
                    maxSelection = 4;
                }
                else
                {
                    maxSelection = 3;
                }
            }

            Console.WriteLine();

            do
            {
                try
                {
                    Console.WriteLine("Resolution: ");
                    _resolution = (Imports.DeviceResolution)(uint.Parse(Console.ReadLine()));
                    valid       = true;
                }
                catch (FormatException e)
                {
                    valid = false;
                    Console.WriteLine("Error: " + e.Message);
                }

                if (_resolution > (Imports.DeviceResolution)maxSelection)
                {
                    Console.WriteLine("Please select a number stated above");
                    valid = false;
                }
            } while (!valid);

            if ((status = Imports.SetDeviceResolution(_handle, _resolution)) != 0)
            {
                Console.WriteLine("Resolution not set Error code: {0)", status);
            }
        }
Example #3
0
        private void buttonOpen_Click(object sender, EventArgs e)
        {
            StringBuilder UnitInfo = new StringBuilder(80);

            short handle;

            string[] description =
            {
                "Driver Version    ",
                "USB Version       ",
                "Hardware Version  ",
                "Variant Info      ",
                "Serial            ",
                "Cal Date          ",
                "Kernel Ver        ",
                "Digital Hardware  ",
                "Analogue Hardware "
            };

            Imports.DeviceResolution resolution = Imports.DeviceResolution.PS5000A_DR_16BIT;
            //Imports.DeviceResolution resolution = Imports.DeviceResolution.PS5000A_DR_8BIT;


            if (_handle > 0)
            {
                Imports.CloseUnit(_handle);
                textBoxUnitInfo.Text = "";
                _handle         = 0;
                buttonOpen.Text = "Open";
            }
            else
            {
                short status = Imports.OpenUnit(out handle, null, resolution);
                if (handle > 0)
                {
                    _handle = handle;

                    textBoxUnitInfo.Text = "Handle            " + _handle.ToString() + "\r\n";

                    for (int i = 0; i < 9; i++)
                    {
                        short requiredSize;
                        Imports.GetUnitInfo(_handle, UnitInfo, 80, out requiredSize, i);
                        textBoxUnitInfo.AppendText(description[i] + UnitInfo + "\r\n");
                    }
                    buttonOpen.Text = "Close";
                }
            }
        }
        /****************************************************************************
        * Outputs the resolution in text format to the console window
        ****************************************************************************/
        void PrintResolution(Imports.DeviceResolution resolution)
        {
            int res = 8; // 8-bits

            switch (resolution)
            {
            case Imports.DeviceResolution.PS5000A_DR_8BIT:

                res = 8;
                break;

            case Imports.DeviceResolution.PS5000A_DR_12BIT:

                res = 12;
                break;

            case Imports.DeviceResolution.PS5000A_DR_14BIT:

                res = 14;
                break;

            case Imports.DeviceResolution.PS5000A_DR_15BIT:

                res = 15;
                break;

            case Imports.DeviceResolution.PS5000A_DR_16BIT:

                res = 16;
                break;

            default:

                break;
            }

            Console.WriteLine("Device Resolution: {0} bits", res);
        }
        private void buttonOpen_Click(object sender, EventArgs e)
        {
            StringBuilder UnitInfo = new StringBuilder(80);

            short handle;

            string[] description =
            {
                "Driver Version    ",
                "USB Version       ",
                "Hardware Version  ",
                "Variant Info      ",
                "Serial            ",
                "Cal Date          ",
                "Kernel Ver        ",
                "Digital Hardware  ",
                "Analogue Hardware "
            };

            Imports.DeviceResolution resolution = Imports.DeviceResolution.PS5000A_DR_16BIT;
            //Imports.DeviceResolution resolution = Imports.DeviceResolution.PS5000A_DR_8BIT;


            if (_handle > 0)
            {
                Imports.CloseUnit(_handle);
                textBoxUnitInfo.Text = "";
                _handle         = 0;
                buttonOpen.Text = "Open";
            }
            else
            {
                uint status = Imports.OpenUnit(out handle, null, resolution);

                if (handle > 0)
                {
                    _handle = handle;

                    if (status == StatusCodes.PICO_POWER_SUPPLY_NOT_CONNECTED || status == StatusCodes.PICO_USB3_0_DEVICE_NON_USB3_0_PORT)
                    {
                        status = Imports.ChangePowerSource(_handle, status);
                    }
                    else if (status != StatusCodes.PICO_OK)
                    {
                        MessageBox.Show("Cannot open device error code: " + status.ToString(), "Error Opening Device", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                    }
                    else
                    {
                        // Do nothing - power supply connected
                    }

                    textBoxUnitInfo.Text = "Handle            " + _handle.ToString() + "\r\n";

                    for (int i = 0; i < 9; i++)
                    {
                        short requiredSize;
                        Imports.GetUnitInfo(_handle, UnitInfo, 80, out requiredSize, (uint)i);
                        textBoxUnitInfo.AppendText(description[i] + UnitInfo + "\r\n");
                    }
                    buttonOpen.Text = "Close";
                }
            }
        }