Ejemplo n.º 1
0
 private void open_handle()
 {
     handle = AardvarkApi.aa_open(port);
     if (handle <= 0)
     {
         Console.WriteLine("Unable to open Aardvark device on port {0}", port);
         Console.WriteLine("error: {0}", AardvarkApi.aa_status_string(handle));
     }
 }
Ejemplo n.º 2
0
        public int i2c_read(ushort slave_addr, ushort bytes, out byte[] data_in)
        {
            data_in = Enumerable.Repeat <byte>(0, bytes).ToArray();            //set it to all 0's first

            var result = AardvarkApi.aa_i2c_read(handle, slave_addr, AardvarkI2cFlags.AA_I2C_NO_FLAGS, bytes, data_in);

            if (result < 0)
            {
                Console.WriteLine("error: {0}\n", AardvarkApi.aa_status_string(result));
            }

            return(result);
        }
Ejemplo n.º 3
0
        public int i2c_write(ushort slave_addr, ushort num_bytes, byte[] data_out)
        {
            var result = AardvarkApi.aa_i2c_write(handle, slave_addr, AardvarkI2cFlags.AA_I2C_NO_FLAGS, num_bytes, data_out);

            if (result < 0)
            {
                Console.WriteLine("error: {0}\n", AardvarkApi.aa_status_string(result));
                //setup_aardvark();
                result = AardvarkApi.aa_i2c_write(handle, slave_addr, AardvarkI2cFlags.AA_I2C_NO_FLAGS, num_bytes, data_out);
                if (result < 0)
                {
                    return(-1);
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        private void setup_i2c()
        {
            // Ensure that the I2C subsystem is enabled
            AardvarkApi.aa_configure(handle, AardvarkConfig.AA_CONFIG_SPI_I2C);

            // Enable the I2C bus pullup resistors (2.2k resistors).
            // This command is only effective on v2.0 hardware or greater.
            // The pullup resistors on the v1.02 hardware are enabled by default.
            AardvarkApi.aa_i2c_pullup(handle, AardvarkApi.AA_I2C_PULLUP_BOTH);

            // Power the EEPROM using the Aardvark adapter's power supply.
            // This command is only effective on v2.0 hardware or greater.
            // The power pins on the v1.02 hardware are not enabled by default.
            AardvarkApi.aa_target_power(handle, AardvarkApi.AA_TARGET_POWER_BOTH);

            // Set the bitrate
            bitrate = AardvarkApi.aa_i2c_bitrate(handle, 400);
            Console.WriteLine("Bitrate set to {0} kHz", bitrate);

            // Set the bus lock timeout
            bus_timeout = AardvarkApi.aa_i2c_bus_timeout(handle, BUS_TIMEOUT);
            Console.WriteLine("Bus lock timeout set to {0} ms", bus_timeout);
        }
Ejemplo n.º 5
0
        public void find_device()
        {
            int device_num = 8;
            var ports      = Enumerable.Repeat <ushort>(9999, device_num).ToArray();
            var ids        = new uint[device_num];

            try
            {
                int aa_num = AardvarkApi.aa_find_devices_ext(device_num, ports, device_num, ids);
                if (aa_num > 0)
                {
                    for (int i = 0; i < device_num; i++)
                    {
                        if (ports[i] != 9999 && !check_aardvark(ids[i]))                         //check if not there already
                        {
                            aardvarks.Add(new Aardvark(ports[i], ids[i]));
                        }
                    }
                }
                int bg_num = BeagleApi.bg_find_devices_ext(device_num, ports, device_num, ids);
                if (bg_num > 0)
                {
                    for (int i = 0; i < device_num; i++)
                    {
                        if (ports[i] != 9999 && !check_beagle(ids[i]))
                        {
                            beagles.Add(new Beagle(ports[i], ids[i]));
                        }
                    }
                }
            }
            catch (System.TypeInitializationException)
            {
                MessageBox.Show("Application must target 64 bit");
            }
        }
Ejemplo n.º 6
0
        private void button_reset_Click(object sender, EventArgs e)
        {
            textBox_data.AppendText("RESET Operation Initiated\n");
            if (iface.current_aardvark.Port != 999)
            {
                AardvarkApi.aa_close(iface.current_aardvark.Port);
            }

            /*
             * if (iface.current_beagle.Port != 999)
             * {
             *      BeagleApi.bg_capture_stop(iface.current_beagle.Port);
             *      BeagleApi.bg_close(iface.current_beagle.Port);
             * }
             *///dont need this
            System.Diagnostics.Process.Start(Application.ExecutablePath);
            this.Close();
            //reset these - OLD WAY BELOW, NEW WAY ABOVE WORKS BETTER

            /*
             * if (select) //only if the scan completed successfully
             *      this.Size = new Size(this.Size.Width, this.Size.Height - height); //resize to hide
             * loop = false; //to stop or esume the measuremetns
             * select = false; //this determines if everything was loaded correctly and can continue to operation
             * run_lock = false;
             * first_log = Enumerable.Repeat<bool>(true, 16).ToArray();
             * for(ushort i = 0x50; i <= 0x5f; i++)
             *      iface.current_aardvark.i2c_write(i, (ushort)1, new byte[] { 128 }); //set the mux to the off (all boards)
             *
             * System.Threading.Thread.Sleep(750); //wait to allow loops to exit out correctly
             *
             * while (tabControl_boards.TabCount > 0) //release resources
             *      tabControl_boards.TabPages[tabControl_boards.TabCount - 1].Dispose();
             * tabControl_boards.TabPages.Clear(); //remove
             *
             * BeagleApi.bg_capture_stop(iface.current_beagle.Port);
             * AardvarkApi.aa_i2c_free_bus(iface.current_aardvark.Port);
             * AardvarkApi.aa_close(iface.current_aardvark.Port);
             * BeagleApi.bg_close(iface.current_beagle.Port);
             * iface.current_aardvark = new Aardvark(); //placeholder
             * iface.current_beagle = new Beagle(); //placeholder
             * iface.current_job = null; //clear it out
             * iface = new TotalPhase();
             *
             * label_avg.Text = "Avg: ";
             * label_max.Text = "Max: ";
             * label_min.Text = "Min: ";
             * label_range.Text = "Range: ";
             * textBox_data.ResetText();
             * textBox_job.ResetText();
             * textBox_lot.ResetText();
             * textBox_system.ResetText();
             *
             * comboBox_aardvark.Items.Clear();
             * comboBox_beagle.Items.Clear();
             * comboBox_config.Items.Clear();
             * listBox_active.Items.Clear();
             * comboBox_aardvark.ResetText();
             * comboBox_beagle.ResetText();
             * comboBox_config.ResetText();
             *
             * button_stop.Visible = false;
             * button_i2cmonitor.Visible = false; //resume
             * button_select.Visible = true; //start
             * checkBox_debug.Checked = false;
             * numericUpDown_values.Value = 0;
             * numericUpDown_values.ResetText();
             * /*
             * if (select)
             * {
             *      iface.current_beagle.reset_beagle();
             * }
             * else //if valid beagle/aardvark combo not selected
             *      MessageBox.Show("Aardvark/Beagle/Config not selected!");
             */
            //log_data();
        }